main
ply4 git calls305 ms42 KiB2 cachedprotocol v2
68 lines3.3 KiBRaw
1// Cherry-pick and revert.
2//
3// ply returns `{outcome:'empty'}` when the transplanted tree equals the target tree and the rename guard stands
4// down: both sides added and deleted exactly the same paths (#103). A target that also has its own adds or deletes
5// is `merge_conflict` (HTTP 409). ply-web used to report that wider case as empty, because it compared post-images
6// and ignored the extra paths. `allowEmpty` is ply's `empty: 'keep'` (`kept_empty`, an applied commit on the same
7// tree). `empty: 'stop'` reports empty and writes nothing.
8import { cherryPick, plyError, revertCommit } from 'ply'
9import { ok, type Result } from '../http/machine.ts'
10import { type PlyError } from '../ply-result.ts'
11import { type CallOpts } from './call.ts'
12import { type Stamp } from './identity.ts'
13import { firstPresent, writeResult } from './result.ts'
15const OUTCOME_EMPTY = 'empty'
16const OUTCOME_OK = 'ok'
17const OUTCOME_KEPT = 'kept_empty'
19export type PlyPickResult = {
20 readonly outcome: string
21 readonly ref: string
22 readonly oid: string
23 readonly [field: string]: unknown
26export type MappedPick =
27 | { readonly kind: 'empty'; readonly ref: string; readonly oid: string }
28 | { readonly kind: 'applied'; readonly name: 'cherry_pick' | 'revert'; readonly ref: string; readonly oid: string; readonly oldOid: string | null; readonly tree: string | null; readonly pushBytes: number }
30/**
31 * ply's pick result. `empty`, `ok`, and `kept_empty` are the whole `PickOutcome` union. Any other string is an
32 * internal error (HTTP 500), not a guessed success. `merge_conflict` is not a result: ply returns it as an Err, and the status
33 * table maps that code to 409.
34 */
35export function mapPickOutcome(result: PlyPickResult, revert: boolean): MappedPick {
36 if (result.outcome === OUTCOME_EMPTY) return { kind: 'empty', ref: result.ref, oid: result.oid }
37 if (result.outcome === OUTCOME_OK || result.outcome === OUTCOME_KEPT) {
38 return {
39 kind: 'applied',
40 name: revert ? 'revert' : 'cherry_pick',
41 ref: result.ref,
42 oid: result.oid,
43 oldOid: firstPresent(result, ['onto'], null) as string | null,
44 tree: firstPresent(result, ['tree'], null) as string | null,
45 pushBytes: firstPresent(result, ['pushBytes'], 0) as number,
46 }
47 }
48 throw plyError('internal', `unexpected ${revert ? 'revert' : 'cherry-pick'} outcome ${result.outcome}`)
51function emptyResult(ref: string, oid: string): Record<string, unknown> {
52 return writeResult('empty', ref, oid, oid, {})
55export async function pick(remote: string, opts: CallOpts, spec: { ref: string; commit: string; committer: Stamp; message: string | null; allowEmpty: boolean; revert: boolean }): Promise<Result<Record<string, unknown>, PlyError>> {
56 const run = spec.revert ? revertCommit : cherryPick
57 const picked = await run(remote, {
58 ref: spec.ref,
59 commit: spec.commit,
60 committer: { name: spec.committer.name, email: spec.committer.email, tz: spec.committer.tz, time: spec.committer.time },
61 message: spec.message,
62 empty: spec.allowEmpty ? 'keep' : 'stop',
63 }, opts)
64 if (!picked.ok) return picked
65 const mapped = mapPickOutcome(picked.value as PlyPickResult, spec.revert)
66 if (mapped.kind === 'empty') return ok(emptyResult(mapped.ref, mapped.oid))
67 return ok(writeResult(mapped.name, mapped.ref, mapped.oid, mapped.oldOid, { tree: mapped.tree, pushBytes: mapped.pushBytes }))
Diagnostics4 git calls · 305 ms
CallStatusSizeTime0305 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=41349
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=41349
git.pkt.payload.max=41254
git.sideband.band1.bytes=41253
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=61
git.pack.bytes=41253
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c
git.pack.full=61
Open pack map
fetch2001.3 KiB299 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=299
git.response.bytes=1374
git.response.cache=MISS
git.response.duration_ms=299
git.fetch.wants=b163302fd65cec0b78bb1f12056fe3035f84f9ae
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1374
git.pkt.payload.max=1353
git.sideband.band1.bytes=1352
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
Ref
refs/heads/main
Commit
526b305930b8ef382f2d7a1f9c0238730a585921
cf-ray
a5e2b49e5874cf33
Request
fc8fa7c5…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format