git/Documentation
Michael Montalbo 74fcf26527 diff: consult oid-only hunk providers via diff.<driver>.process
The provider chain so far holds the diff-hunks store in front of the
terminal builtin computation.  Open it to external processes: a pair on
a path whose driver configures diff.<driver>.process is answered by a
long-running process speaking a pkt-line protocol (following the filter
process protocol), registered at the head of the chain and consulted
before the store and before any blob is loaded.

The protocol starts with the smallest request that can carry an answer:
object names alone.  A request is the pathname and the pair's
old-oid/new-oid, with no content.  The process answers with hunk lines,
with a zero-hunk success that asserts the blobs equivalent (trailing
newlines included), or with status=need-content, on which the pair
falls through to the builtin answer.  This serves the two shapes that
need no content pushed to them: a cache keyed on the blob pair, and a
process that fetches the blobs itself (for example over "git cat-file
--batch").  A pair whose side is not a stored blob carries a NULL id;
the provider sends no request and passes it.  Because Git holds no
content for the exchange, the answer is used as sent: hunks are
validated for order, overlap, lockstep alignment, and magnitude, then
replayed without the normalization xdiff applies to diffs it computes
itself.  The magnitude bound is the blobs' sizes, read from the object
database without loading content: a blob of N bytes holds at most N
lines.

Because the process's answer is authoritative, it outranks the store,
and its head-of-chain position says so.  A pair the process answers
never reaches the store and is never recorded, so nothing it produces
enters the store, which holds the builtin answer only.  A request it
does not answer, whether need-content, a missing capability, or a
missing id, passes down the chain to the builtin answer, which is what
the store serves, so the store may serve such a pair and a warming run
may record it.  Entries recorded before a process was configured are
not purged; a pair the process answers ignores them, and "git diff-hunks
clear" discards them.

The provider gates itself per request.  The driver is looked up by the
old-side path, so a renamed file resolves to the same driver, and by
the repository-relative path, so a diff.relative run from a
subdirectory names the pair the same way.  Options the process is never
told about select no process: the whitespace-ignoring options, -I,
--anchored, and an algorithm forced by option or configuration (blame
routes its algorithm through xdl_opts, so --histogram is covered).  The
request gains its last field, the path; the consumers change only by
filling it, and neither names the process.

The provider's state is its repository's pool of running processes,
keyed by the configured command, so drivers sharing a command share a
process, a submodule speaks to its own, and releasing the provider
(from repo_clear()) stops them.  The pool owns a copy of each command
string, so an entry outlives a config re-read.  A command that fails
stays as an entry that is not retried: its request and every later one
pass, so the store may serve the path for the rest of the command.

A protocol error in a response never kills the command.  The response
is read through a packet reader gentle about framing, so an error takes
one path: a single warning, the process stopped and marked failed, and
the builtin diff for the rest of the command.  That covers garbage
bytes, a truncated response, an empty packet, a bare status, and an
unrecognized status.  Semantically invalid coordinates cost only their
pair: the response is drained, the pair is computed, and the process
stays alive.  A path the protocol cannot carry (an embedded newline, or
one too long for a packet) falls back per path rather than costing the
command its process.  The handshake keeps one fatal check: a process
that announces a capability Git did not request aborts the command, as
the long-running filter protocol does.

Consulting is allowed per command, following the allow_textconv
precedent.  "git diff", "git log" and "git show", and "git blame" set
allow_diff_process; the plumbing diff commands and the interactive-patch
machinery never set it, so scripted and staging output stays builtin.
The options adjust the flag:

- --no-ext-diff clears it and --ext-diff sets it;
- --diff-process and --no-diff-process set and clear it alone, leaving
  external diff drivers as they were;
- format-patch clears it unconditionally, so a generated patch applies
  for recipients without the process;
- range-diff passes --no-ext-diff to the "git log" it compares.

git blame and the summary formats consult the process.  For blame, a
pair reported equivalent emits no hunks, so the whole commit passes to
its parent.  In the stat formats such a pair sums to a zero-count entry,
which the "nothing changed" rule omits, as under -w.  The subprocess is
long-running: one startup cost across a traversal, one round-trip per
consulted pair.  Answers travel in struct xdl_hunk, new in
xdiff-interface.h, holding xdiff's 1-based coordinates; nothing feeds
them back to xdiff, since only coordinate consumers consult.

A content-carrying request is the natural extension: it would serve
sides that are not stored blobs and processes that want content pushed
to them, and bring patch output and log -L's range tracking to the same
answer.  As it stands, a process's answers show in blame and the summary
formats while patch output stays builtin.

t4080 exercises the protocol, the per-command gate, and the error paths:

- each adversarial response shape warns and falls back to builtin, the
  request log proving which failures disable the process and which keep
  it alive (a malformed hunk line, coordinates past the blob size, a
  count overflowing strtol(), overlapping or misaligned hunks, an
  unrecognized status, a bare status, an empty packet, a mid-response
  crash, and raw garbage);
- a capability-less process and status=abort degrade without noise, and
  a failed start warns once and returns the path to the store;
- a trailing token on a hunk line is ignored, pinning field
  appendability;
- positive consults for git diff, git show, and diff-tree under
  --ext-diff and --diff-process; textconv output and gitlink sides are
  never identified; a diff.relative run consults by the repo-relative
  path;
- the equivalence answer is pinned from both consumers, and a warming
  run past a deferring process records the pair for a later read.

Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-03 07:43:11 -07:00
..
RelNotes The 22nd batch 2026-09-02 09:21:59 -07:00
config diff: consult oid-only hunk providers via diff.<driver>.process 2026-09-03 07:43:11 -07:00
howto
includes
mergetools
technical Merge branch 'jc/rerere-doc-typofix' 2026-09-02 09:21:59 -07:00
.gitignore
BreakingChanges.adoc
CodingGuidelines
DecisionMaking.adoc
Makefile diff-hunks: add the store format, library, and command 2026-09-03 07:43:08 -07:00
MyFirstContribution.adoc Merge branch 'wy/doc-myfirstcontribution-trim-quotes' 2026-07-19 10:42:18 -07:00
MyFirstObjectWalk.adoc
ReviewingGuidelines.adoc
SubmittingPatches Merge branch 'ss/submittingpatches-typofix' 2026-08-25 10:53:32 -07:00
ToolsForGit.adoc
asciidoc.conf.in doc: convert git-bisect to synopsis style 2026-05-25 20:05:44 +09:00
asciidoctor-extensions.rb.in
blame-options.adoc
build-docdep.perl
cat-texi.perl
cmd-list.sh
config.adoc diff-hunks: add the store format, library, and command 2026-09-03 07:43:08 -07:00
date-formats.adoc doc: document and test `@` prefix for raw timestamps 2026-06-02 18:13:12 +09:00
diff-algorithm-option.adoc diff: consult oid-only hunk providers via diff.<driver>.process 2026-09-03 07:43:11 -07:00
diff-context-options.adoc
diff-format.adoc
diff-generate-patch.adoc
diff-options.adoc diff: consult oid-only hunk providers via diff.<driver>.process 2026-09-03 07:43:11 -07:00
doc-diff
docbook-xsl.css
docbook.xsl
docinfo-html.in
everyday.adoco
fetch-options.adoc Merge branch 'wy/docs-typofixes' 2026-06-16 09:01:03 -07:00
fix-texi.sh
for-each-ref-options.adoc
format-patch-caveats.adoc doc: convert git-am synopsis and options to new style 2026-05-25 20:05:44 +09:00
format-patch-end-of-commit-message.adoc doc: convert git-am synopsis and options to new style 2026-05-25 20:05:44 +09:00
fsck-msgids.adoc
generate-mergetool-list.sh
git-add.adoc add: introduce '--resolved' option 2026-07-31 08:52:16 -07:00
git-am.adoc doc: convert git-am synopsis and options to new style 2026-05-25 20:05:44 +09:00
git-annotate.adoc
git-apply.adoc doc: convert git-apply synopsis and options to new style 2026-05-25 20:05:44 +09:00
git-archimport.adoc
git-archive.adoc
git-backfill.adoc pack-objects: support sparse:oid filter with path-walk 2026-05-24 18:41:06 +09:00
git-bisect-lk2009.adoc
git-bisect.adoc bisect: add --reset-when-found to leave when done 2026-08-02 16:34:36 -07:00
git-blame.adoc blame: reserve mark column only if necessary 2026-07-06 07:34:48 -07:00
git-branch.adoc branch: add --dry-run for --delete-merged 2026-08-05 10:08:28 -07:00
git-bugreport.adoc
git-bundle.adoc
git-cat-file.adoc cat-file: unify default format 2026-08-07 18:50:08 -07:00
git-check-attr.adoc
git-check-ignore.adoc
git-check-mailmap.adoc
git-check-ref-format.adoc
git-checkout-index.adoc
git-checkout.adoc
git-cherry-pick.adoc
git-cherry.adoc
git-citool.adoc
git-clean.adoc
git-clone.adoc
git-column.adoc
git-commit-graph.adoc
git-commit-tree.adoc
git-commit.adoc
git-config.adoc doc: git-config: escape erroneous highlight markup 2026-06-11 12:08:17 -07:00
git-count-objects.adoc
git-credential-cache--daemon.adoc
git-credential-cache.adoc
git-credential-store.adoc
git-credential.adoc
git-cvsexportcommit.adoc
git-cvsimport.adoc
git-cvsserver.adoc
git-daemon.adoc
git-describe.adoc
git-diagnose.adoc
git-diff-files.adoc
git-diff-hunks.adoc diff-hunks: add the store format, library, and command 2026-09-03 07:43:08 -07:00
git-diff-index.adoc
git-diff-pairs.adoc
git-diff-tree.adoc
git-diff.adoc
git-difftool.adoc
git-fast-export.adoc fast-export: standardize usage string and SYNOPSIS 2026-07-13 08:54:29 -07:00
git-fast-import.adoc fast-import: use parse_options() for command line options 2026-08-11 07:33:17 -07:00
git-fetch-pack.adoc
git-fetch.adoc
git-filter-branch.adoc
git-fmt-merge-msg.adoc
git-for-each-ref.adoc
git-for-each-repo.adoc
git-format-patch.adoc doc: convert git-format-patch synopsis and options to new style 2026-07-23 14:26:58 -07:00
git-format-rev.adoc doc: format-rev: use [synopsis] on code block 2026-08-17 13:33:06 -07:00
git-fsck-objects.adoc
git-fsck.adoc
git-fsmonitor--daemon.adoc
git-gc.adoc
git-get-tar-commit-id.adoc
git-grep.adoc doc: convert git-grep synopsis and options to new style 2026-05-25 20:05:44 +09:00
git-gui.adoc
git-hash-object.adoc
git-help.adoc
git-history.adoc builtin/history: implement "drop" subcommand 2026-07-03 10:32:47 -07:00
git-hook.adoc doc: hook: don’t self-link via config include 2026-05-22 09:36:20 +09:00
git-http-backend.adoc
git-http-fetch.adoc http: avoid concurrent appends to partial packs 2026-07-27 12:57:20 -07:00
git-http-push.adoc
git-imap-send.adoc doc: convert git-imap-send synopsis and options to new style 2026-07-23 14:26:58 -07:00
git-index-pack.adoc
git-init-db.adoc
git-init.adoc
git-instaweb.adoc
git-interpret-trailers.adoc trailers: stop recognizing URLs as trailers 2026-08-21 08:53:27 -07:00
git-last-modified.adoc
git-log.adoc
git-ls-files.adoc
git-ls-remote.adoc
git-ls-tree.adoc
git-mailinfo.adoc
git-mailsplit.adoc
git-maintenance.adoc
git-merge-base.adoc
git-merge-file.adoc
git-merge-index.adoc
git-merge-one-file.adoc
git-merge-tree.adoc
git-merge.adoc
git-mergetool--lib.adoc
git-mergetool.adoc
git-mktag.adoc
git-mktree.adoc
git-multi-pack-index.adoc midx: support custom `--base` for incremental MIDX writes 2026-05-20 11:31:13 +09:00
git-mv.adoc
git-name-rev.adoc
git-notes.adoc
git-p4.adoc
git-pack-objects.adoc pack-objects: support `--delta-islands` with `--path-walk` 2026-06-21 16:26:14 -07:00
git-pack-redundant.adoc
git-pack-refs.adoc
git-patch-id.adoc
git-prune-packed.adoc
git-prune.adoc
git-pull.adoc
git-push.adoc
git-quiltimport.adoc
git-range-diff.adoc Merge branch 'sp/doc-range-diff-takes-notes' 2026-05-31 10:00:39 +09:00
git-read-tree.adoc
git-rebase.adoc
git-receive-pack.adoc
git-reflog.adoc
git-refs.adoc doc: refs: linkgit to git-maintenance(1) 2026-08-06 10:32:49 -07:00
git-remote-ext.adoc
git-remote-fd.adoc
git-remote-helpers.adoco
git-remote.adoc
git-repack.adoc builtin/repack: add guards for --drop-filtered 2026-08-13 13:34:50 -07:00
git-replace.adoc
git-replay.adoc doc: replay: move “default” to the right-hand side 2026-07-30 09:15:04 -07:00
git-repo.adoc repo: add path.gitdir with absolute and relative suffix formatting 2026-06-23 21:15:52 -07:00
git-request-pull.adoc doc: convert git-request-pull synopsis and options to new style 2026-07-23 14:26:58 -07:00
git-rerere.adoc
git-reset.adoc
git-restore.adoc
git-rev-list.adoc
git-rev-parse.adoc
git-revert.adoc
git-rm.adoc
git-send-email.adoc doc: convert git-send-email synopsis and options to new style 2026-07-23 14:26:58 -07:00
git-send-pack.adoc
git-sh-i18n--envsubst.adoc
git-sh-i18n.adoc
git-sh-setup.adoc
git-shell.adoc
git-shortlog.adoc
git-show-branch.adoc
git-show-index.adoc
git-show-ref.adoc
git-show.adoc
git-sparse-checkout.adoc doc: fix typos via codespell 2026-06-08 00:21:35 +09:00
git-stage.adoc
git-stash.adoc
git-status.adoc
git-stripspace.adoc
git-submodule.adoc
git-svn.adoc
git-switch.adoc
git-symbolic-ref.adoc
git-tag.adoc
git-tools.adoc
git-unpack-file.adoc
git-unpack-objects.adoc
git-update-index.adoc
git-update-ref.adoc
git-update-server-info.adoc
git-upload-archive.adoc
git-upload-pack.adoc
git-url-parse.adoc
git-var.adoc
git-verify-commit.adoc
git-verify-pack.adoc
git-verify-tag.adoc
git-version.adoc
git-web--browse.adoc
git-whatchanged.adoc
git-worktree.adoc
git-write-tree.adoc
git.adoc
gitattributes.adoc diff: consult oid-only hunk providers via diff.<driver>.process 2026-09-03 07:43:11 -07:00
gitcli.adoc
gitcore-tutorial.adoc
gitcredentials.adoc
gitcvs-migration.adoc
gitdatamodel.adoc
gitdiffcore.adoc
giteveryday.adoc
gitfaq.adoc
gitformat-bundle.adoc
gitformat-chunk.adoc
gitformat-commit-graph.adoc
gitformat-diff-hunks.adoc diff-hunks: add the store format, library, and command 2026-09-03 07:43:08 -07:00
gitformat-index.adoc
gitformat-loose.adoc
gitformat-pack.adoc
gitformat-signature.adoc
gitglossary.adoc
githooks.adoc
gitignore.adoc
gitk.adoc
gitmailmap.adoc
gitmodules.adoc
gitnamespaces.adoc
gitpacking.adoc
gitprotocol-capabilities.adoc
gitprotocol-common.adoc
gitprotocol-http.adoc
gitprotocol-pack.adoc
gitprotocol-v2.adoc cat-file: unify default format 2026-08-07 18:50:08 -07:00
gitremote-helpers.adoc
gitrepository-layout.adoc
gitrevisions.adoc
gitsubmodules.adoc
gittutorial-2.adoc
gittutorial.adoc
gitweb.adoc
gitweb.conf.adoc
gitworkflows.adoc
glossary-content.adoc
i18n.adoc
install-doc-quick.sh
install-webdoc.sh
line-range-format.adoc
line-range-options.adoc diffcore-pickaxe: limit -G to the -L tracked range 2026-09-03 07:14:39 -07:00
lint-delimited-sections.perl
lint-documentation-style.perl
lint-fsck-msgids.perl
lint-gitlink.perl
lint-man-end-blurb.perl
lint-man-section-order.perl
lint-manpages.sh
manpage-bold-literal.xsl
manpage-normal.xsl
manpage.xsl
merge-options.adoc
merge-strategies.adoc
meson.build diff-hunks: add the store format, library, and command 2026-09-03 07:43:08 -07:00
object-format-disclaimer.adoc
pack-refs-options.adoc
pretty-formats.adoc
pretty-options.adoc
pull-fetch-param.adoc
ref-reachability-filters.adoc
ref-storage-format.adoc
rerere-options.adoc
rev-list-description.adoc
rev-list-options.adoc graph: add --[no-]graph-indent and log.graphIndent 2026-07-14 07:32:51 -07:00
revisions.adoc remote: find tracking branches for URL push destinations 2026-07-22 11:29:49 -07:00
scalar.adoc
sequencer.adoc
signoff-option.adoc
texi.xsl
trace2-target-values.adoc
transfer-data-leaks.adoc
urls-remotes.adoc
urls.adoc
user-manual.adoc