@yaks/git 0.0.0-stage → 0.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +754 -2
- package/_dist/address.d.ts +6 -0
- package/_dist/address.d.ts.map +1 -0
- package/_dist/checkout_vocab.d.ts +3 -0
- package/_dist/checkout_vocab.d.ts.map +1 -0
- package/_dist/cites.d.ts +48 -0
- package/_dist/cites.d.ts.map +1 -0
- package/_dist/commit.d.ts +36 -0
- package/_dist/commit.d.ts.map +1 -0
- package/_dist/comp.d.ts +29 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/door.d.ts +29 -0
- package/_dist/door.d.ts.map +1 -0
- package/_dist/format.d.ts +2 -0
- package/_dist/format.d.ts.map +1 -0
- package/_dist/hold.d.ts +6 -0
- package/_dist/hold.d.ts.map +1 -0
- package/_dist/host.d.ts +126 -0
- package/_dist/host.d.ts.map +1 -0
- package/_dist/http.d.ts +33 -0
- package/_dist/http.d.ts.map +1 -0
- package/_dist/import.d.ts +13 -0
- package/_dist/import.d.ts.map +1 -0
- package/_dist/index.d.ts +80 -0
- package/_dist/index.d.ts.map +1 -0
- package/_dist/land.d.ts +77 -0
- package/_dist/land.d.ts.map +1 -0
- package/_dist/mod.d.ts +73 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/objects.d.ts +40 -0
- package/_dist/objects.d.ts.map +1 -0
- package/_dist/oid.d.ts +24 -0
- package/_dist/oid.d.ts.map +1 -0
- package/_dist/pack-store.d.ts +9 -0
- package/_dist/pack-store.d.ts.map +1 -0
- package/_dist/pack.d.ts +26 -0
- package/_dist/pack.d.ts.map +1 -0
- package/_dist/pkt.d.ts +14 -0
- package/_dist/pkt.d.ts.map +1 -0
- package/_dist/placement.d.ts +4 -0
- package/_dist/placement.d.ts.map +1 -0
- package/_dist/plugin.d.ts +43 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/project.d.ts +20 -0
- package/_dist/project.d.ts.map +1 -0
- package/_dist/push.d.ts +42 -0
- package/_dist/push.d.ts.map +1 -0
- package/_dist/refs.d.ts +81 -0
- package/_dist/refs.d.ts.map +1 -0
- package/_dist/rewrite.d.ts +35 -0
- package/_dist/rewrite.d.ts.map +1 -0
- package/_dist/service.d.ts +35 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/sha1.d.ts +11 -0
- package/_dist/sha1.d.ts.map +1 -0
- package/_dist/source.d.ts +12 -0
- package/_dist/source.d.ts.map +1 -0
- package/_dist/tools.d.ts +11 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/tree.d.ts +28 -0
- package/_dist/tree.d.ts.map +1 -0
- package/_dist/unpack.d.ts +5 -0
- package/_dist/unpack.d.ts.map +1 -0
- package/_dist/vocab.d.ts +8 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/workspace.d.ts +17 -0
- package/_dist/workspace.d.ts.map +1 -0
- package/address.js +9 -0
- package/address.js.map +1 -0
- package/address.ts +15 -0
- package/cache.js +9 -0
- package/cache.js.map +1 -0
- package/cache.ts +6 -0
- package/checkout.js +18 -0
- package/checkout.js.map +1 -0
- package/checkout.ts +24 -0
- package/checkout_vocab.js +14 -0
- package/checkout_vocab.js.map +1 -0
- package/checkout_vocab.ts +11 -0
- package/cites.js +189 -0
- package/cites.js.map +1 -0
- package/cites.ts +206 -0
- package/commit.js +128 -0
- package/commit.js.map +1 -0
- package/commit.ts +183 -0
- package/comp.js +94 -0
- package/comp.js.map +1 -0
- package/comp.ts +111 -0
- package/deno.json +1 -0
- package/door.js +88 -0
- package/door.js.map +1 -0
- package/door.ts +142 -0
- package/format.js +43 -0
- package/format.js.map +1 -0
- package/format.ts +49 -0
- package/hold.js +17 -0
- package/hold.js.map +1 -0
- package/hold.ts +21 -0
- package/host.js +1024 -0
- package/host.js.map +1 -0
- package/host.ts +1140 -0
- package/http.js +268 -0
- package/http.js.map +1 -0
- package/http.ts +329 -0
- package/import.js +141 -0
- package/import.js.map +1 -0
- package/import.ts +128 -0
- package/index.js +496 -0
- package/index.js.map +1 -0
- package/index.ts +634 -0
- package/land.js +788 -0
- package/land.js.map +1 -0
- package/land.ts +871 -0
- package/mod.js +73 -0
- package/mod.js.map +1 -0
- package/mod.ts +74 -0
- package/objects.js +331 -0
- package/objects.js.map +1 -0
- package/objects.ts +390 -0
- package/oid.js +50 -0
- package/oid.js.map +1 -0
- package/oid.ts +83 -0
- package/pack-index.js +103 -0
- package/pack-index.js.map +1 -0
- package/pack-index.ts +104 -0
- package/pack-store.js +216 -0
- package/pack-store.js.map +1 -0
- package/pack-store.ts +292 -0
- package/pack.js +121 -0
- package/pack.js.map +1 -0
- package/pack.ts +146 -0
- package/package.json +78 -4
- package/pkt.js +73 -0
- package/pkt.js.map +1 -0
- package/pkt.ts +93 -0
- package/placement.js +44 -0
- package/placement.js.map +1 -0
- package/placement.ts +38 -0
- package/plugin.js +66 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +88 -0
- package/process-cwd.py +57 -0
- package/project.js +142 -0
- package/project.js.map +1 -0
- package/project.ts +151 -0
- package/push.js +401 -0
- package/push.js.map +1 -0
- package/push.ts +451 -0
- package/refs.js +176 -0
- package/refs.js.map +1 -0
- package/refs.ts +285 -0
- package/rewrite.js +176 -0
- package/rewrite.js.map +1 -0
- package/rewrite.ts +173 -0
- package/service.js +104 -0
- package/service.js.map +1 -0
- package/service.ts +194 -0
- package/sha1.js +115 -0
- package/sha1.js.map +1 -0
- package/sha1.ts +146 -0
- package/source.js +100 -0
- package/source.js.map +1 -0
- package/source.ts +116 -0
- package/spare.js +108 -0
- package/spare.js.map +1 -0
- package/spare.ts +94 -0
- package/tools.js +278 -0
- package/tools.js.map +1 -0
- package/tools.ts +310 -0
- package/tree.js +105 -0
- package/tree.js.map +1 -0
- package/tree.ts +132 -0
- package/unpack.js +207 -0
- package/unpack.js.map +1 -0
- package/unpack.ts +210 -0
- package/vocab.js +20 -0
- package/vocab.js.map +1 -0
- package/vocab.json +386 -0
- package/vocab.ts +22 -0
- package/workspace.js +449 -0
- package/workspace.js.map +1 -0
- package/workspace.ts +445 -0
package/commit.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// A commit, as Git writes one down: a tree, its parents, who wrote it, who
|
|
2
|
+
// recorded it, a blank line, and the message.
|
|
3
|
+
//
|
|
4
|
+
// tree ac1c58…\n
|
|
5
|
+
// parent 2b72ae…\n
|
|
6
|
+
// author yaks <a6433884@users.yaks.app> 1757000000 +0000\n
|
|
7
|
+
// committer yaks.app <git@yaks.app> 1757000000 +0000\n
|
|
8
|
+
// \n
|
|
9
|
+
// deploy 1\n
|
|
10
|
+
//
|
|
11
|
+
// The ids are HEX here, unlike a tree's raw bytes, and they are whichever of
|
|
12
|
+
// the two ids is being written — a SHA-256 commit names its tree and parents
|
|
13
|
+
// by their `oid256`.
|
|
14
|
+
//
|
|
15
|
+
// Two small points of fidelity. The timezone offset is always `+0000`, because
|
|
16
|
+
// the time this package is given is an instant read off the graph and not a
|
|
17
|
+
// place; and the message ends in exactly one newline, which is what
|
|
18
|
+
// `git commit-tree -m` writes, so a message read back out of a Git repository
|
|
19
|
+
// round-trips to the same object id.
|
|
20
|
+
import { concat } from "./oid.js";
|
|
21
|
+
let utf8 = new TextEncoder();
|
|
22
|
+
// `<`, `>` and a newline are the format's own punctuation: Git refuses them in
|
|
23
|
+
// an identity line, so a name containing one has them stripped rather than
|
|
24
|
+
// being allowed to write a commit nobody can parse.
|
|
25
|
+
let ident = (s)=>s.replace(/[<>\n]/g, '').trim();
|
|
26
|
+
/** Whole seconds since the epoch — the clock Git records. */ export let seconds = (at)=>Math.floor(new Date(at).getTime() / 1000);
|
|
27
|
+
/** One authorship line's value: `name <email> 1757000000 +0000`. */ export let signature = (who)=>`${ident(who.name)} <${ident(who.email)}> ${seconds(who.at)} +0000`;
|
|
28
|
+
/**
|
|
29
|
+
* The tree a commit body names, or nothing if these bytes are not a commit.
|
|
30
|
+
*
|
|
31
|
+
* This is the one link in this package that no edge carries. A commit's
|
|
32
|
+
* parents are rows (./comp.ts) because history is walked constantly, but its
|
|
33
|
+
* tree is recorded only here, in the first line of the body the object id was
|
|
34
|
+
* taken over — and packing reads that body anyway on its way out.
|
|
35
|
+
*/ export let treeOf = (body)=>{
|
|
36
|
+
let [word, id] = new TextDecoder().decode(body.subarray(0, 80)).split('\n')[0].split(' ');
|
|
37
|
+
return word == 'tree' && /^[0-9a-f]+$/.test(id ?? '') ? id : undefined;
|
|
38
|
+
};
|
|
39
|
+
/** A commit object's body. */ export let commitBody = (c)=>{
|
|
40
|
+
let lines = [
|
|
41
|
+
`tree ${c.tree}\n`,
|
|
42
|
+
...(c.parents ?? []).map((p)=>`parent ${p}\n`),
|
|
43
|
+
`author ${signature(c.author)}\n`,
|
|
44
|
+
`committer ${signature(c.committer)}\n`,
|
|
45
|
+
...Object.entries(c.headers ?? {}).map(([key, value])=>{
|
|
46
|
+
if (!/^[a-z][a-z0-9-]*$/.test(key) || /[\r\n\0]/.test(value)) {
|
|
47
|
+
throw new Error('git: invalid commit header');
|
|
48
|
+
}
|
|
49
|
+
return `${key} ${value}\n`;
|
|
50
|
+
}),
|
|
51
|
+
`\n`,
|
|
52
|
+
c.message.replace(/\n*$/, '\n')
|
|
53
|
+
];
|
|
54
|
+
return concat(lines.map((l)=>utf8.encode(l)));
|
|
55
|
+
};
|
|
56
|
+
/** Read the tree, ordered parents and complete message of a pushed commit. */ export let commitParts = (bytes)=>{
|
|
57
|
+
let body = new TextDecoder().decode(bytes);
|
|
58
|
+
let end = body.indexOf('\n\n');
|
|
59
|
+
let [tree, ...lines] = body.slice(0, end).split('\n');
|
|
60
|
+
let parents = lines.filter((line)=>line.startsWith('parent ')).map((line)=>line.slice(7));
|
|
61
|
+
let sha = /^[0-9a-f]{40}$/;
|
|
62
|
+
if (end < 0 || !tree.startsWith('tree ') || ![
|
|
63
|
+
tree.slice(5),
|
|
64
|
+
...parents
|
|
65
|
+
].every((v)=>sha.test(v))) {
|
|
66
|
+
throw new Error('git: invalid commit body');
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
tree: tree.slice(5),
|
|
70
|
+
parents,
|
|
71
|
+
message: body.slice(end + 2)
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
/** Translate only the object IDs in the header. The message can contain arbitrary bytes. */ export let compatibleCommit = (bytes, named)=>{
|
|
75
|
+
let end = bytes.findIndex((byte, i)=>byte == 10 && bytes[i + 1] == 10);
|
|
76
|
+
let header = new TextDecoder().decode(bytes.subarray(0, end));
|
|
77
|
+
return concat([
|
|
78
|
+
utf8.encode(header.replace(/^(tree|parent) ([0-9a-f]{40})$/gm, (_, key, oid)=>`${key} ${named(oid)}`)),
|
|
79
|
+
bytes.subarray(end)
|
|
80
|
+
]);
|
|
81
|
+
};
|
|
82
|
+
/** Keep the author's bytes and message when projecting a commit onto an app. */ export let projectedCommit = (bytes, tree, parent, repository)=>{
|
|
83
|
+
let end = bytes.findIndex((byte, i)=>byte == 10 && bytes[i + 1] == 10);
|
|
84
|
+
let headers = new TextDecoder().decode(bytes.subarray(0, end)).split(/\n(?! )/).filter((line)=>!/^(tree|parent|gpgsig(?:-sha256)?|mergetag|yak-app) /.test(line));
|
|
85
|
+
return concat([
|
|
86
|
+
utf8.encode([
|
|
87
|
+
`tree ${tree}`,
|
|
88
|
+
...parent ? [
|
|
89
|
+
`parent ${parent}`
|
|
90
|
+
] : [],
|
|
91
|
+
`yak-app ${repository}`,
|
|
92
|
+
...headers
|
|
93
|
+
].join('\n')),
|
|
94
|
+
bytes.subarray(end)
|
|
95
|
+
]);
|
|
96
|
+
};
|
|
97
|
+
/** Change the graph links of a commit while keeping its authorship and message.
|
|
98
|
+
* A signature over the old body cannot sign the rewritten commit. */ export let rewrittenCommit = (bytes, tree, parents)=>{
|
|
99
|
+
let kept = [
|
|
100
|
+
utf8.encode([
|
|
101
|
+
`tree ${tree}\n`,
|
|
102
|
+
...parents.map((parent)=>`parent ${parent}\n`)
|
|
103
|
+
].join(''))
|
|
104
|
+
];
|
|
105
|
+
let text = new TextDecoder();
|
|
106
|
+
let start = 0;
|
|
107
|
+
for(let end = 0; end < bytes.length; end++){
|
|
108
|
+
if (bytes[end] != 10 || bytes[end + 1] == 32) continue;
|
|
109
|
+
let line = bytes.subarray(start, end + 1);
|
|
110
|
+
let name = text.decode(line.subarray(0, 20)).split(' ')[0];
|
|
111
|
+
if (![
|
|
112
|
+
'tree',
|
|
113
|
+
'parent',
|
|
114
|
+
'gpgsig',
|
|
115
|
+
'gpgsig-sha256',
|
|
116
|
+
'mergetag'
|
|
117
|
+
].includes(name)) {
|
|
118
|
+
kept.push(line);
|
|
119
|
+
}
|
|
120
|
+
start = end + 1;
|
|
121
|
+
if (bytes[start] == 10) return concat([
|
|
122
|
+
...kept,
|
|
123
|
+
bytes.subarray(start)
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
throw new Error('git: invalid commit body');
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=commit.js.map
|
package/commit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.js","sources":["./commit.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,8CAA8C;AAC9C,EAAE;AACF,mBAAmB;AACnB,qBAAqB;AACrB,6DAA6D;AAC7D,yDAAyD;AACzD,OAAO;AACP,eAAe;AACf,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,qBAAqB;AACrB,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,oEAAoE;AACpE,8EAA8E;AAC9E,qCAAqC;AAErC,SAAS,MAAM,mBAAkB;AAuBjC,IAAI,OAAO,IAAI;AAEf,+EAA+E;AAC/E,2EAA2E;AAC3E,oDAAoD;AACpD,IAAI,QAAQ,CAAC,IAAsB,EAAE,OAAO,CAAC,WAAW,IAAI,IAAI;AAEhE,2DAA2D,GAC3D,OAAO,IAAI,UAAU,CAAC,KACpB,KAAK,KAAK,CAAC,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a blank line, and the message.
|
|
3
|
+
//
|
|
4
|
+
// tree ac1c58…\n
|
|
5
|
+
// parent 2b72ae…\n
|
|
6
|
+
// author yaks <a6433884@users.yaks.app> 1757000000 +0000\n
|
|
7
|
+
// committer yaks.app <git@yaks.app> 1757000000 +0000\n
|
|
8
|
+
// \n
|
|
9
|
+
// deploy 1\n
|
|
10
|
+
//
|
|
11
|
+
// The ids are HEX here, unlike a tree's raw bytes, and they are whichever of
|
|
12
|
+
// the two ids is being written — a SHA-256 commit names its tree and parents
|
|
13
|
+
// by their `oid256`.
|
|
14
|
+
//
|
|
15
|
+
// Two small points of fidelity. The timezone offset is always `+0000`, because
|
|
16
|
+
// the time this package is given is an instant read off the graph and not a
|
|
17
|
+
// place; and the message ends in exactly one newline, which is what
|
|
18
|
+
// `git commit-tree -m` writes, so a message read back out of a Git repository
|
|
19
|
+
// round-trips to the same object id.
|
|
20
|
+
|
|
21
|
+
import { concat } from './oid.js'
|
|
22
|
+
|
|
23
|
+
/** One side of a commit's authorship: a name, an email address, and a time.
|
|
24
|
+
* `at` is anything the `Date` constructor accepts — an ISO string read off the
|
|
25
|
+
* graph, or milliseconds since the epoch. */
|
|
26
|
+
export type Who = { name: string; email: string; at: string | number | Date }
|
|
27
|
+
|
|
28
|
+
/** The contents of a commit, with every id under one hash algorithm. */
|
|
29
|
+
export type Commit = {
|
|
30
|
+
/** the root tree's id */
|
|
31
|
+
tree: string
|
|
32
|
+
/** the commits this one follows, in order */
|
|
33
|
+
parents?: string[]
|
|
34
|
+
/** who wrote the change */
|
|
35
|
+
author: Who
|
|
36
|
+
/** who recorded it — for yaks.app, the platform itself */
|
|
37
|
+
committer: Who
|
|
38
|
+
/** the message, newline-terminated on the way out */
|
|
39
|
+
message: string
|
|
40
|
+
/** application metadata, stored in the commit header */
|
|
41
|
+
headers?: Record<string, string>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let utf8 = new TextEncoder()
|
|
45
|
+
|
|
46
|
+
// `<`, `>` and a newline are the format's own punctuation: Git refuses them in
|
|
47
|
+
// an identity line, so a name containing one has them stripped rather than
|
|
48
|
+
// being allowed to write a commit nobody can parse.
|
|
49
|
+
let ident = (s: string): string => s.replace(/[<>\n]/g, '').trim()
|
|
50
|
+
|
|
51
|
+
/** Whole seconds since the epoch — the clock Git records. */
|
|
52
|
+
export let seconds = (at: Who['at']): number =>
|
|
53
|
+
Math.floor(new Date(at).getTime() / 1000)
|
|
54
|
+
|
|
55
|
+
/** One authorship line's value: `name <email> 1757000000 +0000`. */
|
|
56
|
+
export let signature = (who: Who): string =>
|
|
57
|
+
`${ident(who.name)} <${ident(who.email)}> ${seconds(who.at)} +0000`
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The tree a commit body names, or nothing if these bytes are not a commit.
|
|
61
|
+
*
|
|
62
|
+
* This is the one link in this package that no edge carries. A commit's
|
|
63
|
+
* parents are rows (./comp.ts) because history is walked constantly, but its
|
|
64
|
+
* tree is recorded only here, in the first line of the body the object id was
|
|
65
|
+
* taken over — and packing reads that body anyway on its way out.
|
|
66
|
+
*/
|
|
67
|
+
export let treeOf = (body: Uint8Array): string | undefined => {
|
|
68
|
+
let [word, id] = new TextDecoder().decode(body.subarray(0, 80))
|
|
69
|
+
.split('\n')[0]
|
|
70
|
+
.split(' ')
|
|
71
|
+
return word == 'tree' && /^[0-9a-f]+$/.test(id ?? '') ? id : undefined
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A commit object's body. */
|
|
75
|
+
export let commitBody = (c: Commit): Uint8Array<ArrayBuffer> => {
|
|
76
|
+
let lines = [
|
|
77
|
+
`tree ${c.tree}\n`,
|
|
78
|
+
...(c.parents ?? []).map((p) => `parent ${p}\n`),
|
|
79
|
+
`author ${signature(c.author)}\n`,
|
|
80
|
+
`committer ${signature(c.committer)}\n`,
|
|
81
|
+
...Object.entries(c.headers ?? {}).map(([key, value]) => {
|
|
82
|
+
if (!/^[a-z][a-z0-9-]*$/.test(key) || /[\r\n\0]/.test(value)) {
|
|
83
|
+
throw new Error('git: invalid commit header')
|
|
84
|
+
}
|
|
85
|
+
return `${key} ${value}\n`
|
|
86
|
+
}),
|
|
87
|
+
`\n`,
|
|
88
|
+
c.message.replace(/\n*$/, '\n'),
|
|
89
|
+
]
|
|
90
|
+
return concat(lines.map((l) => utf8.encode(l)))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Read the tree, ordered parents and complete message of a pushed commit. */
|
|
94
|
+
export let commitParts = (
|
|
95
|
+
bytes: Uint8Array,
|
|
96
|
+
): { tree: string; parents: string[]; message: string } => {
|
|
97
|
+
let body = new TextDecoder().decode(bytes)
|
|
98
|
+
let end = body.indexOf('\n\n')
|
|
99
|
+
let [tree, ...lines] = body.slice(0, end).split('\n')
|
|
100
|
+
let parents = lines.filter((line) => line.startsWith('parent ')).map((line) =>
|
|
101
|
+
line.slice(7)
|
|
102
|
+
)
|
|
103
|
+
let sha = /^[0-9a-f]{40}$/
|
|
104
|
+
if (
|
|
105
|
+
end < 0 || !tree.startsWith('tree ') ||
|
|
106
|
+
![tree.slice(5), ...parents].every((v) => sha.test(v))
|
|
107
|
+
) {
|
|
108
|
+
throw new Error('git: invalid commit body')
|
|
109
|
+
}
|
|
110
|
+
return { tree: tree.slice(5), parents, message: body.slice(end + 2) }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Translate only the object IDs in the header. The message can contain arbitrary bytes. */
|
|
114
|
+
export let compatibleCommit = (
|
|
115
|
+
bytes: Uint8Array,
|
|
116
|
+
named: (id: string) => string,
|
|
117
|
+
): Uint8Array<ArrayBuffer> => {
|
|
118
|
+
let end = bytes.findIndex((byte, i) => byte == 10 && bytes[i + 1] == 10)
|
|
119
|
+
let header = new TextDecoder().decode(bytes.subarray(0, end))
|
|
120
|
+
return concat([
|
|
121
|
+
utf8.encode(
|
|
122
|
+
header.replace(
|
|
123
|
+
/^(tree|parent) ([0-9a-f]{40})$/gm,
|
|
124
|
+
(_, key, oid) => `${key} ${named(oid)}`,
|
|
125
|
+
),
|
|
126
|
+
),
|
|
127
|
+
bytes.subarray(end),
|
|
128
|
+
])
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Keep the author's bytes and message when projecting a commit onto an app. */
|
|
132
|
+
export let projectedCommit = (
|
|
133
|
+
bytes: Uint8Array,
|
|
134
|
+
tree: string,
|
|
135
|
+
parent: string | null,
|
|
136
|
+
repository: string,
|
|
137
|
+
): Uint8Array<ArrayBuffer> => {
|
|
138
|
+
let end = bytes.findIndex((byte, i) => byte == 10 && bytes[i + 1] == 10)
|
|
139
|
+
let headers = new TextDecoder().decode(bytes.subarray(0, end))
|
|
140
|
+
.split(/\n(?! )/)
|
|
141
|
+
.filter((line) =>
|
|
142
|
+
!/^(tree|parent|gpgsig(?:-sha256)?|mergetag|yak-app) /.test(line)
|
|
143
|
+
)
|
|
144
|
+
return concat([
|
|
145
|
+
utf8.encode(
|
|
146
|
+
[
|
|
147
|
+
`tree ${tree}`,
|
|
148
|
+
...parent ? [`parent ${parent}`] : [],
|
|
149
|
+
`yak-app ${repository}`,
|
|
150
|
+
...headers,
|
|
151
|
+
].join('\n'),
|
|
152
|
+
),
|
|
153
|
+
bytes.subarray(end),
|
|
154
|
+
])
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Change the graph links of a commit while keeping its authorship and message.
|
|
158
|
+
* A signature over the old body cannot sign the rewritten commit. */
|
|
159
|
+
export let rewrittenCommit = (
|
|
160
|
+
bytes: Uint8Array,
|
|
161
|
+
tree: string,
|
|
162
|
+
parents: string[],
|
|
163
|
+
): Uint8Array<ArrayBuffer> => {
|
|
164
|
+
let kept: Uint8Array[] = [utf8.encode([
|
|
165
|
+
`tree ${tree}\n`,
|
|
166
|
+
...parents.map((parent) => `parent ${parent}\n`),
|
|
167
|
+
].join(''))]
|
|
168
|
+
let text = new TextDecoder()
|
|
169
|
+
let start = 0
|
|
170
|
+
for (let end = 0; end < bytes.length; end++) {
|
|
171
|
+
if (bytes[end] != 10 || bytes[end + 1] == 32) continue
|
|
172
|
+
let line = bytes.subarray(start, end + 1)
|
|
173
|
+
let name = text.decode(line.subarray(0, 20)).split(' ')[0]
|
|
174
|
+
if (
|
|
175
|
+
!['tree', 'parent', 'gpgsig', 'gpgsig-sha256', 'mergetag'].includes(name)
|
|
176
|
+
) {
|
|
177
|
+
kept.push(line)
|
|
178
|
+
}
|
|
179
|
+
start = end + 1
|
|
180
|
+
if (bytes[start] == 10) return concat([...kept, bytes.subarray(start)])
|
|
181
|
+
}
|
|
182
|
+
throw new Error('git: invalid commit body')
|
|
183
|
+
}
|
package/comp.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// The components this package ships, as a vocabulary document to load beside
|
|
2
|
+
// your own.
|
|
3
|
+
//
|
|
4
|
+
// gitobj{type, size} one Git object; its entity id is its SHA-1 object id
|
|
5
|
+
// blob{sha} where its bytes are, in the @yaks/blob store
|
|
6
|
+
// tree_entry{name, mode} an @yaks/edge relation: a tree holds a child
|
|
7
|
+
// parent an @yaks/edge relation: a commit follows a commit
|
|
8
|
+
// compat an @yaks/key kind: the same object's SHA-256 id
|
|
9
|
+
// ref{app, name, commit} where one branch of one repository points
|
|
10
|
+
// cites @yaks/kernel's relation: a citation of a place
|
|
11
|
+
// revision{commit} the commit a citation was last checked against
|
|
12
|
+
//
|
|
13
|
+
// The document itself is ./vocab.json — plain JSON Schema, readable by
|
|
14
|
+
// anything that reads JSON. This file re-exports it under the names callers
|
|
15
|
+
// use, and keeps the explanation of why it is shaped this way.
|
|
16
|
+
//
|
|
17
|
+
// The entity ID is the object ID. `gitobj` declares no `sha` property, because
|
|
18
|
+
// the entity's own id is that value: an object written twice is one row
|
|
19
|
+
// without anyone declaring a uniqueness constraint, and a `want` line arriving
|
|
20
|
+
// in a fetch request is a lookup by id rather than a query. It is the same
|
|
21
|
+
// trick @yaks/edge and @yaks/key play with a derived id — here the derivation
|
|
22
|
+
// is Git's.
|
|
23
|
+
//
|
|
24
|
+
// Tree children are read from the immutable body, in both Git object formats.
|
|
25
|
+
// The framed SHA-256 tree is addressed by its Git object id; `blob{sha}`
|
|
26
|
+
// addresses the SHA-1-format body. `tree_entry` remains declared for links, which
|
|
27
|
+
// need no rewrite. Parent edges still join commits for history traversal.
|
|
28
|
+
//
|
|
29
|
+
// A `ref` IS A row, one per repository and branch name ({@link refEid}), and
|
|
30
|
+
// the only component here that is not about an object. Objects form one global
|
|
31
|
+
// set — an object is named by the digest of its own bytes, so the same file in
|
|
32
|
+
// two repositories is one row — while a branch belongs to exactly one
|
|
33
|
+
// repository. That is why {@link refDoc} is the same declaration published on
|
|
34
|
+
// its own: a server that keeps its refs in the graph where it decides access,
|
|
35
|
+
// and its objects in a store of their own, loads one document in each.
|
|
36
|
+
//
|
|
37
|
+
// A citation is an edge, and each fact about it is a component of its own on
|
|
38
|
+
// that edge: @yaks/kernel's `cites` says the link is a citation, and
|
|
39
|
+
// `revision{commit}` says which commit it was last checked against. The place
|
|
40
|
+
// it names is what it points at: a @yaks/file `file{path, root}` whose root is
|
|
41
|
+
// the repository, an entity wearing @yaks/file's `lines{file, start, end}` for
|
|
42
|
+
// some lines of one (with what was quoted as its `content.body`), or a
|
|
43
|
+
// @yaks/code `symbol` for a definition. So a citation is an ordinary link
|
|
44
|
+
// between two entities rather than a path property somewhere. Whether it is
|
|
45
|
+
// still current is derived from Git for a file of a repository, and from the
|
|
46
|
+
// kernel's content hash for any other entity (./cites.ts). A verified citation
|
|
47
|
+
// also carries the kernel's `verified{at, by, via}` mark, written by the act
|
|
48
|
+
// of checking.
|
|
49
|
+
//
|
|
50
|
+
// `compat` Is A key, not a property on `gitobj`, so the reverse lookup — a
|
|
51
|
+
// SHA-256 `want` arriving at a SHA-1 graph — is a lookup by derived id rather
|
|
52
|
+
// than an index someone has to remember to declare. Same mechanism as
|
|
53
|
+
// @yaks/alias's names. It is named `compat`, Git's own term for the object id
|
|
54
|
+
// under the other hash function, rather than `oid256`, because a component
|
|
55
|
+
// name in the query grammar must be letters (@yaks/query `SEG`): a component
|
|
56
|
+
// nobody can name in a query is a component nobody can read back.
|
|
57
|
+
import { derivedEid } from "@yaks/graph/identity";
|
|
58
|
+
import { pick } from "@yaks/vocab/runtime";
|
|
59
|
+
import doc from './vocab.json' with {
|
|
60
|
+
type: 'json'
|
|
61
|
+
};
|
|
62
|
+
/** The component naming a Git object: what it is, and how long its body is. */ export let GITOBJ = 'gitobj';
|
|
63
|
+
/** The component naming where an object's bytes are. */ export let BLOB = 'blob';
|
|
64
|
+
/** The relation tag on a tree's link to a child. Named with Git's own two
|
|
65
|
+
* words for it, because `entry` on its own is a transcript line in
|
|
66
|
+
* @yaks/session. */ export let TREE_ENTRY = 'tree_entry';
|
|
67
|
+
/** The relation tag on a commit's link to the commit it follows. */ export let PARENT = 'parent';
|
|
68
|
+
/** The key kind an object's SHA-256 object id is stored under. Git calls an
|
|
69
|
+
* object's id under the other hash function its compat oid. */ export let COMPAT = 'compat';
|
|
70
|
+
/** The component recording where one branch of one repository points. */ export let REF = 'ref';
|
|
71
|
+
/**
|
|
72
|
+
* The entity id of a ref, derived from the string `ref|<app>|<name>`.
|
|
73
|
+
*
|
|
74
|
+
* Derived rather than freshly generated, so writing where a branch points is
|
|
75
|
+
* idempotent from anywhere: the hook that saw the release and the sweep that
|
|
76
|
+
* missed it update the same row.
|
|
77
|
+
*/ export let refEid = (app, name)=>derivedEid(`${REF}|${app}|${name}`);
|
|
78
|
+
// The citation components are named in ./cites.ts, beside the code that reads
|
|
79
|
+
// them: `file` as a component and `FILE` as a tree entry's mode (./tree.ts)
|
|
80
|
+
// are two different things, and this module's names are re-exported from
|
|
81
|
+
// ./mod.ts where they would collide.
|
|
82
|
+
/**
|
|
83
|
+
* This package's components as a vocabulary document, to load beside
|
|
84
|
+
* @yaks/edge's and @yaks/key's:
|
|
85
|
+
* `loadVocab([edgeDoc, keyDoc, gitDoc], [edgeKeywords, keyKeywords])`.
|
|
86
|
+
*/ export let gitDoc = doc;
|
|
87
|
+
/**
|
|
88
|
+
* The `ref` component alone, for the graph that keeps a repository's branches
|
|
89
|
+
* when that is not the graph its objects are in. It is the same declaration,
|
|
90
|
+
* so the name means one thing in both.
|
|
91
|
+
*/ export let refDoc = pick(gitDoc, [
|
|
92
|
+
'ref'
|
|
93
|
+
]);
|
|
94
|
+
//# sourceMappingURL=comp.js.map
|
package/comp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comp.js","sources":["./comp.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,YAAY;AACZ,EAAE;AACF,iFAAiF;AACjF,yEAAyE;AACzE,yEAAyE;AACzE,8EAA8E;AAC9E,4EAA4E;AAC5E,sEAAsE;AACtE,2EAA2E;AAC3E,2EAA2E;AAC3E,EAAE;AACF,uEAAuE;AACvE,4EAA4E;AAC5E,+DAA+D;AAC/D,EAAE;AACF,+EAA+E;AAC/E,wEAAwE;AACxE,+EAA+E;AAC/E,2EAA2E;AAC3E,8EAA8E;AAC9E,YAAY;AACZ,EAAE;AACF,8EAA8E;AAC9E,yEAAyE;AACzE,kFAAkF;AAClF,0EAA0E;AAC1E,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,+EAA+E;AAC/E,sEAAsE;AACtE,8EAA8E;AAC9E,8EAA8E;AAC9E,uEAAuE;AACvE,EAAE;AACF,6EAA6E;AAC7E,qEAAqE;AACrE,8EAA8E;AAC9E,+EAA+E;AAC/E,+EAA+E;AAC/E,uEAAuE;AACvE,0EAA0E;AAC1E,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,eAAe;AACf,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,sEAAsE;AACtE,8EAA8E;AAC9E,2EAA2E;AAC3E,6EAA6E;AAC7E,kEAAkE;AAGlE,SAAS,UAAU,oCAAyC;AAC5D,SAAS,IAAI,mCAAuD;AACpE,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AAEpD,6EAA6E,GAC7E,OAAO,IAAI,SAAS,SAAQ;AAE5B,sDAAsD,GACtD,OAAO,IAAI,OAAO,OAAM;AAExB;;kBAEkB,GAClB,OAAO,IAAI,aAAa,aAAY;AAEpC,kEAAkE,GAClE,OAAO,IAAI,SAAS,SAAQ;AAE5B;6DAC6D,GAC7D,OAAO,IAAI,SAAS,SAAQ;AAE5B,uEAAuE,GACvE,OAAO,IAAI,MAAM,MAAK;AAEtB;;;;;;CAMC,GACD,OAAO,IAAI,SAAS,CAAC,KAAU,OAC7B,WAAW,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,EAAC;AAErC,8EAA8E;AAC9E,4EAA4E;AAC5E,yEAAyE;AACzE,qCAAqC;AAErC;;;;CAIC,GACD,OAAO,IAAI,SAAmB,IAAG;AAEjC;;;;CAIC,GACD,OAAO,IAAI,SAAmB,KAAK,QAAQ;EAAC;CAAM,EAAC"}
|
package/comp.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// The components this package ships, as a vocabulary document to load beside
|
|
2
|
+
// your own.
|
|
3
|
+
//
|
|
4
|
+
// gitobj{type, size} one Git object; its entity id is its SHA-1 object id
|
|
5
|
+
// blob{sha} where its bytes are, in the @yaks/blob store
|
|
6
|
+
// tree_entry{name, mode} an @yaks/edge relation: a tree holds a child
|
|
7
|
+
// parent an @yaks/edge relation: a commit follows a commit
|
|
8
|
+
// compat an @yaks/key kind: the same object's SHA-256 id
|
|
9
|
+
// ref{app, name, commit} where one branch of one repository points
|
|
10
|
+
// cites @yaks/kernel's relation: a citation of a place
|
|
11
|
+
// revision{commit} the commit a citation was last checked against
|
|
12
|
+
//
|
|
13
|
+
// The document itself is ./vocab.json — plain JSON Schema, readable by
|
|
14
|
+
// anything that reads JSON. This file re-exports it under the names callers
|
|
15
|
+
// use, and keeps the explanation of why it is shaped this way.
|
|
16
|
+
//
|
|
17
|
+
// The entity ID is the object ID. `gitobj` declares no `sha` property, because
|
|
18
|
+
// the entity's own id is that value: an object written twice is one row
|
|
19
|
+
// without anyone declaring a uniqueness constraint, and a `want` line arriving
|
|
20
|
+
// in a fetch request is a lookup by id rather than a query. It is the same
|
|
21
|
+
// trick @yaks/edge and @yaks/key play with a derived id — here the derivation
|
|
22
|
+
// is Git's.
|
|
23
|
+
//
|
|
24
|
+
// Tree children are read from the immutable body, in both Git object formats.
|
|
25
|
+
// The framed SHA-256 tree is addressed by its Git object id; `blob{sha}`
|
|
26
|
+
// addresses the SHA-1-format body. `tree_entry` remains declared for links, which
|
|
27
|
+
// need no rewrite. Parent edges still join commits for history traversal.
|
|
28
|
+
//
|
|
29
|
+
// A `ref` IS A row, one per repository and branch name ({@link refEid}), and
|
|
30
|
+
// the only component here that is not about an object. Objects form one global
|
|
31
|
+
// set — an object is named by the digest of its own bytes, so the same file in
|
|
32
|
+
// two repositories is one row — while a branch belongs to exactly one
|
|
33
|
+
// repository. That is why {@link refDoc} is the same declaration published on
|
|
34
|
+
// its own: a server that keeps its refs in the graph where it decides access,
|
|
35
|
+
// and its objects in a store of their own, loads one document in each.
|
|
36
|
+
//
|
|
37
|
+
// A citation is an edge, and each fact about it is a component of its own on
|
|
38
|
+
// that edge: @yaks/kernel's `cites` says the link is a citation, and
|
|
39
|
+
// `revision{commit}` says which commit it was last checked against. The place
|
|
40
|
+
// it names is what it points at: a @yaks/file `file{path, root}` whose root is
|
|
41
|
+
// the repository, an entity wearing @yaks/file's `lines{file, start, end}` for
|
|
42
|
+
// some lines of one (with what was quoted as its `content.body`), or a
|
|
43
|
+
// @yaks/code `symbol` for a definition. So a citation is an ordinary link
|
|
44
|
+
// between two entities rather than a path property somewhere. Whether it is
|
|
45
|
+
// still current is derived from Git for a file of a repository, and from the
|
|
46
|
+
// kernel's content hash for any other entity (./cites.ts). A verified citation
|
|
47
|
+
// also carries the kernel's `verified{at, by, via}` mark, written by the act
|
|
48
|
+
// of checking.
|
|
49
|
+
//
|
|
50
|
+
// `compat` Is A key, not a property on `gitobj`, so the reverse lookup — a
|
|
51
|
+
// SHA-256 `want` arriving at a SHA-1 graph — is a lookup by derived id rather
|
|
52
|
+
// than an index someone has to remember to declare. Same mechanism as
|
|
53
|
+
// @yaks/alias's names. It is named `compat`, Git's own term for the object id
|
|
54
|
+
// under the other hash function, rather than `oid256`, because a component
|
|
55
|
+
// name in the query grammar must be letters (@yaks/query `SEG`): a component
|
|
56
|
+
// nobody can name in a query is a component nobody can read back.
|
|
57
|
+
|
|
58
|
+
import type { Eid } from 'jsr:@yaks/graph@0.2.36'
|
|
59
|
+
import { derivedEid } from '@yaks/graph/identity'
|
|
60
|
+
import { pick, type VocabDoc } from '@yaks/vocab/runtime'
|
|
61
|
+
import doc from './vocab.json' with { type: 'json' }
|
|
62
|
+
|
|
63
|
+
/** The component naming a Git object: what it is, and how long its body is. */
|
|
64
|
+
export let GITOBJ = 'gitobj'
|
|
65
|
+
|
|
66
|
+
/** The component naming where an object's bytes are. */
|
|
67
|
+
export let BLOB = 'blob'
|
|
68
|
+
|
|
69
|
+
/** The relation tag on a tree's link to a child. Named with Git's own two
|
|
70
|
+
* words for it, because `entry` on its own is a transcript line in
|
|
71
|
+
* @yaks/session. */
|
|
72
|
+
export let TREE_ENTRY = 'tree_entry'
|
|
73
|
+
|
|
74
|
+
/** The relation tag on a commit's link to the commit it follows. */
|
|
75
|
+
export let PARENT = 'parent'
|
|
76
|
+
|
|
77
|
+
/** The key kind an object's SHA-256 object id is stored under. Git calls an
|
|
78
|
+
* object's id under the other hash function its compat oid. */
|
|
79
|
+
export let COMPAT = 'compat'
|
|
80
|
+
|
|
81
|
+
/** The component recording where one branch of one repository points. */
|
|
82
|
+
export let REF = 'ref'
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The entity id of a ref, derived from the string `ref|<app>|<name>`.
|
|
86
|
+
*
|
|
87
|
+
* Derived rather than freshly generated, so writing where a branch points is
|
|
88
|
+
* idempotent from anywhere: the hook that saw the release and the sweep that
|
|
89
|
+
* missed it update the same row.
|
|
90
|
+
*/
|
|
91
|
+
export let refEid = (app: Eid, name: string): Eid =>
|
|
92
|
+
derivedEid(`${REF}|${app}|${name}`)
|
|
93
|
+
|
|
94
|
+
// The citation components are named in ./cites.ts, beside the code that reads
|
|
95
|
+
// them: `file` as a component and `FILE` as a tree entry's mode (./tree.ts)
|
|
96
|
+
// are two different things, and this module's names are re-exported from
|
|
97
|
+
// ./mod.ts where they would collide.
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* This package's components as a vocabulary document, to load beside
|
|
101
|
+
* @yaks/edge's and @yaks/key's:
|
|
102
|
+
* `loadVocab([edgeDoc, keyDoc, gitDoc], [edgeKeywords, keyKeywords])`.
|
|
103
|
+
*/
|
|
104
|
+
export let gitDoc: VocabDoc = doc
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The `ref` component alone, for the graph that keeps a repository's branches
|
|
108
|
+
* when that is not the graph its objects are in. It is the same declaration,
|
|
109
|
+
* so the name means one thing in both.
|
|
110
|
+
*/
|
|
111
|
+
export let refDoc: VocabDoc = pick(gitDoc, ['ref'])
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"publish":{"exclude":["**/*_test.ts","./testing.ts"]},"name":"@yaks/git","version":"0.2.36","license":"Apache-2.0","description":"Builds Git trees and commits from a file manifest, stores the objects as graph entities, and serves clones and pushes over Git smart HTTP.","exports":{".":"./mod.ts","./cites":"./cites.ts","./door":"./door.ts","./address":"./address.ts","./push":"./push.ts","./host":"./host.ts","./land":"./land.ts","./hold":"./hold.ts","./tools":"./tools.ts","./vocab":"./vocab.ts","./service":"./service.ts","./source":"./source.ts","./workspace":"./workspace.ts"},"imports":{"@yaks/git":"./mod.ts","@yaks/git/cites":"./cites.ts","@yaks/git/door":"./door.ts","@yaks/git/address":"./address.ts","@yaks/git/push":"./push.ts","@yaks/git/host":"./host.ts","@yaks/git/land":"./land.ts","@yaks/git/hold":"./hold.ts","@yaks/git/tools":"./tools.ts","@yaks/git/vocab":"./vocab.ts","@yaks/git/service":"./service.ts","@yaks/git/source":"./source.ts","@yaks/git/workspace":"./workspace.ts"}}
|
package/door.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// A repository's door: what a clone or a fetch at a repository's address is
|
|
2
|
+
// answered with, over repositories its host finds by name. The wire is
|
|
3
|
+
// ./http.ts; this decides which address is which door, how a clone is asked
|
|
4
|
+
// for its credential, and what it hears when it is not getting one. Where the
|
|
5
|
+
// refs and the objects are kept, and who may read them, are the host's.
|
|
6
|
+
//
|
|
7
|
+
// A repository is `<name>.git`, and smart HTTP knocks on two addresses under
|
|
8
|
+
// it (`DOORS`). A name holds no dot of its own, so the split is unambiguous.
|
|
9
|
+
// A clone of `<name>/`, the address a browser shows, asks for the
|
|
10
|
+
// advertisement there (`BARE`) and is sent to `<name>.git` by a 301, which git
|
|
11
|
+
// follows and posts its fetch to where it landed
|
|
12
|
+
// (`http.followRedirects=initial`, git's default since 2.11). So the detector
|
|
13
|
+
// is the query, never the user agent: `?service=git-upload-pack` is something
|
|
14
|
+
// no browser asks for, and a site that serves a static `info/refs` serves it
|
|
15
|
+
// to a browser as before.
|
|
16
|
+
//
|
|
17
|
+
// A clone has to be asked for its credential: git sends none unprompted, so a
|
|
18
|
+
// private repository that said 404 would be a 404 to its own owner. So a
|
|
19
|
+
// repository the request may not read answers `401 WWW-Authenticate: Basic`
|
|
20
|
+
// while nobody has proved anything, and git comes back with a password. Once
|
|
21
|
+
// somebody has, the answer is 403, which is terminal: 401 would send git
|
|
22
|
+
// round to ask for the password they already gave correctly. A repository
|
|
23
|
+
// the host does not find is 404 to everyone, credential or not.
|
|
24
|
+
import { advertise, SERVICE, uploadPack } from "./http.js";
|
|
25
|
+
import { RECEIVE } from "./http.js";
|
|
26
|
+
import { BARE, DOORS } from "./address.js";
|
|
27
|
+
export { BARE, DOORS, knocks } from "./address.js";
|
|
28
|
+
// What a clone hears when it is not getting one. Plain text, because the
|
|
29
|
+
// thing reading it is git and not a browser.
|
|
30
|
+
let refusal = (status, say, more = {})=>new Response(`git: ${say}\n`, {
|
|
31
|
+
status,
|
|
32
|
+
headers: {
|
|
33
|
+
'content-type': 'text/plain; charset=utf-8',
|
|
34
|
+
...more
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
/// password(new Request('http://x', { headers: { authorization: 'Basic ' + btoa('x:tok') } })) -> 'tok'
|
|
38
|
+
/// password(new Request('http://x', { headers: { authorization: 'Basic ' + btoa('x:') } })) -> null
|
|
39
|
+
/// password(new Request('http://x', { headers: { authorization: 'Bearer tok' } })) -> null
|
|
40
|
+
/// password(new Request('http://x')) -> null
|
|
41
|
+
/** The password of a request's Basic credential. Its username is whatever
|
|
42
|
+
* the person typed in front of it, which a token that says whose it is makes
|
|
43
|
+
* decoration. */ export let password = (req)=>{
|
|
44
|
+
let said = /^Basic +(\S+)$/i.exec(req.headers.get('authorization') ?? '');
|
|
45
|
+
if (!said) return null;
|
|
46
|
+
let pair;
|
|
47
|
+
try {
|
|
48
|
+
pair = atob(said[1]);
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
let colon = pair.indexOf(':');
|
|
53
|
+
return colon < 0 ? null : pair.slice(colon + 1) || null;
|
|
54
|
+
};
|
|
55
|
+
// The browser's address, sent to the repository's own with its query.
|
|
56
|
+
let redirect = (req, path)=>{
|
|
57
|
+
let bare = BARE.exec(path);
|
|
58
|
+
let url = new URL(req.url);
|
|
59
|
+
if (req.method != 'GET' || !bare) return null;
|
|
60
|
+
if (url.searchParams.get('service') != SERVICE) return null;
|
|
61
|
+
url.pathname = `/${bare[1]}.git/info/refs`;
|
|
62
|
+
return Response.redirect(url, 301);
|
|
63
|
+
};
|
|
64
|
+
/** The door: a `Response` for a repository's address, `null` for any other,
|
|
65
|
+
* which its host answers as it would without one. */ export let door = (host)=>async (req)=>{
|
|
66
|
+
let path = new URL(req.url).pathname;
|
|
67
|
+
let asked = DOORS.exec(path);
|
|
68
|
+
if (!asked) return redirect(req, path);
|
|
69
|
+
let [, name, at] = asked;
|
|
70
|
+
let found = await host.find(name, req, password(req));
|
|
71
|
+
if (!found) return refusal(404, 'no such repository');
|
|
72
|
+
let pushing = at == RECEIVE || at == 'info/refs' && new URL(req.url).searchParams.get('service') == RECEIVE;
|
|
73
|
+
if (!found.reads) {
|
|
74
|
+
return found.proven ? refusal(403, 'not your repository') : refusal(401, pushing ? 'sign in to push to this repository' : 'sign in to clone this repository', {
|
|
75
|
+
'www-authenticate': `Basic realm="${host.realm}"`
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (pushing && found.receive) {
|
|
79
|
+
let { advertiseReceive, receivePack, warm } = await import("./push.js");
|
|
80
|
+
let hold = host.hold;
|
|
81
|
+
return at == 'info/refs' ? req.method == 'GET' ? advertiseReceive(found.refs, hold && ((refs)=>hold(warm(refs, found.objects)))) : refusal(405, 'use GET') : receivePack(req, found.refs, found.objects, found.receive);
|
|
82
|
+
}
|
|
83
|
+
if (at == RECEIVE) {
|
|
84
|
+
return refusal(403, 'push is unavailable for this repository');
|
|
85
|
+
}
|
|
86
|
+
return at == 'info/refs' ? advertise(req) : uploadPack(req, found.refs, found.objects, host.failed);
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=door.js.map
|
package/door.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"door.js","sources":["./door.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,uEAAuE;AACvE,4EAA4E;AAC5E,8EAA8E;AAC9E,wEAAwE;AACxE,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,kEAAkE;AAClE,+EAA+E;AAC/E,iDAAiD;AACjD,8EAA8E;AAC9E,8EAA8E;AAC9E,6EAA6E;AAC7E,0BAA0B;AAC1B,EAAE;AACF,8EAA8E;AAC9E,yEAAyE;AACzE,4EAA4E;AAC5E,6EAA6E;AAC7E,yEAAyE;AACzE,0EAA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