@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.
Files changed (183) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +754 -2
  3. package/_dist/address.d.ts +6 -0
  4. package/_dist/address.d.ts.map +1 -0
  5. package/_dist/checkout_vocab.d.ts +3 -0
  6. package/_dist/checkout_vocab.d.ts.map +1 -0
  7. package/_dist/cites.d.ts +48 -0
  8. package/_dist/cites.d.ts.map +1 -0
  9. package/_dist/commit.d.ts +36 -0
  10. package/_dist/commit.d.ts.map +1 -0
  11. package/_dist/comp.d.ts +29 -0
  12. package/_dist/comp.d.ts.map +1 -0
  13. package/_dist/door.d.ts +29 -0
  14. package/_dist/door.d.ts.map +1 -0
  15. package/_dist/format.d.ts +2 -0
  16. package/_dist/format.d.ts.map +1 -0
  17. package/_dist/hold.d.ts +6 -0
  18. package/_dist/hold.d.ts.map +1 -0
  19. package/_dist/host.d.ts +126 -0
  20. package/_dist/host.d.ts.map +1 -0
  21. package/_dist/http.d.ts +33 -0
  22. package/_dist/http.d.ts.map +1 -0
  23. package/_dist/import.d.ts +13 -0
  24. package/_dist/import.d.ts.map +1 -0
  25. package/_dist/index.d.ts +80 -0
  26. package/_dist/index.d.ts.map +1 -0
  27. package/_dist/land.d.ts +77 -0
  28. package/_dist/land.d.ts.map +1 -0
  29. package/_dist/mod.d.ts +73 -0
  30. package/_dist/mod.d.ts.map +1 -0
  31. package/_dist/objects.d.ts +40 -0
  32. package/_dist/objects.d.ts.map +1 -0
  33. package/_dist/oid.d.ts +24 -0
  34. package/_dist/oid.d.ts.map +1 -0
  35. package/_dist/pack-store.d.ts +9 -0
  36. package/_dist/pack-store.d.ts.map +1 -0
  37. package/_dist/pack.d.ts +26 -0
  38. package/_dist/pack.d.ts.map +1 -0
  39. package/_dist/pkt.d.ts +14 -0
  40. package/_dist/pkt.d.ts.map +1 -0
  41. package/_dist/placement.d.ts +4 -0
  42. package/_dist/placement.d.ts.map +1 -0
  43. package/_dist/plugin.d.ts +43 -0
  44. package/_dist/plugin.d.ts.map +1 -0
  45. package/_dist/project.d.ts +20 -0
  46. package/_dist/project.d.ts.map +1 -0
  47. package/_dist/push.d.ts +42 -0
  48. package/_dist/push.d.ts.map +1 -0
  49. package/_dist/refs.d.ts +81 -0
  50. package/_dist/refs.d.ts.map +1 -0
  51. package/_dist/rewrite.d.ts +35 -0
  52. package/_dist/rewrite.d.ts.map +1 -0
  53. package/_dist/service.d.ts +35 -0
  54. package/_dist/service.d.ts.map +1 -0
  55. package/_dist/sha1.d.ts +11 -0
  56. package/_dist/sha1.d.ts.map +1 -0
  57. package/_dist/source.d.ts +12 -0
  58. package/_dist/source.d.ts.map +1 -0
  59. package/_dist/tools.d.ts +11 -0
  60. package/_dist/tools.d.ts.map +1 -0
  61. package/_dist/tree.d.ts +28 -0
  62. package/_dist/tree.d.ts.map +1 -0
  63. package/_dist/unpack.d.ts +5 -0
  64. package/_dist/unpack.d.ts.map +1 -0
  65. package/_dist/vocab.d.ts +8 -0
  66. package/_dist/vocab.d.ts.map +1 -0
  67. package/_dist/workspace.d.ts +17 -0
  68. package/_dist/workspace.d.ts.map +1 -0
  69. package/address.js +9 -0
  70. package/address.js.map +1 -0
  71. package/address.ts +15 -0
  72. package/cache.js +9 -0
  73. package/cache.js.map +1 -0
  74. package/cache.ts +6 -0
  75. package/checkout.js +18 -0
  76. package/checkout.js.map +1 -0
  77. package/checkout.ts +24 -0
  78. package/checkout_vocab.js +14 -0
  79. package/checkout_vocab.js.map +1 -0
  80. package/checkout_vocab.ts +11 -0
  81. package/cites.js +189 -0
  82. package/cites.js.map +1 -0
  83. package/cites.ts +206 -0
  84. package/commit.js +128 -0
  85. package/commit.js.map +1 -0
  86. package/commit.ts +183 -0
  87. package/comp.js +94 -0
  88. package/comp.js.map +1 -0
  89. package/comp.ts +111 -0
  90. package/deno.json +1 -0
  91. package/door.js +88 -0
  92. package/door.js.map +1 -0
  93. package/door.ts +142 -0
  94. package/format.js +43 -0
  95. package/format.js.map +1 -0
  96. package/format.ts +49 -0
  97. package/hold.js +17 -0
  98. package/hold.js.map +1 -0
  99. package/hold.ts +21 -0
  100. package/host.js +1024 -0
  101. package/host.js.map +1 -0
  102. package/host.ts +1140 -0
  103. package/http.js +268 -0
  104. package/http.js.map +1 -0
  105. package/http.ts +329 -0
  106. package/import.js +141 -0
  107. package/import.js.map +1 -0
  108. package/import.ts +128 -0
  109. package/index.js +496 -0
  110. package/index.js.map +1 -0
  111. package/index.ts +634 -0
  112. package/land.js +788 -0
  113. package/land.js.map +1 -0
  114. package/land.ts +871 -0
  115. package/mod.js +73 -0
  116. package/mod.js.map +1 -0
  117. package/mod.ts +74 -0
  118. package/objects.js +331 -0
  119. package/objects.js.map +1 -0
  120. package/objects.ts +390 -0
  121. package/oid.js +50 -0
  122. package/oid.js.map +1 -0
  123. package/oid.ts +83 -0
  124. package/pack-index.js +103 -0
  125. package/pack-index.js.map +1 -0
  126. package/pack-index.ts +104 -0
  127. package/pack-store.js +216 -0
  128. package/pack-store.js.map +1 -0
  129. package/pack-store.ts +292 -0
  130. package/pack.js +121 -0
  131. package/pack.js.map +1 -0
  132. package/pack.ts +146 -0
  133. package/package.json +78 -4
  134. package/pkt.js +73 -0
  135. package/pkt.js.map +1 -0
  136. package/pkt.ts +93 -0
  137. package/placement.js +44 -0
  138. package/placement.js.map +1 -0
  139. package/placement.ts +38 -0
  140. package/plugin.js +66 -0
  141. package/plugin.js.map +1 -0
  142. package/plugin.ts +88 -0
  143. package/process-cwd.py +57 -0
  144. package/project.js +142 -0
  145. package/project.js.map +1 -0
  146. package/project.ts +151 -0
  147. package/push.js +401 -0
  148. package/push.js.map +1 -0
  149. package/push.ts +451 -0
  150. package/refs.js +176 -0
  151. package/refs.js.map +1 -0
  152. package/refs.ts +285 -0
  153. package/rewrite.js +176 -0
  154. package/rewrite.js.map +1 -0
  155. package/rewrite.ts +173 -0
  156. package/service.js +104 -0
  157. package/service.js.map +1 -0
  158. package/service.ts +194 -0
  159. package/sha1.js +115 -0
  160. package/sha1.js.map +1 -0
  161. package/sha1.ts +146 -0
  162. package/source.js +100 -0
  163. package/source.js.map +1 -0
  164. package/source.ts +116 -0
  165. package/spare.js +108 -0
  166. package/spare.js.map +1 -0
  167. package/spare.ts +94 -0
  168. package/tools.js +278 -0
  169. package/tools.js.map +1 -0
  170. package/tools.ts +310 -0
  171. package/tree.js +105 -0
  172. package/tree.js.map +1 -0
  173. package/tree.ts +132 -0
  174. package/unpack.js +207 -0
  175. package/unpack.js.map +1 -0
  176. package/unpack.ts +210 -0
  177. package/vocab.js +20 -0
  178. package/vocab.js.map +1 -0
  179. package/vocab.json +386 -0
  180. package/vocab.ts +22 -0
  181. package/workspace.js +449 -0
  182. package/workspace.js.map +1 -0
  183. package/workspace.ts +445 -0
