Expand description
Tree and content diffs, rename detection, merge diffs, and related helpers.
Library guide: mod
use grit_lib::repo::{InitOptions, Repository};
let dir = tempfile::tempdir()?;
let _repo = Repository::init(dir.path(), &InitOptions::default())?;
let _ = _repo.diff();
Modules§
- combined_
diff_ patch - combined_diff_patch API (re-exported at this path).
- combined_
tree_ diff - Combined tree diff helpers for merge commits.
- fmt_
merge_ msg - Merge commit message formatting from FETCH_HEAD-style input.
- merge_
diff - Combined diff content for octopus merges.
- merge_
file - merge_file API (re-exported at this path).
- merge_
trees - merge_trees API (re-exported at this path).
- patch_
ids - patch_ids API (re-exported at this path).
- rerere
- rerere API (re-exported at this path).
- structured
- Structured line diffs for CLI and embedders (
grit diff,grit show). - userdiff
- Per-path diff driver (funcname) matching.
- ws
- ASCII whitespace helpers used by the diff engine.
Structs§
- Commit
Files Many Input - One commit’s identity for
Diff::commit_files_many_work, avoiding a second ODB read. - Commit
Files Many Options - Options for
Diff::commit_files_many. - Commit
Files Result - One commit’s diff output in
Diff::commit_files_many(same order as input oids). - Detect
Renames Options - Options for
detect_renames_with_policy. - Diff
- Compare trees, the index, and the working tree for one repository.
- Diff
Arguments - Resolved diff mode and normalized pathspecs.
- Diff
Entries Result - Tree or commit diff entries after rename detection, with an optional limit notice.
- Diff
Entry - A single diff entry representing one changed path.
- Diff
Files Output - Output of
build_file_diffs. - Diff
Filter - Typed include/exclude set for
DiffStatususing Git’s letter syntax. - Diff
Index ToWorktree Options - Additional inputs for
diff_index_to_worktree_with_options. - Diff
Options - Line-diff options shared by structured output, log patches, and benchmarks.
- Diff
Postprocess Options - Options for Git-style rename, copy, and break-rewrite post-processing on tree diffs.
- Diff
Postprocess Worktree - Index and git directory used to read canonical (clean) worktree bytes during break-rewrite post-processing on tree↔worktree diffs.
- Diff
Request - Unparsed
grit diffflags and operands, as the user typed them. - Diff
Stat - Per-file line counts plus totals for a whole diff.
- Diff
Totals - Summary across all files in a stat-style diff.
- File
Change - One changed path with both sides’ bytes loaded for diffing.
- File
Diff - One changed file with structured hunks and metadata (returned by
Diff::files). - File
Stat - One file’s row in a
DiffStat. - Hunk
Diff Bundle - Staged and unstaged file diffs for hunk id assignment (one staged scan per call).
- HunkId
- Twelve lowercase hex characters identifying one structured hunk within a side and path.
- Inexact
Rename Detection Skipped - Emitted when unmatched rename candidates exceed
diff.renameLimitafter exact and basename pairing. - Line
Stat - Line insertion/deletion counts for one file (
--numstat). - Listed
File Diff - One changed file with optional patch body or line counts (returned by
build_file_diffs). - LogPatch
Options - Options for
write_commit_log_patch. - Patch
Resolved Side - One file for
write_patch_resolved: diff metadata plus where each side’s content is. - Patch
Text Options - Options for
write_patch(git diff --binary-compatible output forgit apply). - Pickaxe
- Compiled pickaxe filter for
crate::rev_list::rev_list. - StatBar
- Column counts for one diffstat row’s change bar (see
LineStat::bar). - Tree
Diff Content - One tree diff entry with both sides loaded for line-level diffing.
- Tree
Diff Structured - Tree diff entry with structured line hunks ready for CLI rendering.
- Uncommitted
Diff - Staged, unstaged, and working-tree diffs over one loaded index.
- Unknown
Diff Algorithm - Unknown value for
DiffAlgorithm’sFromStrimplementation. - Whitespace
Mode - Whitespace handling for line diffs (
super::DiffOptions::whitespace).
Enums§
- Diff
Algorithm - Line diff algorithm names matching Git’s
diff.algorithmand--diff-algorithm. - Diff
Detail - How much content to compute for each changed file.
- Diff
Merges - How to diff a merge commit’s tree against its parents.
- Diff
Side - Which tree/index/worktree sides a hunk was produced from.
- Diff
Status - The kind of change between two sides of a diff.
- Diff
Target - What to compare when producing a structured file diff list.
- Hunk
IdError - Parse or format failure for
HunkId. - Invalid
Diff Filter - Unknown or unsupported
--diff-filterletter. - LogPatch
Binary Format - Binary file encoding inside a log/show patch (
git log -pvsgit diff --binary). - LogPatch
Commit Header - How much commit metadata precedes each patch in
write_commit_log_patch. - NoIndex
Error - Failure modes specific to
diff_paths. - Patch
Side - Where
write_patch_resolvedtakes the content of one side of a file. - Pickaxe
Error - Invalid pickaxe pattern.
- Pickaxe
Kind - Which pickaxe mode is active (
-Sor-G). - Rename
Detection - Rename detection policy for tree diffs.
- Resolve
Diff Arguments Error - Invalid
grit diffargument combinations or revision parsing failures.
Constants§
- RENAME_
DETECTION_ DISABLED - u32 rename APIs: thresholds
0–100run detection at that Git-Mpercent;RENAME_DETECTION_DISABLED(101) and above skip detection (legacy postprocess and--no-renamesplumbing). - WORD_
LEVEL_ INLINE_ MAX_ CHANGED_ FILES - Changed-file count above which word-level inline emphasis is skipped (human TTY diffs).
Functions§
- anchored_
unified_ diff - Compute a unified diff with anchored lines.
- annotate_
unified_ diff_ no_ newline_ at_ eof - Insert Git
\ No newline at end of fileafter-/+hunk lines when that side of the file lacks a trailing newline on the last line. - build_
file_ diffs - Fill per-file diff bodies for tree/index diff entries.
- build_
file_ diffs_ streaming - Build patch
FileDiffrows one entry at a time without retaining every hunk list. - bytes_
for_ diff - Classify raw blob bytes for line diffs (NUL in the first 8 KiB ⇒ binary).
- combined_
structured_ patch_ body - Format a
CombinedStructuredTextDiffas Git combined patch body bytes. - commit_
diff_ files - Build per-file diffs for one commit, using combined merge diff when requested.
- count_
changes_ with_ algorithm - Count insertions and deletions using the given line-diff algorithm.
- count_
git_ lines - Line count for diffstat/
--numstat, matching Git’scount_lines()indiff.c. - detect_
copies_ with_ policy - Like
detect_copies, but honors parallel thread policy and rename limits. - detect_
renames_ with_ policy - Like
detect_renames, but honorsindex.threads/--threadsviathread_policy. - diff_
commits - Diff the trees recorded at two commits (
baseis the old side,tipthe new side). - diff_
commits_ with_ renames - Diff the trees at two commits and pair deleted/added paths as renames when similar enough.
- diff_
index_ to_ tree - Compare the index against a tree (usually HEAD’s tree).
- diff_
index_ to_ worktree - Compare the index against the working tree.
- diff_
index_ to_ worktree_ for_ staging - Like
diff_index_to_worktree_with_options, but loads config fromrepository_git_dir(the main repository for linked worktrees) and persists each hashed worktree blob intoodbso staging can update the index without re-reading file contents. Symlinks store their target bytes. WithDiffIndexToWorktreeOptions::hash_blobs_without_write, returns the same blob IDs without writing objects, for staging previews. - diff_
index_ to_ worktree_ with_ options - Compare tracked index entries with the worktree, using link-target bytes for symlinks.
- diff_
index_ to_ worktree_ with_ renames - Diff the index against the working tree and pair deleted/added paths as renames when similar.
- diff_
paths - Diff two filesystem paths (files, directories, or one of each).
- diff_
tree_ to_ worktree - Compare a tree against the working tree.
- diff_
tree_ to_ worktree_ with_ git_ dir - Like
diff_tree_to_worktree, but loads config fromrepository_git_dir(linked worktrees / gitfiles). - diff_
tree_ to_ worktree_ with_ git_ dir_ and_ rules - Like
diff_tree_to_worktree_with_git_dir, with optional sharedcrate::worktree_rules::WorktreeRules. - diff_
trees - Compare two trees and return the list of changed entries.
- diff_
trees_ show_ tree_ entries - Like
diff_trees, but emit entries for tree objects themselves in addition to their recursive contents (Git’sdiff-tree -tbehavior). - diff_
trees_ with_ renames - Diff two trees and pair deleted/added paths as renames when content is similar enough.
- empty_
blob_ oid - Return the ObjectId for the empty blob object.
- for_
each_ tree_ diff_ structured - Visit structured tree diffs in path order without retaining every file’s hunks at once.
- format_
raw - Format a diff entry in Git’s raw diff format.
- format_
raw_ abbrev - Format a diff entry with abbreviated OIDs.
- hash_
worktree_ file - Hash normalized worktree bytes for a path (does not write to the object database).
- hunk_
diff_ bundle - Load unstaged diffs and the staged peer hunks on the same paths.
- hunk_
ids - Stable ids for
hunksin file order (0-based index matches vector position). - hunk_
ids_ with_ duplicate_ peers - Like
hunk_ids, butpeer_hunkson the same path (typically the other index/worktree side) participate in duplicate-body detection so ids stay stable when an earlier identical hunk moves to the staged side. - index_
mtime_ for_ diff - Effective index-file mtime for racy-git checks.
- line_
change_ counts - Count insertions and deletions between two text sides using
DiffOptions’s algorithm. - line_
diff_ unified_ hunk_ body - Unified hunk bodies (
@@…) for two text sides usingDiffOptions. - load_
object_ changes - Load both sides of each entry from the object database.
- load_
odb_ blob_ side_ for_ diff - Load ODB blob bytes for diffing, skipping inflation when over
core.bigFileThreshold. - mode_
from_ metadata - Derive a Git file mode from filesystem metadata.
- name_
status_ line - Git
--name-statusletter for a diff entry (uppercase status + rename score suffix). - normalize_
ignore_ space_ change - Normalise text like Git’s
-b/--ignore-space-change: on each line, collapse runs of whitespace to a single ASCII space and trim trailing spaces. - normalize_
ignore_ space_ change_ line - Normalise one line like Git’s
-b/--ignore-space-change(ASCII ws only). - parse_
diff_ rename_ threshold_ percent - Parse
-M/--find-renamesthreshold into Git’s 0–100 similarity percent. - peer_
hunks_ by_ primary_ path - Keep structured peer hunks only for paths present in the primary side.
- peer_
scope_ includes_ path - True when a diff entry’s displayed or old path is listed in the primary change set.
- postprocess_
diff_ entries - Apply break-rewrite, rename, and copy detection to a flat tree or index diff.
- read_
worktree_ side_ bytes_ for_ diff - Read worktree file bytes in Git (repository) form for line diffs against index or tree blobs.
- refresh_
index_ stat_ content_ verified - Refresh cached stat data for stage-0 file/symlink entries whose worktree content still matches the recorded OID but whose on-disk stat went stale.
- rename_
similarity_ score - Compute rename/copy similarity percentage (0–100) between two byte slices.
- renames_
from_ config diff.renames:falsedisables;trueor copy modes use default similarity.- resolve_
commit_ diff_ pathspecs - Normalize pathspecs for a commit or range diff to repository-relative form.
- resolve_
diff_ arguments - Parse
grit diffflags and positionals into aDiffTargetand pathspecs. - resolve_
diff_ request - Decide what
grit diffcompares and which paths it is limited to. - resolve_
indent_ heuristic - Resolve indent heuristic:
--no-indent-heuristicand--indent-heuristicoverride config. - sort_
entries_ by_ path - Stable-sort diff entries by
DiffEntry::pathin raw byte order, Git’s output order for diff lists (non-UTF-8 paths compare by their decoded bytes). - stat_
matches - Whether worktree metadata matches cached index stat data (Git
ie_match_stat/match_stat_data). - submodule_
porcelain_ flags - Inspect a checked-out submodule at
rel_path(relative tosuper_worktree) and return flags used forgit status --porcelain=v2submodule tokens. - text_
sides_ differ - Whether two text sides differ under whitespace options in
opts. - tree_
diff_ contents_ parallel - Load old/new blob bytes for each entry, using a worker pool when thresholds allow.
- tree_
diff_ stat_ parallel - Per-file line counts for stat modes (loads blobs, no hunk allocation).
- tree_
diff_ structured_ entry - Load sides and compute a structured line diff for one tree diff entry.
- tree_
diff_ structured_ parallel - Load sides and compute structured line diffs for each entry in parallel.
- tree_
oid_ of_ commit - Return the tree OID stored in a commit object.
- unified_
diff - Unified diff for two text sides with default
a//b/path prefixes. - unified_
diff_ histogram_ hunks_ only - Unified diff hunks for Git’s histogram algorithm (no
---/+++lines). - unified_
diff_ histogram_ ignore_ with_ prefix_ and_ funcname - Full unified diff (
---/+++/ hunks) using Git’s histogram algorithm, applying--ignore-blank-lines/-Ichange-record suppression (histogram_unified_body_ignore_fc) and then attaching function-name hunk headers likeunified_diff_histogram_with_prefix_and_funcname_indent. - unified_
diff_ with_ prefix_ and_ funcname - Same as
unified_diff_with_prefixwith optional custom hunk-header function-name matching. - unified_
diff_ with_ prefix_ and_ funcname_ and_ algorithm - Same as
unified_diff_with_prefix_and_funcnamebut allows callers to choose the line diff algorithm used for hunk generation. - write_
commit_ header_ and_ message - Write commit header (author, date, indented message) after the
commitline. - write_
commit_ log_ patch - Write one commit in
git log -p --no-color --format=%Hshape (no patch for merges). - write_
commits_ log_ patch - Like
write_commit_log_patchfor many commits (avoids re-reading parent commits). - write_
diff_ entry_ log_ patch - Write the
diff --githeader and unified body for oneDiffEntry. - write_
patch - Write
git diff --binary-style patches for tree diff entries (forgit apply). - write_
patch_ resolved - Write
git diff --binary-compatible patch text for files whose sides may live in memory, the object database, or the work tree (index and work-tree diffs). - write_
patch_ structured - Write patch text from precomputed
TreeDiffStructuredrows. - write_
paths_ patch - Write
git diff --no-index --binary-style patch bytes for two filesystem paths. - zero_
oid - Return the zero ObjectId.