Skip to main content

Module revspec

Module revspec 

Source
Expand description

Shared revision-spec resolver (issue #227, parent #226).

resolve_revision turns a user-supplied revision string into a single object Hash. It is the keystone the diff/checkout/ cherry-pick/bisect commands build on so they all accept the same grammar instead of each one hand-rolling a hash::from_hex call.

Accepted grammar (a deliberately small subset of git rev-parse):

  • Full hash — exactly 64 hex chars (lower or upper), present in the object store.
  • Short hash — a hex prefix of at least MIN_SHORT_HASH chars that unambiguously names exactly one object in the store. An ambiguous prefix (≥ 2 matches) is an error; a prefix matching none is an error.
  • Ref name — a branch (refs/heads/<name>), a tag (refs/tags/<name>), or the literal HEAD. Branches win over tags on a name collision (matching the precedence the existing checkout command used).
  • Suffix navigation — a <base> from any of the above followed by zero or more ~n / ^ / ^n steps walking the commit’s first-parent chain. ~n walks n first-parents (~ alone == ~1); ^ / ^n selects the n-th parent (^ == ^1, 1-based). ^0 is the commit itself. HEAD~2, main^, <hash>~1^2 all parse.

The resolver intentionally does NOT accept pathspecs, :/text message searches, reflog (@{n}) syntax, or ranges — A..B ranges are split by the caller (diff) before each end reaches here.

Enums§

RevError
Errors raised while resolving a revision string.

Constants§

MIN_SHORT_HASH
Minimum length of an accepted short-hash prefix. Shorter prefixes are rejected as too-ambiguous-by-construction rather than scanned, so a stray 1–3 char token (e.g. a typo’d ref) fails fast.

Functions§

resolve_revision
Resolve spec to a single object Hash.