MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / parseInfoRefs

Function parseInfoRefs

packages/plugins/apps/src/git-client/pktline.ts:69–110  ·  view source on GitHub ↗
(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

67
68// Parse the response of GET /info/refs?service=git-upload-pack (protocol v1).
69export function parseInfoRefs(bytes: Uint8Array): RefAdvertisement {
70 const { tokens } = parsePktLines(bytes, { requireComplete: true });
71 const refs = new Map<string, string>();
72 let capabilities: string[] = [];
73 let headTarget: string | undefined;
74 let sawService = false;
75 let first = true;
76
77 for (const t of tokens) {
78 if (t.kind !== "line" || !t.data) continue;
79 let line = td.decode(t.data);
80 if (line.endsWith("\n")) line = line.slice(0, -1);
81 if (line.startsWith("# service=")) {
82 sawService = true;
83 continue;
84 }
85 // first ref line carries \0-separated capabilities
86 if (first) {
87 const nul = line.indexOf("\0");
88 if (nul >= 0) {
89 capabilities = line
90 .slice(nul + 1)
91 .split(" ")
92 .filter(Boolean);
93 line = line.slice(0, nul);
94 }
95 first = false;
96 }
97 const sp = line.indexOf(" ");
98 if (sp < 0) continue;
99 const sha = line.slice(0, sp);
100 const name = line.slice(sp + 1);
101 if (/^[0-9a-f]{40,64}$/.test(sha)) refs.set(name, sha);
102 }
103
104 // symref HEAD from capabilities: symref=HEAD:refs/heads/main
105 for (const cap of capabilities) {
106 if (cap.startsWith("symref=HEAD:")) headTarget = cap.slice("symref=HEAD:".length);
107 }
108
109 return { refs, headTarget, capabilities, protocolVersion: sawService ? 1 : 1 };
110}
111
112// Resolve which sha a caller wants given a ref advertisement + optional ref name.
113export function resolveWant(

Callers 2

app-source.test.tsFile · 0.90
checkRefsFunction · 0.90

Calls 2

parsePktLinesFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected