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§
- Hunk
Render Options - Hunk-shaping and styling options for
render_hunks. - 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§
- 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§
- render_
hunks - Render the unified-diff hunk body for a single file change into
out.
Type Aliases§
- Heading
Fn - Resolve the section heading for one candidate line.