Through git-diff(1) it is possible to generate a diff directly between two blobs. This is particularly useful when the pre-image and post-image blobs are known and we only care about the diff between them. Unfortunately, if a user has a batch of known blob pairs to compute diffs for, there is currently not a way to do so via a single Git process. To enable support for batch diffs of multiple blob pairs, this series introduces a new diff plumbing command git-diff-pairs(1) based on a previous patch series submitted by Peff[1]. This command uses NUL-delimited raw diffs as its source of input to control exactly which filepairs are diffed. The advantage of using the raw diff format is that it already has diff status type and object context information embedded in each line making it more efficient to generate diffs with as we can avoid having to peel revisions to get some the same info. For example: git diff-tree -r -z -M $old $new | git diff-pairs -p -z Here the output of git-diff-tree(1) is fed to git-diff-pairs(1) to generate the same output that would be expected from `git diff-tree -p -M`. While by itself not particularly useful, this means it is possible to split git-diff-tree(1) output across multiple git-diff-pairs(1) processes. Such a feature is useful on the server-side where diffs bewteen a large set of changes may not be feasible all at once due to timeout concerns. This command can be viewed as a backend tool that exposes Git's diff machinery. In its current form, the frontend that generates the raw diff lines used as input is expected to most of the heavy lifting (ie. pathspec limiting, tree object expansion). This series is structured as follows: - Patch 1 adds some new helper functions to get access to the queued `diff_filepair` after `diff_queue()` is invoked. - Patch 2 adds a new diff_options field that can be used to disable diff filepair status resolution. This prevents rename/copy statuses set from stdin from being altered when `diffcore_std()` is invoked. - Patch 3 introduces the new git-diff-pairs(1) plumbing command. - Patch 4 allows git-diff-pairs(1) to immediately compute diffs queued on stdin when a NUL-byte is written after a raw input line instead of waiting for stdin to close. Changes since V4: - Renamed usage and options variables to better follow convention. - Removed unneeded PARSE_OPT_KEEP_UNKNOWN_OPT from `parse_options()`. - Instead of using the deprecated `test_create_repo ()` in the tests, plain git-init(1) is used. Changes since V3: - Instead of relying on found_follow to prevent `diffcore_std()` from mutating diff filepair statuses, a new `diff_options` field, `skip_resolving_statuses` is introduced to achieve the same result in a more specific manner. - Parsing of diff options is now handled directly instead of going through `setup_revisions()`. This is done to so the diff options can be appended to the usage options and printed in the usage message. - Swapped to using `strbuf_getwholeline()` during stdin parsing to make the line termiantor more configurable in the future. - Stopped printing the usage message on errors to avoid masking the underlying error message. - Added test setup to exercise submodule change diffs. - Other small minor cleanups. Changes since V2: - Pathspecs are not supported and thus rejected when provided as arguments. It should be possible in a future series to add support though. - Tree objects present in `diff-pairs` input are rejected. Support for tree objects could be added in the future, but for now they are rejected to enable to future support in a backwards compatible manner. - The -z option is required by git-diff-pairs(1). The NUL-delimited raw diff format is the only accepted form of input. Consequently, NUL-delimited output is the only option in the `--raw` mode. - git-diff-pairs(1) defaults to patch output instead of raw output. This better fits the intended usecase of the command. - A NUL-byte is now always used as the delimiter between batches of file pair diffs when queued diffs are explicitly computed by writing a NUL-byte on stdin. - Several other small cleanups and fixes along with documentation changes. Changes since V1: - Changed from git-diff-blob(1) to git-diff-pairs(1) based on a previously submitted series. - Instead of each line containing a pair of blob revisions, the raw diff format is used as input which already has diff status and object context embedded. -Justin [1]: <20161201204042.6yslbyrg7l6ghhww@xxxxxxxxxxxxxxxxxxxxx> Justin Tobler (4): diff: return diff_filepair from diff queue helpers diff: add option to skip resolving diff statuses builtin: introduce diff-pairs command builtin/diff-pairs: allow explicit diff queue flush .gitignore | 1 + Documentation/git-diff-pairs.adoc | 60 +++++++++ Documentation/meson.build | 1 + Makefile | 1 + builtin.h | 1 + builtin/diff-pairs.c | 207 ++++++++++++++++++++++++++++++ command-list.txt | 1 + diff.c | 72 ++++++++--- diff.h | 33 +++++ git.c | 1 + meson.build | 1 + t/meson.build | 1 + t/t4070-diff-pairs.sh | 90 +++++++++++++ 13 files changed, 449 insertions(+), 21 deletions(-) create mode 100644 Documentation/git-diff-pairs.adoc create mode 100644 builtin/diff-pairs.c create mode 100755 t/t4070-diff-pairs.sh Range-diff against v4: 1: b2e5486442 = 1: b2e5486442 diff: return diff_filepair from diff queue helpers 2: 31d80d99ae = 2: 31d80d99ae diff: add option to skip resolving diff statuses 3: 3722c02112 ! 3: 1024a4290c builtin: introduce diff-pairs command @@ builtin/diff-pairs.c (new) + int line_term = '\0'; + int ret; + -+ const char * const usagestr[] = { ++ const char * const builtin_diff_pairs_usage[] = { + N_("git diff-pairs -z [<diff-options>]"), + NULL + }; -+ struct option options[] = { ++ struct option builtin_diff_pairs_options[] = { + OPT_END() + }; + @@ builtin/diff-pairs.c (new) + * setup_revisions(). Explicitly handle parsing to ensure options are + * printed in the usage message. + */ -+ parseopts = add_diff_options(options, &revs.diffopt); -+ show_usage_with_options_if_asked(argc, argv, usagestr, parseopts); ++ parseopts = add_diff_options(builtin_diff_pairs_options, &revs.diffopt); ++ show_usage_with_options_if_asked(argc, argv, builtin_diff_pairs_usage, parseopts); + + repo_config(repo, git_diff_basic_config, NULL); + revs.disable_stdin = 1; + revs.abbrev = 0; + revs.diff = 1; + -+ argc = parse_options(argc, argv, prefix, parseopts, usagestr, -+ PARSE_OPT_KEEP_UNKNOWN_OPT | -+ PARSE_OPT_KEEP_DASHDASH | -+ PARSE_OPT_KEEP_ARGV0); ++ argc = parse_options(argc, argv, prefix, parseopts, builtin_diff_pairs_usage, ++ PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_DASHDASH); + + if (setup_revisions(argc, argv, &revs, NULL) > 1) + usagef(_("unrecognized argument: %s"), argv[0]); @@ t/t4070-diff-pairs.sh (new) +# typechange entries. This includes a submodule to test submodule diff support. +test_expect_success 'setup' ' + test_config_global protocol.file.allow always && -+ test_create_repo sub && ++ git init sub && + test_commit -C sub initial && + -+ test_create_repo main && ++ git init main && + cd main && + echo to-be-gone >deleted && + echo original >modified && 4: a4809cbd80 ! 4: 56f21b664e builtin/diff-pairs: allow explicit diff queue flush @@ Documentation/git-diff-pairs.adoc: in the NUL-terminated raw output format as ge ## builtin/diff-pairs.c ## @@ builtin/diff-pairs.c: int cmd_diff_pairs(int argc, const char **argv, const char *prefix, - show_usage_with_options_if_asked(argc, argv, usagestr, parseopts); + show_usage_with_options_if_asked(argc, argv, builtin_diff_pairs_usage, parseopts); repo_config(repo, git_diff_basic_config, NULL); + revs.diffopt.no_free = 1; -- 2.49.0.rc0