Skip to main content

Crate sley_diff_merge

Crate sley_diff_merge 

Source

Modules§

range
Patch-series assignment for range-diff.
render
Unified-diff / patch RENDERER: turn a computed file diff (the old/new blob contents) into the textual unified-diff hunk body git’s diff.c emit path produces (emit_diff_symbol / fn_out_consume).
ws
Whitespace-rule engine — a port of git’s ws.c / ws.h.

Structs§

ApplyFileOptions
Options for apply_file_patch_with_options, mirroring the git apply flags that change fragment placement.
BString
A byte string for git paths and similar on-disk identifiers.
BinaryHunk
One binary hunk: the encoding method and the still-deflated data, plus the declared original (inflated) length.
BinaryPatch
A GIT binary patch payload: a mandatory forward hunk (preimage → postimage) and an optional reverse hunk (postimage → preimage), mirroring git’s parse_binary.
Conflict
DiffLine
A single line of a blob, slicing into the original buffer.
DiffNameStatusOptions
FilePatch
A patch targeting a single file. Produced by parse_unified_patch.
Hunk
A single @@ -old_start,old_len +new_start,new_len @@ hunk.
IndexGitlinkEntry
IndexWorktreeDiff
MergeBlobOptions
Labels and style controlling merge_blobs conflict markers.
MergeBlobResult
The outcome of a 3-way blob merge.
MergeStages
Per-stage higher-order index entries for a conflicted path.
MergeTreesOptions
Options controlling a merge_trees run.
MergeTreesResult
The outcome of a 3-way tree merge: the merged top-level tree plus per-path detail and a clean/conflicted flag.
MergedPath
One resolved/conflicted path in the merged tree.
NameStatusEntry
PatchPathOptions
Path-resolution options for parse_unified_patch_with_options, mirroring git apply’s -p<n> strip (p_value) and --directory=<root> prefix.
RejectApply
The outcome of a hunk-by-hunk apply (git apply --reject).
RenameDetectionOptions
Options controlling inexact (similarity-based) rename and copy detection, layered additively on top of DiffNameStatusOptions.
WsApplyOptions
Options for apply_file_patch_ws.
WsIgnore
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.

Enums§

ApplyOutcome
Outcome of applying a FilePatch to a base buffer.
BinaryMethod
How a binary hunk encodes the postimage.
ConflictStyle
Which conflict-marker style merge_blobs emits.
DiffAlgorithm
DiffOp
A run-length entry in a Myers edit script.
DirectoryRenames
How directory-rename detection behaves, mirroring git’s merge.directoryRenames configuration.
FileChange
HunkLine
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.
MergeConflictKind
The kind of conflict recorded for a path, used to render the stable conflict-type token and human message.
MergeFavor
Whether to favour one side wholesale for textual conflicts (-Xours / -Xtheirs), or to leave conflict markers in place.
MergeInfoMessage
Non-conflict merge information that porcelain commands may print.
NameStatus
WsApplyOutcome
Outcome of apply_file_patch_ws.

Constants§

DEFAULT_RENAME_THRESHOLD
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).
S_IFMT
The bit mask isolating the file-type bits of a git mode (S_IFMT). Regular files are 0o100000, symlinks 0o120000, gitlinks 0o160000, trees 0o040000.

Functions§

apply_file_patch
Apply a single-file patch to base, returning the patched bytes.
apply_file_patch_rejecting
Apply a single-file patch hunk-by-hunk, collecting the hunks that do not apply rather than rejecting the whole patch — git apply --reject.
apply_file_patch_with_options
Apply a single-file patch with explicit fragment-placement options.
apply_file_patch_ws
Whitespace-aware single-file apply — git’s apply_one_fragment matching path.
basename_min_score
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%.)
basename_rename_matches
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).
blob_similarity
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).
count_changes
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.
diff_lines_with_algorithm
Dispatch to the line-diff implementation selected by algorithm.
diff_name_status_empty_tree_with_options
diff_name_status_empty_tree_with_rename_options
Diff the empty tree against right_tree with full rename/copy options.
diff_name_status_head_index
diff_name_status_head_index_with_options
diff_name_status_head_index_with_rename_options
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.
diff_name_status_head_worktree
diff_name_status_head_worktree_with_options
diff_name_status_head_worktree_with_rename_options
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.
diff_name_status_index_worktree
diff_name_status_index_worktree_for_diff_files_with_options
Index-vs-worktree name-status for git diff-files (plumbing), which selects changed paths by the cached stat rather than by content.
diff_name_status_index_worktree_for_diff_files_with_rename_options
As diff_name_status_index_worktree_for_diff_files_with_options, but with full rename/copy options (the git diff-files -M/-C path). The stat-dirty augmentation is identical; only the underlying content diff differs.
diff_name_status_index_worktree_with_options
diff_name_status_index_worktree_with_options_and_gitlinks
diff_name_status_index_worktree_with_rename_options
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.
diff_name_status_index_worktree_with_rename_options_and_gitlinks
diff_name_status_tree_index_with_options
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.
diff_name_status_tree_index_with_rename_options
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.
diff_name_status_tree_worktree_with_options
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.
diff_name_status_tree_worktree_with_rename_options
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.
diff_name_status_trees_with_options
diff_name_status_trees_with_rename_options
Diff two trees with full rename/copy options, including inexact (similarity) detection when RenameDetectionOptions::detect_inexact is set.
flatten_tree
Read a tree object (by oid) into a flattened path -> (mode, oid) map, descending into subtrees. The canonical empty tree yields an empty map.
git_patch_delta
Apply a git delta (delta.c patch_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.
gitlink_broken_gitdir
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).
gitlink_git_dir
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.
gitlink_head_oid
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.
histogram_diff_lines
Compute a line-level edit script transforming old into new using the histogram diff algorithm (as in git diff --histogram, derived from JGit).
is_mergeable_file_mode
True for a plain file blob (regular or executable) — i.e. a mode whose content can be textually 3-way merged. Symlinks and gitlinks are excluded.
is_type_change
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 (0o1006440o100755) is NOT a typechange — same S_IFMT.
merge_blobs
Perform a 3-way merge of three blobs using the diff3 algorithm.
merge_entry_maps
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.
merge_trees
3-way merge of three trees into a single merged tree.
modify_or_type_change
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).
myers_diff_lines
Compute a minimal line-level edit script transforming old into new using Myers’ O(ND) difference algorithm.
myers_diff_lines_ws
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.
parse_unified_patch
Parse a unified/git diff into one FilePatch per file it touches.
parse_unified_patch_with_options
Parse a unified/git diff, applying -p<n> strip and --directory prefix to every resolved pathname exactly as git apply does.
parse_unified_patch_with_recount
Parse a unified/git diff, optionally ignoring hunk header line counts and recounting them from the hunk body. This mirrors git apply --recount.
path_basename
The basename of a slash-separated path: the portion after the last / (git’s get_basename).
patience_diff_lines
Compute a line-level edit script transforming old into new using the patience diff algorithm (Bram Cohen’s algorithm, as in git diff --patience).
patience_diff_lines_anchored
As patience_diff_lines, but pins lines whose content has any of anchors as a byte prefix into the common subsequence (git’s --anchored=<text>).
render_reject_hunk
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_file_patch
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.
split_lines
Split a blob into lines, preserving the exact bytes of each line.
symlink_target_bytes
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.

Type Aliases§

MergeEntryMap
Flattened tree: repository-relative path -> (mode, blob/symlink/gitlink oid).