Skip to main content

Module render

Module render 

Source
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 HeadingFn closure that, given a candidate line, returns its section heading (git’s def_ff default heuristic or a userdiff xfuncname pattern). 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_diff is set, the renderer delegates each hunk’s body to a HunkWordDiff hook, 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§

HunkRenderOptions
Hunk-shaping and styling options for render_hunks.
RenderColors
ANSI color palette for a unified diff, mirroring git’s diff_get_color slots. Each field is the raw escape sequence (empty string = no color).
TaggedLine
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).
WsErrorHighlight
Which line kinds get whitespace-error highlighting, plus the rule to check against. git’s --ws-error-highlight defaults to highlighting only new (+) lines.

Enums§

LineKind
The per-line origin marker for an emitted diff line.

Constants§

DEFAULT_CONTEXT
git’s default hunk context (-U3).

Traits§

HunkWordDiff
A hook that renders a single hunk’s body when --word-diff is active.

Functions§

render_hunks
Render the unified-diff hunk body for a single file change into out.

Type Aliases§

HeadingFn
Resolve the section heading for one candidate line.