Expand description
git format-patch mail-rendering primitives.
The full format-patch command in the grit binary parses argv, walks the
revision range, reads config, runs rename detection, talks to the notes /
range-diff machinery, decides on output files vs. stdout, prints the written
filenames, and maps exit codes. Those responsibilities — argv parsing,
revision selection, config/env resolution, file output, terminal printing,
and the crate-internal log/range-diff dispatch — stay in the CLI.
What lives here is the self-contained, presentation-free core of mbox patch
assembly: the byte-exact RFC 2047 / RFC 822 header encoders and folders, the
[PATCH n/m] subject builder, the filename sanitizer/truncator, the
committer-date formatter, the threading-header writer, and the small string
transforms (mboxrd escaping, ident formatting, reroll/version labels) that
git’s pretty.c, utf8.c, and builtin/log.c use to turn a commit plus
its diff into an email. Each function computes a result from plain strings,
bytes, or a CommitData alone — no argv, no terminal output, and no
process/filesystem state — so the CLI can call them while still owning every
I/O and config decision.
Enums§
Functions§
- add_
rfc822_ quoted - add_
rfc2047 - Append
lineRFC2047-Q-encoded toout, folding at 76 columns with continuation lines. - add_
wrapped_ text - Port of git’s
strbuf_add_wrapped_textfor ASCII text (used for subject/From folding).indent1negative means-indent1columns are already consumed on the current line. - apply_
rfc_ prefix - Apply the
--rfc[=<str>]modifier to a subject prefix. DefaultRFCprepends “RFC “; a value starting with-appends(...); else replaces leader. - build_
patch_ filename - Build the full patch basename
<file_prefix><NNNN>-<sanitized-subject>.patch, truncating the whole basename tofilename_max_length - 1chars (Git’sFORMAT_PATCH_NAME_MAX, default 64). - build_
patch_ subject - Build a patch Subject value:
[<prefix> n/m] <subject>with proper handling of empty prefix. - commit_
author_ timestamp - encode_
display_ name - Encode a display name portion of an email address.
- encode_
email_ address - Encode an email address for use in email headers.
- encode_
email_ address_ for_ charset - Like
encode_email_addressbut usescharset_labelfor RFC 2047 when non-ASCII. - ensure_
trailing_ slash - Ensure a directory prefix ends with
/. - first_
subject_ line - The first physical line of the subject (used for the patch filename, matching git which stops
format_sanitized_subjectat the first newline). Returns the whole trimmed message if single-line. - flatten_
subject - Flatten a multi-line commit message into a single-line subject (paragraph join with spaces).
- format_
date_ rfc2822 - Extract date from identity string and format as RFC 2822-like.
- format_
ident - Format an identity string as “Name
”. - is_
valid_ from_ ident - Validate a
--from=<ident>value: must look like an email ident (contain@). - last_
line_ length - Length of the last line of
s(bytes after the final\n). - mboxrd_
escape - Apply mboxrd
>Fromescaping to body lines ifmboxrdis set. - needs_
rfc822_ quoting - needs_
rfc2047_ encoding - True if
lineneeds RFC2047 encoding (non-ASCII, newline, or=?). - notes_
value_ to_ ref - Map a
format.notes/--notes=value to a full notes ref (refs/notes/<x>unless already a fullrefs/...ref). An empty value ortruemeans the defaultrefs/notes/commits. - path_
matches_ spec - prev_
version_ label Interdiff against v<N-1>:label, orNoneif reroll is not an integer >= 2.- push_
indented - Append
bodytoout, indenting every line by two spaces (matchingsed -e "s/^/ /"). - rfc2047_
charset_ label - Charset token for RFC 2047
=?charset?q?...?=(matches Git test expectations). - rfc2047_
encode - RFC 2047 UTF-8 quoted-printable encoding for an email display name.
- sanitize_
reroll - Sanitize a reroll-count string for use in a filename prefix (
v<x>-), like git’s sanitizer. - sanitize_
subject - Sanitize a subject line for use as a filename, matching Git’s
format_sanitized_subjectbyte-for-byte: runs of non-title bytes collapse into a single-, consecutive.collapse into one, and trailing./-are trimmed. Operates on raw bytes (non-ASCII → separators). - strip_
angles - write_
addr_ header - Write a
From:/recipient address header<Name> <mail>, encoding/folding the display name. - write_
folded_ header - Write a folded email header with multiple values.
- write_
signature - Write the trailing signature block
-- \n<sig>\n\n, or nothing when suppressed. - write_
subject_ header - Write the
Subject:header (already-built subject string), encoding/folding like git. - write_
thread_ headers - Write In-Reply-To / References / Message-ID threading headers.