swarmops resolve#
Name the changeset REV names, and whether REV is a ref's name.
- Group
read- Since
0.1.0- Mutates
- no
- Identity required
- no
- MCP tool
resolve_rev- Envelope op
resolve_rev- Exit codes
- 026
Syntax#
swarmops resolve [OPTIONS] <REV>Required arguments#
Syntax: <REV>.
The revision: a ref name, a full changeset id or a unique prefix of 12 or more of its hex digits, then any number of ~N suffixes.
Optional arguments#
The command also takes the global options.
Examples#
swarmops --repo [tmp]/store resolve main{
"ok": true,
"op": "resolve_rev",
"api": 1,
"result": {
"id": "[c2]",
"kind": "ref"
},
"meta": {
"repo": "[tmp]/store",
"elapsed_ms": "[elapsed_ms]",
"resolved": {
"main": "[c2]"
},
"auth": "trust"
}
}Exit code 0. Recorded by the CLI tests. A name in square brackets, such as [tmp] or [c1], stands for what differs from run to run: the test's temporary directory, an id, a time.
No recorded example yet.
Details#
resolve answers one question: which changeset does this revision name right now? Every other
read resolves its revisions the same way, in the same snapshot it then reads, so resolve is how
a script or an agent fixes a revision to a full id before it does anything else with it.
How a revision resolves#
A revision is a base, then any number of ~N suffixes:
| Base | Example | Resolves to |
|---|---|---|
| A ref's name | main, release/1.0 | The changeset the ref names in this snapshot. |
| A full changeset id | 64 hex digits | That changeset, if the store holds it. |
| An id prefix | 12 to 63 hex digits, either case | The one changeset whose id starts with it. |
Each ~N walks N first parents back, and the suffixes add up: main~1~1 is main~2, and
main~0 is main's own changeset. A merge's other parents are never walked.
kind is ref only when REV is exactly a ref's name. Anything else is changeset, including a
ref's name with a suffix such as main~0, and a full id that a ref happens to name. A ref
result names what the ref holds now, and moves when the ref does; the id you got does not.
The envelope's meta.resolved maps REV to the same id, as it does for every revision any
command resolves.
Patterns#
- Pin once, read many times. Resolve
mainonce and pass the fullidto every latercat,ls,difforlogof the same task. Each command takes its own snapshot, so two commands that both saymaincan read two different changesets if another agent lands between them. - Read what a compare-and-swap needs.
ref set --expect,ref delete --expectandcommit --parent ... --advanceprotect only when they get the full id you read. Take it fromresult.idhere, not from the ref's name. - Check a revision an agent was handed. A prefix copied from a log, or a
main~Na person typed, resolves here without reading any file, and the error says what is wrong with it. - Tell a ref from an id.
kindsays whether the caller passed a moving name or a fixed changeset, for a tool that treats the two differently.
Errors and their causes#
E_INVALID_ARG(exit 2): REV is not in the grammar.HEAD,main^,main~without a number,main~-1, an empty string, a ref name outsidemainandrelease/<name>(such asMainorfoo), a prefix shorter than 12 hex digits, and~Nsuffixes whose sum overflows a 64-bit count are all refused here. The hint gives the grammar.E_REV_NOT_FOUND(exit 6): REV is well formed but names nothing: a ref that does not exist (the hint isswarmops ref list), an id or prefix of no changeset (an id of a blob or a tree among them; the hint isswarmops log), or a~Npast the first changeset of the history (the hint isswarmops log <base>). A new store has nomainuntil something creates it, such as a firstcommit --advance main, soresolve mainon it isE_REV_NOT_FOUND.E_AMBIGUOUS_ID(exit 1): more than one changeset starts with the prefix. Give more digits;swarmops logprints whole ids.- A ref that names a changeset the store does not hold is
E_REV_NOT_FOUNDas well, with that changeset's id in the message: damage thatswarmops verifyreports.
Caveats#
- A prefix that is unique today can stop being unique when another changeset with the same leading digits is committed. Store full ids, never prefixes.
- A local reader sees a commit before its sync completes, so a power loss can take back a
changeset that
resolvealready returned; see known limitations. - Like every read,
resolvetakes no lock, so a writer never blocks it. If commits land during every one of its attempts to take a snapshot, it fails with the retryableE_BUSY(exit 4). - A
~Nof more than 1,024 steps lifts along the first-parent skip list, a derived value.swarmops derivederives it ahead of any reader; where it is missing, the first such walk derives and stores it, and a store that cannot be written resolves all the same, without storing it.
Performance#
resolve takes one snapshot of the store's metadata. In the v0.1.0 measurement a snapshot with a
changeset lookup took 50.9 µs p50 and 101.5 µs p99 on a store of 10,000 changesets, and 55.2 µs
and 107.6 µs on 100,000; the cost grows with the number of refs (1.55 ms p50 with 256 refs). See
the performance ledger.
Guides#
Return information#
result is a ResolvedRev (swarmops schema ResolvedRev prints its JSON Schema).
| Field | Type | Required | Description |
|---|---|---|---|
id | string | yes | The full id of the changeset the revision names. |
kind | RevKind | yes | What the revision is: ref when it is exactly a ref's name, changeset otherwise. |
Envelope op: resolve_rev.
Exit codes:
0: Success.2: The request or the command line is malformed.6: Something the request names does not exist.
Errors#
- E_REV_NOT_FOUND (exit 6): A revision names no changeset.
- E_INVALID_ARG (exit 2): A malformed argument or request, including a command-line usage error.
Any command that opens a store may also fail with a store error, such as E_NOT_A_REPO, E_IO or E_STORE_CORRUPT; a command line the grammar refuses is E_INVALID_ARG (exit 2).