Whitespace-ignore flags for line comparison, mirroring git’s
XDF_WHITESPACE_FLAGS (-w, -b, --ignore-space-at-eol,
--ignore-cr-at-eol). Only one of the whitespace flavours is honoured per
git’s precedence (-w ⊃ -b ⊃ --ignore-space-at-eol ⊃
--ignore-cr-at-eol); when several are set, the strongest wins, matching
the cascade in xdl_recmatch.
A single line inside a hunk. The stored bytes never include the trailing
line terminator; whether the line is terminated by \n is tracked
separately on the Hunk (see Hunk::old_no_newline /
Hunk::new_no_newline) so the no-final-newline case can be reproduced
byte-for-byte.
git’s default minimum similarity (as a percentage) for a pair of files to be
reported as a rename or copy. Matches git’s built-in -M/-C threshold
of 50% (DEFAULT_RENAME_SCORE is MAX_SCORE / 2).
The stricter score a basename match must reach: git’s min_basename_score
with the default GIT_BASENAME_FACTOR of 0.5, i.e. halfway between the
rename threshold and 100%. (For the default 50% threshold this is 75%.)
git’s find_basename_matches: among the still-unmatched rename sources and
destinations, pair those whose basename is UNIQUE on both sides and whose
similarity meets basename_min_score. Returns the (src_local, dst_local, score) pairings to apply before the full O(n·m) similarity matrix, so a
same-basename rename wins over a globally-more-similar different-basename
candidate (diffcore-rename.c).
Compute the content similarity of two blobs as an integer percentage in
0..=100, using git’s span-hash counting metric (see the module comment
above for the exact definition).
Sum, over every hash present in both maps, the smaller of the two byte
counts. This is git’s src_copied: the number of bytes that appear on both
sides (counting multiplicity via the per-hash byte totals).
git diffcore_count_changes(): span-hash byte accounting between two
blobs. Returns (src_copied, literal_added) — the bytes of src that
survive into dst, and the bytes of dst not accounted for by src.
--dirstat’s default “changes” damage is
(src.len() - src_copied) + literal_added.
HEAD-vs-index name-status with full rename/copy options, including inexact
(similarity) detection when enabled. All blob content (both sides) comes from
the object database.
HEAD-vs-worktree name-status with full rename/copy options, including inexact
(similarity) detection when enabled. Worktree blob content is read directly
from the working tree; HEAD-side blobs come from the object database.
Index-vs-worktree name-status with full rename/copy options, including inexact
(similarity) detection when enabled. Worktree blob content is read directly
from the working tree; index-side blobs come from the object database.
Name-status diff of an arbitrary tree against the index, the engine behind
git diff-index --cached <tree-ish>. Exact rename/copy detection follows
options; all blob content comes from the object database.
Tree-vs-index name-status with full rename/copy options, including inexact
(similarity) detection when enabled. Both sides read blob content from the
object database. Counterpart of
diff_name_status_head_index_with_rename_options for an arbitrary tree.
Name-status diff of an arbitrary tree against the working tree, the engine
behind plain git diff-index <tree-ish> (no --cached). New-side oids for
paths whose worktree contents differ from the index are cleared (rendered as
zeros), matching git, which only reports the worktree blob oid when it is
known-clean against the index.
Tree-vs-worktree name-status with full rename/copy options, including inexact
(similarity) detection when enabled. Worktree blob content is read directly
from the working tree (via an oid-keyed cache); tree-side blobs come from the
object database. As with diff_name_status_tree_worktree_with_options,
new-side oids for paths that differ from the index are cleared.
Apply a git delta (delta.cpatch_delta) to reconstruct the postimage from
base. The delta begins with the base size and result size as varints,
followed by copy (0x80 bit set: offset/size from base) and insert (literal
bytes) opcodes. Returns None on any malformed/inconsistent delta.
When sub_root holds a broken gitlink — a .git file whose gitdir:
pointer names a directory that no longer exists (e.g. the submodule’s git
directory was moved out of .git/modules/) — return that unresolved gitdir
path. git’s status / diff-index fail fatally (“not a git repository: …”)
here. Returns None for a valid gitlink (a .git directory, or a .git
file with a live gitdir) and for an unpopulated gitlink (no .git entry at
all), both of which git treats as non-fatal (the latter as unchanged).
Resolve the git directory of an embedded repository whose working tree is
at sub_root. A .git directory is returned as-is; a .git file is
followed through its gitdir: <path> pointer (a relative pointer resolves
against sub_root). Returns None when there is no .git entry or the
pointer does not name an existing directory.
Resolve the commit checked out in the embedded repository at sub_root
(the value a gitlink entry for that path records): its git directory’s
HEAD, followed through symbolic refs. None when sub_root is not a
repository or its HEAD does not resolve to a commit (e.g. an unborn
branch) — upstream’s resolve_gitlink_ref() < 0 case.
Whether a pair of (non-zero) modes constitutes a git “typechange”: the file
type bits (S_IFMT) differ. Mirrors diffcore.h’s DIFF_PAIR_TYPE_CHANGED
((S_IFMT & one->mode) != (S_IFMT & two->mode)). An exec-bit-only change
(0o100644 ↔ 0o100755) is NOT a typechange — same S_IFMT.
merge_trees operating on already-flattened entry maps. The merge
porcelains often hold the flattened maps already (e.g. cherry-pick builds
theirs from a picked commit’s tree), so this avoids re-reading them.
Classify a both-sides-present change whose entries already differ: a
NameStatus::TypeChanged when the modes’ S_IFMT bits differ, otherwise a
plain NameStatus::Modified. git sets DIFF_STATUS_TYPE_CHANGED before any
rename/modify resolution (diff.c ~6650).
Compute a line-level edit script transforming old into new, comparing
lines under the whitespace-ignore flags ignore while the returned ops
still index the original lines position-for-position.
Reconstruct the unified-diff text of one hunk for a .rej file. Mirrors the
raw fragment text git copies into <file>.rej: the @@ -os[,oc] +ns[,nc] @@
header (the ,1 count is omitted, matching git) followed by each line with
its /+/- prefix, plus the \ No newline at end of file note where the
old/new side’s final line is unterminated.
Reverse a file patch (git apply -R): swap the old/new names, modes, hunk
ranges, and no-newline flags, exchange add↔delete status, and flip every
Insert/Delete line. Applying the result undoes the original patch.
Read a symbolic link’s target as git stores it: the raw target path bytes,
with no trailing newline. This is the “content” of a symlink blob (mode
120000) — git’s diff_populate_filespec uses strbuf_readlink for a
worktree symlink rather than dereferencing it.