package/mod.js ADDED
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @yaks/git — Git objects stored as graph entities, so a deploy history is a
3
+ * repository anyone can clone.
4
+ *
5
+ * A yaks.app version is a file manifest — `path → sha256`, over bytes already
6
+ * in a @yaks/blob store. This package turns one into the objects Git asks for
7
+ * and keeps them in a graph:
8
+ *
9
+ * ```ts
10
+ * import { index } from '@yaks/git'
11
+ *
12
+ * // let git = index(g, store)
13
+ * // let tree = await git.files({ 'index.html': sha, 'lib/app.js': other })
14
+ * // let head = await git.commit({
15
+ * // tree,
16
+ * // author: { name: 'ada', email: 'ada@users.yaks.app', at: deployedAt },
17
+ * // committer: { name: 'yaks.app', email: 'git@yaks.app', at: deployedAt },
18
+ * // message: 'deploy 7',
19
+ * // })
20
+ * ```
21
+ *
22
+ * What it is made of:
23
+ *
24
+ * - **An object's entity id is its Git object id.** {@link oid} computes Git's
25
+ * SHA-1 id over `"<type> <size>\0<body>"`, so the same object written by two
26
+ * apps is one row, and a `want` line in a fetch request is a lookup by id.
27
+ * - **Every object also has a SHA-256 object id**, from the first write:
28
+ * {@link oid256} over the same object with its children's ids translated,
29
+ * stored as an @yaks/key of kind `compat`. A client that asks for
30
+ * `object-format=sha256` is answered from that key rather than by converting
31
+ * the repository.
32
+ * - **Bodies carry tree children; rows carry object addresses.**
33
+ * {@link treeBody} and {@link commitBody} write Git's own bytes; the graph
34
+ * keeps `gitobj{type, size}`, `blob{sha}` and `parent` edges;
35
+ * a pack reads tree children from the immutable body.
36
+ * - **A Git blob is the blob you already have.** The bytes an app deployed are
37
+ * already stored under their SHA-256 address; the Git object is those bytes
38
+ * with a header hashed over them, and nothing is re-encoded or copied.
39
+ * - **A clone is those walks, packed.** {@link objects} lists every object
40
+ * reachable from a set of wants, minus what the client already has, and
41
+ * {@link pack} streams them as a version 2 packfile — whole objects, no
42
+ * deltas.
43
+ * - **A branch is a row.** {@link refEid} derives its entity id,
44
+ * {@link refAt} reads where it points, and {@link commitOnto} lands one
45
+ * manifest on it: objects written, then the branch moved, in an order that
46
+ * makes running it twice cost reads and no writes. {@link commits} is that
47
+ * same step packaged as a plugin hooked on the `effect` phase.
48
+ * - **And a clone is HTTP.** {@link advertise} and {@link uploadPack}
49
+ * implement Git's smart HTTP protocol, version 2, read-only: a `Request` in,
50
+ * a `Response` out, over a {@link Refs} and an {@link Objects} that the
51
+ * caller mounting them supplies.
52
+ *
53
+ * Object storage and clone use `crypto.subtle`, `CompressionStream` and
54
+ * `Request`/`Response`, so the same code runs on a server, in a worker and in
55
+ * a browser tab. Receive-pack uses `node:zlib` to unpack pushes. Its door (`@yaks/git/door`) answers a repository's addresses;
56
+ * which repository a name is, and who may read it, are its host's.
57
+ *
58
+ * @module
59
+ */ export * from "./comp.js";
60
+ export * from "./oid.js";
61
+ export * from "./tree.js";
62
+ export * from "./commit.js";
63
+ export * from "./index.js";
64
+ export * from "./sha1.js";
65
+ export * from "./pack.js";
66
+ export * from "./pack-store.js";
67
+ export * from "./rewrite.js";
68
+ export * from "./objects.js";
69
+ export * from "./pkt.js";
70
+ export * from "./http.js";
71
+ export * from "./refs.js";
72
+ export * from "./plugin.js";
73
+ //# sourceMappingURL=mod.js.map
package/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DC,GAED,0BAAyB;AACzB,yBAAwB;AACxB,0BAAyB;AACzB,4BAA2B;AAC3B,2BAA0B;AAC1B,0BAAyB;AACzB,0BAAyB;AACzB,gCAA+B;AAC/B,6BAA4B;AAC5B,6BAA4B;AAC5B,yBAAwB;AACxB,0BAAyB;AACzB,0BAAyB;AACzB,4BAA2B"}
package/mod.ts ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @yaks/git — Git objects stored as graph entities, so a deploy history is a
3
+ * repository anyone can clone.
4
+ *
5
+ * A yaks.app version is a file manifest — `path → sha256`, over bytes already
6
+ * in a @yaks/blob store. This package turns one into the objects Git asks for
7
+ * and keeps them in a graph:
8
+ *
9
+ * ```ts
10
+ * import { index } from '@yaks/git'
11
+ *
12
+ * // let git = index(g, store)
13
+ * // let tree = await git.files({ 'index.html': sha, 'lib/app.js': other })
14
+ * // let head = await git.commit({
15
+ * // tree,
16
+ * // author: { name: 'ada', email: 'ada@users.yaks.app', at: deployedAt },
17
+ * // committer: { name: 'yaks.app', email: 'git@yaks.app', at: deployedAt },
18
+ * // message: 'deploy 7',
19
+ * // })
20
+ * ```
21
+ *
22
+ * What it is made of:
23
+ *
24
+ * - **An object's entity id is its Git object id.** {@link oid} computes Git's
25
+ * SHA-1 id over `"<type> <size>\0<body>"`, so the same object written by two
26
+ * apps is one row, and a `want` line in a fetch request is a lookup by id.
27
+ * - **Every object also has a SHA-256 object id**, from the first write:
28
+ * {@link oid256} over the same object with its children's ids translated,
29
+ * stored as an @yaks/key of kind `compat`. A client that asks for
30
+ * `object-format=sha256` is answered from that key rather than by converting
31
+ * the repository.
32
+ * - **Bodies carry tree children; rows carry object addresses.**
33
+ * {@link treeBody} and {@link commitBody} write Git's own bytes; the graph
34
+ * keeps `gitobj{type, size}`, `blob{sha}` and `parent` edges;
35
+ * a pack reads tree children from the immutable body.
36
+ * - **A Git blob is the blob you already have.** The bytes an app deployed are
37
+ * already stored under their SHA-256 address; the Git object is those bytes
38
+ * with a header hashed over them, and nothing is re-encoded or copied.
39
+ * - **A clone is those walks, packed.** {@link objects} lists every object
40
+ * reachable from a set of wants, minus what the client already has, and
41
+ * {@link pack} streams them as a version 2 packfile — whole objects, no
42
+ * deltas.
43
+ * - **A branch is a row.** {@link refEid} derives its entity id,
44
+ * {@link refAt} reads where it points, and {@link commitOnto} lands one
45
+ * manifest on it: objects written, then the branch moved, in an order that
46
+ * makes running it twice cost reads and no writes. {@link commits} is that
47
+ * same step packaged as a plugin hooked on the `effect` phase.
48
+ * - **And a clone is HTTP.** {@link advertise} and {@link uploadPack}
49
+ * implement Git's smart HTTP protocol, version 2, read-only: a `Request` in,
50
+ * a `Response` out, over a {@link Refs} and an {@link Objects} that the
51
+ * caller mounting them supplies.
52
+ *
53
+ * Object storage and clone use `crypto.subtle`, `CompressionStream` and
54
+ * `Request`/`Response`, so the same code runs on a server, in a worker and in
55
+ * a browser tab. Receive-pack uses `node:zlib` to unpack pushes. Its door (`@yaks/git/door`) answers a repository's addresses;
56
+ * which repository a name is, and who may read it, are its host's.
57
+ *
58
+ * @module
59
+ */
60
+
61
+ export * from './comp.js'
62
+ export * from './oid.js'
63
+ export * from './tree.js'
64
+ export * from './commit.js'
65
+ export * from './index.js'
66
+ export * from './sha1.js'
67
+ export * from './pack.js'
68
+ export * from './pack-store.js'
69
+ export * from './rewrite.js'
70
+ export * from './objects.js'
71
+ export * from './pkt.js'
72
+ export * from './http.js'
73
+ export * from './refs.js'
74
+ export * from './plugin.js'
package/objects.js ADDED
@@ -0,0 +1,331 @@
1
+ // What a clone has to carry: every object reachable from the commits a client
2
+ // asked for, each one once, and the bytes of each — the other half of a
3
+ // packfile, which ./pack.ts writes without looking anything up.
4
+ //
5
+ // Two walks and a read. Commits are followed along `parent` edges; trees and
6
+ // a commit's own tree are read from their immutable bodies (`treeEntries`,
7
+ // ./tree.ts; `treeOf`, ./commit.ts). Each entry's mode says whether its child
8
+ // is a tree or a blob, without another query of the object index. Each
9
+ // object is listed once: the same tree under two commits, or one blob under
10
+ // two names, is one entry in the packfile.
11
+ //
12
+ // A `have` is subtraction, not negotiation. Everything the client reports it
13
+ // holds is walked first into the same seen set, so those objects are simply
14
+ // absent from the answer. One round, no deltas, no shallow clones: a first
15
+ // clone is the full reachable set, and a fetch after it is the difference
16
+ // (D-34943). A `have` naming an object this graph never held is ignored — the
17
+ // client may hold objects we do not.
18
+ //
19
+ // The frontier is read in batches because a query's any-of list becomes bound
20
+ // parameters and a database limits how many there may be. The commit walk
21
+ // follows the parent relation in the graph on the other side of that door.
22
+ import { streamOf } from "@yaks/blob";
23
+ import { line } from "@yaks/query";
24
+ import { WALK_LIMIT } from "@yaks/query/core";
25
+ import { commitParts, treeOf } from "./commit.js";
26
+ import { BLOB, GITOBJ, PARENT } from "./comp.js";
27
+ import { pack } from "./pack.js";
28
+ import { DIR, treeEntries } from "./tree.js";
29
+ export let reachable = (from, roots)=>{
30
+ let found = new Set();
31
+ let next = [
32
+ ...roots
33
+ ];
34
+ while(next.length){
35
+ let oid = next.pop();
36
+ let links = from.get(oid);
37
+ if (!links || found.has(oid)) continue;
38
+ found.add(oid);
39
+ for (let link of links)next.push(link);
40
+ }
41
+ return found;
42
+ };
43
+ // How many ids go into one query's any-of list.
44
+ let BITE = 100;
45
+ let comp = (b, name)=>b[name] ?? {};
46
+ /** An object reader over a graph that carries this package's components and
47
+ * the @yaks/blob store that holds the bytes — the same pair the index writes
48
+ * to. */ export let objects = (g, store)=>{
49
+ // One query per batch of the frontier, with the results appended.
50
+ let some = async (query, oids)=>{
51
+ let out = [];
52
+ for(let i = 0; i < oids.length; i += BITE){
53
+ out.push(...await g.read(query(oids.slice(i, i + BITE))));
54
+ }
55
+ return out;
56
+ };
57
+ // Each object's index row, as this reader has read it: an object's id names
58
+ // its content, so its row never changes, and a walk that reads an object
59
+ // to follow its links leaves the row for the pack that carries it.
60
+ let known = new Map();
61
+ // The type of each of these objects — and, by absence, which we never had.
62
+ let kinds = async (oids)=>{
63
+ let unread = oids.filter((oid)=>!known.has(oid));
64
+ let read = new Map((await some((l)=>line`.${GITOBJ}&.entity.eid=${l}`, unread)).map((r)=>[
65
+ r.entity.eid,
66
+ comp(r, GITOBJ).type
67
+ ]));
68
+ return new Map(oids.flatMap((oid)=>{
69
+ let type = known.get(oid)?.type ?? read.get(oid);
70
+ return type ? [
71
+ [
72
+ oid,
73
+ type
74
+ ]
75
+ ] : [];
76
+ }));
77
+ };
78
+ let ancestors = async (tip)=>{
79
+ let rows = await g.read(line`.gitobj&.parent<-${tip}&.limit=${WALK_LIMIT}`);
80
+ let ids = rows.map((r)=>r.entity.eid);
81
+ if (ids.length < WALK_LIMIT) return ids;
82
+ // A capped query may have stopped at any boundary. Follow only the
83
+ // edges that leave the set it returned, then repeat at those parents.
84
+ let covered = new Set([
85
+ tip,
86
+ ...ids
87
+ ]);
88
+ let edges = await some((l)=>line`.${PARENT}&.edge.from=${l}`, [
89
+ ...covered
90
+ ]);
91
+ let next = new Set(edges.map((r)=>String(comp(r, 'edge').to)));
92
+ for (let id of next){
93
+ if (!covered.has(id)) ids.push(id, ...await ancestors(id));
94
+ }
95
+ return ids;
96
+ };
97
+ async function* indexed(oids) {
98
+ for(let i = 0; i < oids.length; i += BITE){
99
+ let bite = oids.slice(i, i + BITE);
100
+ // `?blob` is not decoration: a query returns the components it names,
101
+ // and a graph reached over @yaks/api's read endpoint returns exactly
102
+ // those — so a read that asked only for `.gitobj` came back with rows
103
+ // that did not include where the bytes were, and every object was
104
+ // reported missing.
105
+ let unread = bite.filter((oid)=>!known.has(oid));
106
+ for (let row of (await some((l)=>line`.${GITOBJ}&?${BLOB}&.entity.eid=${l}`, unread))){
107
+ let { type, size } = comp(row, GITOBJ);
108
+ known.set(row.entity.eid, {
109
+ sha: String(comp(row, BLOB).sha),
110
+ type: type,
111
+ size: Number(size)
112
+ });
113
+ }
114
+ yield bite.map((oid)=>{
115
+ let row = known.get(oid);
116
+ if (!row) throw new Error(`git: no object ${oid}`);
117
+ return row;
118
+ });
119
+ }
120
+ }
121
+ let bytesOf = async (sha, type)=>{
122
+ let bytes = await store.get(sha, type);
123
+ if (!bytes) throw new Error(`git: no bytes stored under ${sha}`);
124
+ return bytes;
125
+ };
126
+ async function* read(oids) {
127
+ let width = 6;
128
+ for await (let bite of indexed(oids)){
129
+ for(let at = 0; at < bite.length; at += width){
130
+ let group = bite.slice(at, at + width);
131
+ yield* await Promise.all(group.map(async ({ type, sha })=>({
132
+ type,
133
+ bytes: await bytesOf(sha, type)
134
+ })));
135
+ }
136
+ }
137
+ }
138
+ async function* streamed(oids) {
139
+ for await (let bite of indexed(oids)){
140
+ for (let { type, sha, size } of bite){
141
+ yield {
142
+ type,
143
+ size,
144
+ body: async ()=>{
145
+ if (!store.open) return streamOf(await bytesOf(sha, type)).stream;
146
+ let object = await store.open(sha, type);
147
+ if (!object) throw new Error(`git: no bytes stored under ${sha}`);
148
+ return object.read();
149
+ }
150
+ };
151
+ }
152
+ }
153
+ }
154
+ let packObjects = (oids, prior)=>pack(oids.length + (prior?.count ?? 0), streamed(oids), prior);
155
+ // Walk immutable bodies only up to the packed frontier. A held tree
156
+ // covers its whole subtree, and a held commit covers its entire ancestry.
157
+ let additions = async (tip, held)=>{
158
+ let links = new Map();
159
+ let met = new Set();
160
+ let seen = new Set();
161
+ let front = async (oids)=>{
162
+ let fresh = oids.filter((oid)=>!seen.has(oid) && (seen.add(oid), true));
163
+ let known = await held(fresh);
164
+ for (let oid of known)met.add(oid);
165
+ return fresh.filter((oid)=>!known.has(oid));
166
+ };
167
+ let commits = [
168
+ tip
169
+ ];
170
+ let trees = [];
171
+ while(commits.length){
172
+ let batch = await front(commits);
173
+ commits = [];
174
+ let at = 0;
175
+ for await (let obj of read(batch)){
176
+ let { tree, parents } = commitParts(obj.bytes);
177
+ links.set(batch[at++], [
178
+ tree,
179
+ ...parents
180
+ ]);
181
+ trees.push(tree);
182
+ for (let parent of parents)commits.push(parent);
183
+ }
184
+ }
185
+ let blobs = new Set();
186
+ while(trees.length){
187
+ let batch = await front(trees);
188
+ trees = [];
189
+ let at = 0;
190
+ for await (let obj of read(batch)){
191
+ let entries = treeEntries(obj.bytes);
192
+ links.set(batch[at++], entries.map((e)=>e.oid));
193
+ for (let entry of entries){
194
+ if (entry.mode == DIR) trees.push(entry.oid);
195
+ else blobs.add(entry.oid);
196
+ }
197
+ }
198
+ }
199
+ for (let oid of (await front([
200
+ ...blobs
201
+ ])))links.set(oid, []);
202
+ return {
203
+ links,
204
+ met
205
+ };
206
+ };
207
+ // One graph walk gets the commit frontier; its bodies name the tree
208
+ // frontier. Previously packed objects already carry their immutable links.
209
+ let catalog = async (tip, prior = new Map())=>{
210
+ let links = new Map(prior);
211
+ let commits = prior.has(tip) ? [] : [
212
+ ...new Set([
213
+ tip,
214
+ ...await ancestors(tip)
215
+ ])
216
+ ].filter((oid)=>!links.has(oid));
217
+ let trees = new Set();
218
+ let n = 0;
219
+ for await (let obj of read(commits)){
220
+ let { tree, parents } = commitParts(obj.bytes);
221
+ links.set(commits[n++], [
222
+ tree,
223
+ ...parents
224
+ ]);
225
+ trees.add(tree);
226
+ }
227
+ while(trees.size){
228
+ let front = [
229
+ ...trees
230
+ ].filter((oid)=>!links.has(oid));
231
+ trees.clear();
232
+ let at = 0;
233
+ for await (let obj of read(front)){
234
+ let entries = treeEntries(obj.bytes);
235
+ links.set(front[at++], entries.map((e)=>e.oid));
236
+ for (let entry of entries){
237
+ if (entry.mode == DIR) trees.add(entry.oid);
238
+ else if (!links.has(entry.oid)) links.set(entry.oid, []);
239
+ }
240
+ }
241
+ }
242
+ let all = reachable(links, [
243
+ tip
244
+ ]);
245
+ let out = new Map();
246
+ for (let oid of all){
247
+ let children = links.get(oid);
248
+ if (children.some((child)=>!all.has(child))) {
249
+ throw new Error(`git: incomplete history at ${oid}`);
250
+ }
251
+ out.set(oid, children);
252
+ }
253
+ return out;
254
+ };
255
+ // The walk itself. `seen` comes in holding what the client has and goes out
256
+ // holding that plus every object this answer lists.
257
+ let walk = async (roots, seen, history = true)=>{
258
+ let fresh = (oids)=>oids.filter((o)=>!seen.has(o) && (seen.add(o), true));
259
+ let kind = await kinds(roots);
260
+ let missing = roots.find((o)=>!kind.has(o));
261
+ if (missing) throw new Error(`git: no object ${missing}`);
262
+ let found = fresh(roots.filter((o)=>kind.get(o) == 'commit'));
263
+ if (history) {
264
+ for (let tip of [
265
+ ...found
266
+ ])found.push(...fresh(await ancestors(tip)));
267
+ }
268
+ // A commit's tree is in its body; a `want` that is a tree is its own root.
269
+ let tops = roots.filter((o)=>kind.get(o) == 'tree');
270
+ for await (let o of read(found)){
271
+ let tree = treeOf(o.bytes);
272
+ if (tree) tops.push(tree);
273
+ }
274
+ let blobs = fresh(roots.filter((o)=>kind.get(o) == 'blob'));
275
+ let front = fresh(tops);
276
+ while(front.length){
277
+ found.push(...front);
278
+ let next = [];
279
+ for await (let tree of read(front)){
280
+ for (let entry of treeEntries(tree.bytes)){
281
+ if (seen.has(entry.oid)) continue;
282
+ seen.add(entry.oid);
283
+ if (entry.mode == DIR) next.push(entry.oid);
284
+ else blobs.push(entry.oid);
285
+ }
286
+ }
287
+ front = next;
288
+ }
289
+ return [
290
+ ...found,
291
+ ...blobs
292
+ ];
293
+ };
294
+ let reach = async (wants, haves = [])=>{
295
+ let seen = new Set();
296
+ // Only the haves we recognise: a client may hold objects we never had.
297
+ if (haves.length) await walk([
298
+ ...(await kinds(haves)).keys()
299
+ ], seen);
300
+ return walk(wants, seen);
301
+ };
302
+ return {
303
+ commits: async (tip, held)=>{
304
+ let ids = [
305
+ ...new Set([
306
+ tip,
307
+ ...await ancestors(tip)
308
+ ])
309
+ ].filter((oid)=>!held?.has(oid));
310
+ let found = new Map();
311
+ let i = 0;
312
+ for await (let object of read(ids))found.set(ids[i++], object.bytes);
313
+ return found;
314
+ },
315
+ additions,
316
+ catalog,
317
+ common: async (wants, haves)=>{
318
+ let known = new Set(wants);
319
+ for (let want of wants){
320
+ for (let parent of (await ancestors(want)))known.add(parent);
321
+ }
322
+ return haves.filter((oid)=>known.has(oid));
323
+ },
324
+ reach,
325
+ snapshots: (tips)=>walk(tips, new Set(), false),
326
+ read,
327
+ packObjects,
328
+ pack: async (wants, haves)=>packObjects(await reach(wants, haves))
329
+ };
330
+ };
331
+ //# sourceMappingURL=objects.js.map
package/objects.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objects.js","sources":["./objects.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,wEAAwE;AACxE,gEAAgE;AAChE,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,uEAAuE;AACvE,4EAA4E;AAC5E,2CAA2C;AAC3C,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,2EAA2E;AAC3E,0EAA0E;AAC1E,8EAA8E;AAC9E,qCAAqC;AACrC,EAAE;AACF,8EAA8E;AAC9E,0EAA0E;AAC1E,2EAA2E;AAE3E,SAAqB,QAAQ,0BAA+B;AAE5D,SAAoB,IAAI,2BAAgC;AACxD,SAAS,UAAU,gCAAqC;AACxD,SAAS,WAAW,EAAE,MAAM,sBAAqB;AACjD,SAAS,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAmB;AAEhD,SAAmB,IAAI,oBAAmB;AAC1C,SAAS,GAAG,EAAE,WAAW,oBAAmB;AA8B5C,OAAO,IAAI,YAAY,CAAC,MAAe;EACrC,IAAI,QAAQ,IAAI;EAChB,IAAI,OAAO;OAAI;GAAM;EACrB,MAAO,KAAK,MAAM,CAAE;IAClB,IAAI,MAAM,KAAK,GAAG;IAClB,IAAI,QAAQ,KAAK,GAAG,CAAC;IACrB,IAAI,CAAC,SAAS,MAAM,GAAG,CAAC,MAAM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