mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Through git-diff(1), a single diff can be generated from a pair of blob revisions directly. Unfortunately, there is not a mechanism to compute batches of specific file pair diffs in a single process. Such a feature is particularly useful on the server-side where diffing between a large set of changes is not feasible all at once due to timeout concerns. To facilitate this, introduce git-diff-pairs(1) which acts as a backend passing its NUL-terminated raw diff format input from stdin through diff machinery to produce various forms of output such as patch or raw. The raw format was originally designed as an interchange format and represents the contents of the diff_queued_diff list making it possible to break the diff pipeline into separate stages. For example, git-diff-tree(1) can be used as a frontend to compute file pairs to queue and feed its raw output to git-diff-pairs(1) to compute patches. With this, batches of diffs can be progressively generated without having to recompute renames or retrieve object context. Something like the following: git diff-tree -r -z -M $old $new | git diff-pairs -p -z should generate the same output as `git diff-tree -p -M`. Furthermore, each line of raw diff formatted input can also be individually fed to a separate git-diff-pairs(1) process and still produce the same output. Based-on-patch-by: Jeff King <peff@peff.net> Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
82 lines
2.1 KiB
Bash
Executable File
82 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='basic diff-pairs tests'
|
|
. ./test-lib.sh
|
|
|
|
# This creates a diff with added, modified, deleted, renamed, copied, and
|
|
# typechange entries. This includes a submodule to test submodule diff support.
|
|
test_expect_success 'setup' '
|
|
test_config_global protocol.file.allow always &&
|
|
git init sub &&
|
|
test_commit -C sub initial &&
|
|
|
|
git init main &&
|
|
cd main &&
|
|
echo to-be-gone >deleted &&
|
|
echo original >modified &&
|
|
echo now-a-file >symlink &&
|
|
test_seq 200 >two-hundred &&
|
|
test_seq 201 500 >five-hundred &&
|
|
git add . &&
|
|
test_tick &&
|
|
git commit -m base &&
|
|
git tag base &&
|
|
|
|
git submodule add ../sub &&
|
|
echo now-here >added &&
|
|
echo new >modified &&
|
|
rm deleted &&
|
|
mkdir subdir &&
|
|
echo content >subdir/file &&
|
|
mv two-hundred renamed &&
|
|
test_seq 201 500 | sed s/300/modified/ >copied &&
|
|
rm symlink &&
|
|
git add -A . &&
|
|
test_ln_s_add dest symlink &&
|
|
test_tick &&
|
|
git commit -m new &&
|
|
git tag new
|
|
'
|
|
|
|
test_expect_success 'diff-pairs recreates --raw' '
|
|
git diff-tree -r -M -C -C -z base new >expect &&
|
|
git diff-pairs --raw -z >actual <expect &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'diff-pairs can create -p output' '
|
|
git diff-tree -p -M -C -C base new >expect &&
|
|
git diff-tree -r -M -C -C -z base new |
|
|
git diff-pairs -p -z >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'diff-pairs does not support normal raw diff input' '
|
|
git diff-tree -r base new |
|
|
test_must_fail git diff-pairs >out 2>err &&
|
|
|
|
echo "usage: working without -z is not supported" >expect &&
|
|
test_must_be_empty out &&
|
|
test_cmp expect err
|
|
'
|
|
|
|
test_expect_success 'diff-pairs does not support tree objects as input' '
|
|
git diff-tree -z base new |
|
|
test_must_fail git diff-pairs -z >out 2>err &&
|
|
|
|
echo "fatal: tree objects not supported" >expect &&
|
|
test_must_be_empty out &&
|
|
test_cmp expect err
|
|
'
|
|
|
|
test_expect_success 'diff-pairs does not support pathspec arguments' '
|
|
git diff-tree -r -z base new |
|
|
test_must_fail git diff-pairs -z -- new >out 2>err &&
|
|
|
|
echo "usage: pathspec arguments not supported" >expect &&
|
|
test_must_be_empty out &&
|
|
test_cmp expect err
|
|
'
|
|
|
|
test_done
|