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_HASHchars 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 literalHEAD. Branches win over tags on a name collision (matching the precedence the existingcheckoutcommand used). - Suffix navigation — a
<base>from any of the above followed by zero or more~n/^/^nsteps walking the commit’s first-parent chain.~nwalksnfirst-parents (~alone ==~1);^/^nselects the n-th parent (^==^1, 1-based).^0is the commit itself.HEAD~2,main^,<hash>~1^2all 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
specto a single objectHash.