Expand description
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).
This is the byte-for-byte port of git’s hunk emitter: @@ -os,oc +ns,nc @@ <heading> hunk headers, the +/-/context lines, and the
\ No newline at end of file marker. It owns hunk grouping (combining
changes whose context windows overlap, xdl_get_hunk’s distance > max_common break) and hunk range computation, then emits each hunk.
What this module deliberately does NOT own (those stay with the caller, which has the repository/userdiff/config context):
- The per-file metainfo header (
diff --git,index,---/+++, mode/similarity lines). That is repository- and option-shaped; the renderer only produces the hunk body that follows it. - Funcname section-heading resolution. The caller supplies a
HeadingFnclosure that, given a candidate line, returns its section heading (git’sdef_ffdefault heuristic or a userdiffxfuncnamepattern). The renderer does the scan upward for the nearest heading line; the caller only classifies a single line. - Word-diff body rendering. When
HunkRenderOptions::word_diffis set, the renderer delegates each hunk’s body to aHunkWordDiffhook, which the caller implements over its own word-diff machinery.
The seams keep the byte-shaping (ranges, headers, prefixes, no-newline markers, color spans) here — the part every diff-emitting command used to re-derive — while leaving the repository-coupled concerns in the consumer.
Structs§
- Change
Ignore - Color
Moved - Moved-code coloring configuration.
- Color
Moved Ws --color-moved-ws=<mode>comparison mode.- Combined
Render Options - Options controlling the combined-diff body emission.
- Hunk
Render Options - Hunk-shaping and styling options for
render_hunks. - Line
Range - A half-open
[start, end)line range (0-based) forlog -Lhunk restriction. Mirrors diff.c’sstruct range. - Render
Colors - ANSI color palette for a unified diff, mirroring git’s
diff_get_colorslots. Each field is the raw escape sequence (empty string = no color). - Tagged
Line - One line of the unified diff, with its origin and 0-based positions in the old/new files (used to compute hunk ranges and feed the word-diff hook).
- WsError
Highlight - Which line kinds get whitespace-error highlighting, plus the rule to check
against. git’s
--ws-error-highlightdefaults to highlighting only new (+) lines.
Enums§
- Color
Moved Mode --color-moved=<mode>hunk-body mode.- Line
Kind - The per-line origin marker for an emitted diff line.
Constants§
- DEFAULT_
CONTEXT - git’s default hunk context (
-U3).
Traits§
- Hunk
Word Diff - A hook that renders a single hunk’s body when
--word-diffis active.
Functions§
- enable_
function_ context - Encode
-W/--function-contextinto the context field without changing the option shape used by the existing renderer call sites. - render_
combined - Render a combined / merge diff body into
out. - render_
combined_ with render_combinedwith explicit options.- render_
hunks - Render the unified-diff hunk body for a single file change into
out.
Type Aliases§
- Change
Ignore Regex - Configuration for change-group suppression (
--ignore-blank-linesand-I<regex>). A change group is ignorable iff every old line and every new line it touches is blank (whenignore_blank_lines) or matches one of the-Iregexes (regex_match). Ignorable groups are kept out of hunk emission perxdl_get_hunk’s leading/isolated-ignorable removal. - Heading
Fn - Resolve the section heading for one candidate line.