Skip to main content

Module compare

Module compare 

Source
Expand description

Compare: resolve a base and a (possibly cross-fork) head, then report ahead/behind counts, the commit list and a structured diff.

Behaviour follows the JSS forge compareData, resolveHead, parseHeadSpec, parsePatch and renderDiff (cited by name only). A head is either a branch of the same repository (feature) or <owner>:<ref>, a branch of the named owner’s same-named repository. A cross-repository head is path-fetched into the base repository under the hidden, reusable ref refs/forge/heads/<owner>/<ref>; both ends of the fetch are forge-owned paths and no user-supplied URL is ever fetched.

Structs§

CommitSummary
One commit in a compare/PR list (JSS commitLog shape).
Compare
Everything a compare view needs.
DiffFile
One file of a structured diff (JSS parsePatch shape).
DiffLine
One diff line with its old/new numbers.
HeadRef
A resolved compare/PR head.
Hunk
One @@ hunk.

Enums§

LineKind
Kind of one diff line.

Constants§

COMMITS_PER_PAGE
Commits per page in compare and pull commit lists (JSS PER_PAGE).

Functions§

parse_head_spec
Parse ref or owner:ref against the base owner. None when invalid.
parse_patch
Parse unified git diff output into a structured per-file form, as JSS parsePatch does. Unlike the JSS parser, hunk bodies are consumed by the line counts in their @@ header, so a content line that happens to start with +++ or --- is classified as content, not as a file header.
render_diff
Render a structured diff as escaped HTML tables (JSS renderDiff).
valid_owner
JSS OWNER_NAME: alphanumeric first, then [A-Za-z0-9._-], at most 64.
valid_ref
JSS okRef: alphanumeric first, then [A-Za-z0-9._/-] (at most 201), no .., no //, no trailing /. Additionally refuses a trailing .lock or ., which git itself would reject, so a branch name can never address a lock file. A leading - is impossible, so it can never be read as an option.
valid_repo
JSS REPO_NAME (at most 128) tightened to the crate’s 100-character directory limit, with no .. and no .git suffix.
valid_sha
JSS SHA_RE: 4 to 64 lowercase hexadecimal characters.