@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
@@ -0,0 +1,8 @@
1
+ import type { VocabDoc } from "@yaks/vocab";
2
+ import { gitDoc, refDoc } from "./comp.js";
3
+ import { checkoutDoc } from "./checkout_vocab.js";
4
+ export { checkoutDoc, gitDoc, refDoc };
5
+ /** What this package is: its manifest's description, the one place it is
6
+ * written, which a host stamps on each document here. */ export declare let description: string;
7
+ /** Every vocabulary document this plugin declares. */ export declare let docs: VocabDoc[];
8
+ //# sourceMappingURL=vocab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AASA,cAAc,QAAQ,2BAAgC;AACtD,SAAS,MAAM,EAAE,MAAM,oBAAmB;AAC1C,SAAS,WAAW,8BAA6B;AAGjD,SAAS,WAAW,EAAE,MAAM,EAAE,MAAM,GAAE;AAEtC;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,oDAAoD,GACpD,OAAO,YAAI,MAAM,WAAqB"}
@@ -0,0 +1,17 @@
1
+ import type { Bundle, Graph } from "@yaks/graph";
2
+ import type { ComputerTransport } from "@yaks/machine";
3
+ import { type CheckoutRequest, type Held } from "./host.js";
4
+ /** Resolve the stable filesystem, never a convenience directory. */ export declare let filesystem: (g: Graph, workspace: string) => Promise<Bundle>;
5
+ /** Operations bound to one explicitly connected filesystem. */ export type WorkspaceGit = {
6
+ discover: (cwd?: string) => Promise<Bundle>;
7
+ create: (request: CheckoutRequest, source?: string) => Promise<Bundle>;
8
+ reclaim: (id: string) => Promise<Held | 'referenced' | undefined>;
9
+ context: string;
10
+ };
11
+ /** Git on a selected workspace. The caller connects this exact filesystem
12
+ * before binding the transport. All paths, realpath and locks run there. */ export declare let workspaceGit: (g: Graph, workspace: string, transport: ComputerTransport) => Promise<WorkspaceGit>;
13
+ /** Graph references that keep a checkout: a process that has not exited, or
14
+ * the home of a session that has not settled. A running process uses its
15
+ * launch workspace even after a session switches its default. Missing
16
+ * placement is not evidence that it runs elsewhere. */ export declare let retained: (g: Graph, workspace: string) => Promise<boolean>;
17
+ //# sourceMappingURL=workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.d.ts","sources":["../workspace.ts"],"names":[],"mappings":"AAEA,cAAc,MAAM,EAAQ,KAAK,2BAAgC;AAcjE,cAAc,iBAAiB,6BAAkC;AAEjE,SACE,KAAK,eAAe,EACpB,KAAK,IAAI,oBAGO;AAIlB,kEAAkE,GAClE,OAAO,YAAI,aACT,GAAG,OACH,WAAW,MAAM,KAChB,QAAQ,QAqCV;AASD,6DAA6D,GAC7D,YAAY;EACV,WAAW,MAAM,MAAM,KAAK,QAAQ;EACpC,SAAS,SAAS,iBAAiB,SAAS,MAAM,KAAK,QAAQ;EAC/D,UAAU,IAAI,MAAM,KAAK,QAAQ,OAAO,eAAe,SAAS;EAChE,SAAS,MAAM;;AAGjB;0EAC0E,GAC1E,OAAO,YAAI,eACT,GAAG,OACH,WAAW,MAAM,EACjB,WAAW,sBACV,QAAQ,cA2QV;AAkBD;;;qDAGqD,GACrD,OAAO,YAAI,WAAkB,GAAG,OAAO,WAAW,MAAM,KAAG,QAAQ,OAAO,EAgEzE"}
package/address.js ADDED
@@ -0,0 +1,9 @@
1
+ /** The two addresses smart HTTP knocks on, under a name wearing `.git`. */ export let DOORS = /^\/([^/.]*)\.git\/(info\/refs|git-upload-pack|git-receive-pack)$/;
2
+ /** The advertisement asked for at the name's own address, where a clone of
3
+ * the browser's URL begins. */ export let BARE = /^\/([^/.]+)\/info\/refs$/;
4
+ /// knocks('/recipes.git/info/refs') -> true
5
+ /// knocks('/recipes/info/refs') -> true
6
+ /// knocks('/recipes/') -> false
7
+ /** Whether a path is one a clone knocks on, which a host answers with
8
+ * {@link door} ahead of whatever else it serves there. */ export let knocks = (path)=>DOORS.test(path) || BARE.test(path);
9
+ //# sourceMappingURL=address.js.map
package/address.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.js","sources":["./address.ts"],"names":[],"mappings":"AAAA,yEAAyE,GACzE,OAAO,IAAI,QACT,mEAAkE;AAEpE;6BAC6B,GAC7B,OAAO,IAAI,OAAe,2BAA0B;AAEpD,4CAA4C;AAC5C,wCAAwC;AACxC,gCAAgC;AAChC;wDACwD,GACxD,OAAO,IAAI,SAAS,CAAC,OACnB,MAAM,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,MAAK"}
package/address.ts ADDED
@@ -0,0 +1,15 @@
1
+ /** The two addresses smart HTTP knocks on, under a name wearing `.git`. */
2
+ export let DOORS: RegExp =
3
+ /^\/([^/.]*)\.git\/(info\/refs|git-upload-pack|git-receive-pack)$/
4
+
5
+ /** The advertisement asked for at the name's own address, where a clone of
6
+ * the browser's URL begins. */
7
+ export let BARE: RegExp = /^\/([^/.]+)\/info\/refs$/
8
+
9
+ /// knocks('/recipes.git/info/refs') -> true
10
+ /// knocks('/recipes/info/refs') -> true
11
+ /// knocks('/recipes/') -> false
12
+ /** Whether a path is one a clone knocks on, which a host answers with
13
+ * {@link door} ahead of whatever else it serves there. */
14
+ export let knocks = (path: string): boolean =>
15
+ DOORS.test(path) || BARE.test(path)
package/cache.js ADDED
@@ -0,0 +1,9 @@
1
+ // Paths a checkout can regenerate: dependencies, compiler output and declared
2
+ // scratch. Every other ignored path can hold unique work.
3
+ export let cache = (path)=>path.split('/').some((part)=>[
4
+ 'node_modules',
5
+ '.scratch',
6
+ '.types',
7
+ 'target'
8
+ ].includes(part));
9
+ //# sourceMappingURL=cache.js.map
package/cache.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sources":["./cache.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,0DAA0D;AAC1D,OAAO,IAAI,QAAQ,CAAC,OAClB,KAAK,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,OACpB;MAAC;MAAgB;MAAY;MAAU;KAAS,CAAC,QAAQ,CAAC,OAC3D"}
package/cache.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Paths a checkout can regenerate: dependencies, compiler output and declared
2
+ // scratch. Every other ignored path can hold unique work.
3
+ export let cache = (path: string): boolean =>
4
+ path.split('/').some((part) =>
5
+ ['node_modules', '.scratch', '.types', 'target'].includes(part)
6
+ )
package/checkout.js ADDED
@@ -0,0 +1,18 @@
1
+ // A checkout keeps the commit its first request resolved. Repeating that
2
+ // request after its branch moves still means the same checkout.
3
+ export let checkoutBase = async (intent, requested, resolve)=>{
4
+ let name = String(intent?.requested ?? requested ?? 'HEAD');
5
+ let pinned = intent?.base == null ? undefined : String(intent.base);
6
+ if (intent && requested != null && requested != name) {
7
+ let [before, after] = await Promise.all([
8
+ pinned ?? resolve(name),
9
+ resolve(requested)
10
+ ]);
11
+ if (before != after) {
12
+ throw new Error('checkout request conflicts with pinned base intent');
13
+ }
14
+ return before;
15
+ }
16
+ return pinned ?? await resolve(name);
17
+ };
18
+ //# sourceMappingURL=checkout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout.js","sources":["./checkout.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,gEAAgE;AAIhE,OAAO,IAAI,eAAe,OACxB,QACA,WACA;EAEA,IAAI,OAAO,OAAO,QAAQ,aAAa,aAAa;EACpD,IAAI,SAAS,QAAQ,QAAQ,OAAO,YAAY,OAAO,OAAO,IAAI;EAClE,IAAI,UAAU,aAAa,QAAQ,aAAa,MAAM;IACpD,IAAI,CAAC,QAAQ,MAAM,GAAG,MAAM,QAAQ,GAAG,CAAC;MACtC,UAAU,QAAQ;MAClB,QAAQ;KACT;IACD,IAAI,UAAU,OAAO;MACnB,MAAM,IAAI,MAAM;IAClB;IACA,OAAO;EACT;EACA,OAAO,UAAU,MAAM,QAAQ;AACjC,EAAC"}
package/checkout.ts ADDED
@@ -0,0 +1,24 @@
1
+ // A checkout keeps the commit its first request resolved. Repeating that
2
+ // request after its branch moves still means the same checkout.
3
+
4
+ type Intent = { requested?: unknown; base?: unknown }
5
+
6
+ export let checkoutBase = async (
7
+ intent: Intent | undefined,
8
+ requested: string | undefined,
9
+ resolve: (name: string) => Promise<string>,
10
+ ): Promise<string> => {
11
+ let name = String(intent?.requested ?? requested ?? 'HEAD')
12
+ let pinned = intent?.base == null ? undefined : String(intent.base)
13
+ if (intent && requested != null && requested != name) {
14
+ let [before, after] = await Promise.all([
15
+ pinned ?? resolve(name),
16
+ resolve(requested),
17
+ ])
18
+ if (before != after) {
19
+ throw new Error('checkout request conflicts with pinned base intent')
20
+ }
21
+ return before
22
+ }
23
+ return pinned ?? await resolve(name)
24
+ }
@@ -0,0 +1,14 @@
1
+ // The four components that describe checkouts on one machine — `repository`,
2
+ // `worktree`, `ref` and `checkout` — pulled out of ./vocab.json as a document
3
+ // of their own, for a graph that tracks checkouts but stores no Git objects.
4
+ import { pick } from "@yaks/vocab/runtime";
5
+ import gitDoc from './vocab.json' with {
6
+ type: 'json'
7
+ };
8
+ export const checkoutDoc = pick(gitDoc, [
9
+ 'repository',
10
+ 'worktree',
11
+ 'ref',
12
+ 'checkout'
13
+ ], 'git-checkout');
14
+ //# sourceMappingURL=checkout_vocab.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout_vocab.js","sources":["./checkout_vocab.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,8EAA8E;AAC9E,6EAA6E;AAE7E,SAAS,IAAI,mCAAuD;AACpE,OAAO,YAAY,oBAAoB;EAAE,MAAM;AAAO,EAAC;AACvD,OAAO,MAAM,cAAwB,KACnC,QACA;EAAC;EAAc;EAAY;EAAO;CAAW,EAC7C,gBACD"}
@@ -0,0 +1,11 @@
1
+ // The four components that describe checkouts on one machine — `repository`,
2
+ // `worktree`, `ref` and `checkout` — pulled out of ./vocab.json as a document
3
+ // of their own, for a graph that tracks checkouts but stores no Git objects.
4
+
5
+ import { pick, type VocabDoc } from '@yaks/vocab/runtime'
6
+ import gitDoc from './vocab.json' with { type: 'json' }
7
+ export const checkoutDoc: VocabDoc = pick(
8
+ gitDoc as VocabDoc,
9
+ ['repository', 'worktree', 'ref', 'checkout'],
10
+ 'git-checkout',
11
+ )
package/cites.js ADDED
@@ -0,0 +1,189 @@
1
+ // How a citation stands right now, derived and never stored.
2
+ //
3
+ // A citation is an edge — `A cites B` — carrying the commit it was last checked
4
+ // against (`revision{commit}`) and the `verified` mark somebody wrote when they
5
+ // checked it. What B is names the place: a @yaks/file `file` for a whole file,
6
+ // an entity wearing `lines{file, start, end}` for some lines of one (a place,
7
+ // holding the text the citer quoted as `content.body`), a @yaks/code `symbol`
8
+ // for a definition, whose file is its module, or any entity at all. Whether it
9
+ // is still true is not a property: it is re-derived here, so a document can
10
+ // never claim a freshness the repository contradicts.
11
+ //
12
+ // For a file of a repository, the question is Git's, asked in a checkout of
13
+ // that repository: which commits after `revision.commit` touched the place the
14
+ // citation names. `git log <commit>..HEAD` answers it, narrowed by
15
+ // `-L :<symbol>:<path>` or `-L <start>,<end>:<path>` when the citation named a
16
+ // place, so a commit elsewhere in the same file is not reported. The commit is
17
+ // checked with `cat-file` first, because a commit this checkout does not have
18
+ // (rebased away, or from another clone) makes `log` fail the same way an empty
19
+ // range succeeds-empty would look, and that must read as unknown rather than
20
+ // current: a citation that reads fresh on an answer nothing could establish is
21
+ // worse than one that admits it cannot tell.
22
+ //
23
+ // For anything else, a file on a volume and the lines of one included,
24
+ // @yaks/kernel compares the content hash kept when the citation was verified
25
+ // with the entity's content now.
26
+ //
27
+ // Nothing here writes: `cites verify` (./tools.ts) is the only thing that
28
+ // writes the mark. It runs `git` as a subprocess, so like ./host.ts and
29
+ // ./land.ts it stays out of ./mod.ts, which type-checks with only the web
30
+ // platform in scope.
31
+ import { CITES, status as entityStatus } from "@yaks/kernel";
32
+ import { run as git } from "./land.js";
33
+ export { CITES };
34
+ /** @yaks/file's component naming a file, a path in a root. (./tree.ts `FILE`
35
+ * is a tree entry's mode, a different thing, which is why these names live
36
+ * here.) */ export let FILE = 'file';
37
+ /** @yaks/file's component naming the lines of a file an entity sits at, which
38
+ * a citation of some lines points at. */ export let LINES = 'lines';
39
+ /** The component a file's root wears when Git answers for its files. */ export let REPOSITORY = 'repository';
40
+ /** The component naming the commit a citation was last checked against. */ export let REVISION = 'revision';
41
+ /** @yaks/code's component for an exported definition, named here because a
42
+ * citation may point at one. */ export let SYMBOL = 'symbol';
43
+ /** @yaks/kernel's mark, named here because a citation carries one. Only the
44
+ * act of checking writes it, so its absence means nobody has checked. */ export let VERIFIED = 'verified';
45
+ let comp = (b, name)=>b?.[name];
46
+ let text = (v)=>typeof v == 'string' ? v.trim() : '';
47
+ let count = (v)=>typeof v == 'number' && Number.isFinite(v) ? v : undefined;
48
+ /// within({ entity: { eid: 's' }, symbol: { module: 'f' } }) -> 'f'
49
+ /// within({ entity: { eid: 'p' }, lines: { file: 'f', start: 3 } }) -> 'f'
50
+ /// within({ entity: { eid: 'f' }, file: { path: 'a.ts' } }) -> undefined
51
+ /** The file a cited symbol or place is in, by id: a symbol's module, a place's
52
+ * file. Nothing for a file itself, or for anything that sits in no file. */ export let within = (to)=>text(comp(to, SYMBOL)?.module) || text(comp(to, LINES)?.file) || undefined;
53
+ /**
54
+ * The file of a repository a citation of `to` is checked against in Git: `to`
55
+ * itself when it is one, the module a symbol is in, or the file a place is in.
56
+ * Nothing when that file is not in a repository (a file on a volume, the lines
57
+ * of a transcript) or `to` is in no file at all: a citation of those holds to
58
+ * the cited content. `get` answers the file and its root by id.
59
+ */ export let tracked = (to, get)=>{
60
+ let ref = within(to);
61
+ let file = ref ? get(ref) : to;
62
+ let at = comp(file, FILE);
63
+ return text(at?.path) && get(text(at?.root))?.[REPOSITORY] ? file : undefined;
64
+ };
65
+ // The `-L` arguments narrowing the log to the place a citation names: the
66
+ // definition by name, else the lines, else nothing and the whole file is the
67
+ // place. A symbol is preferred over a range because it survives the file
68
+ // moving around it, which is the whole reason Git has the form.
69
+ let place = (to, path)=>{
70
+ let name = text(comp(to, SYMBOL)?.name);
71
+ if (name) return [
72
+ '-L',
73
+ `:${name}:${path}`
74
+ ];
75
+ let lines = comp(to, LINES);
76
+ let start = count(lines?.start);
77
+ if (start == null) return [];
78
+ return [
79
+ '-L',
80
+ `${start},${count(lines?.end) ?? start}:${path}`
81
+ ];
82
+ };
83
+ let short = (commit)=>commit.slice(0, 8);
84
+ let lines = (out)=>out.split('\n').map((l)=>l.trim()).filter(Boolean);
85
+ // Git's complaint, first line only: `-L` naming a definition the file no
86
+ // longer has says so in one line, and the rest is a usage note.
87
+ let why = (err, fallback)=>err.trim().split('\n').find(Boolean) ?? fallback;
88
+ /**
89
+ * Derive how one citation stands. `cite` is the edge bundle, `to` the bundle
90
+ * it points at, and `file` the file of a repository it is checked against in
91
+ * Git ({@link tracked}), absent for a citation of content. For one whose lines
92
+ * a later commit touched,
93
+ * `status(cite, place, { checkout: { cwd: '/home/me/project', repository }, vocab }, file)`
94
+ * answers `{ state: 'moved', changes: ['b8b0f89'] }`.
95
+ */ export let status = async (cite, to, ops, file)=>{
96
+ let mark = comp(cite, VERIFIED);
97
+ if (!mark) return {
98
+ state: 'unverified'
99
+ };
100
+ if (!file && comp(to, SYMBOL)) {
101
+ return {
102
+ state: 'unknown',
103
+ why: 'the cited symbol has no file to check'
104
+ };
105
+ }
106
+ if (!file) return entityStatus(cite, to, ops.vocab);
107
+ let at = ops.checkout;
108
+ if (!at) {
109
+ return {
110
+ state: 'unknown',
111
+ why: 'this citation names a file, and no checkout was given'
112
+ };
113
+ }
114
+ if (text(comp(file, FILE)?.root) != at.repository) {
115
+ return {
116
+ state: 'unknown',
117
+ why: 'the cited file is in another repository than this checkout'
118
+ };
119
+ }
120
+ let path = text(comp(file, FILE)?.path);
121
+ let commit = text(comp(cite, REVISION)?.commit);
122
+ if (!commit) {
123
+ return {
124
+ state: 'unknown',
125
+ why: 'verified against no commit'
126
+ };
127
+ }
128
+ let ask = ops.run ?? git;
129
+ let known = await ask([
130
+ 'cat-file',
131
+ '-e',
132
+ `${commit}^{commit}`
133
+ ], at.cwd);
134
+ if (!known.ok) {
135
+ return {
136
+ state: 'unknown',
137
+ why: `commit ${short(commit)} is not in this checkout`
138
+ };
139
+ }
140
+ // Two questions, coarse first: did anything touch the FILE, and only then
141
+ // did anything touch the place in it. The order is not an optimization —
142
+ // `git log -L` refuses an empty revision range ("No commit specified?"), and
143
+ // a citation verified at HEAD has exactly that range, so asking `-L` first
144
+ // would make every freshly verified citation read unknown.
145
+ let touched = await ask([
146
+ 'log',
147
+ '--format=%h',
148
+ `${commit}..HEAD`,
149
+ '--',
150
+ path
151
+ ], at.cwd);
152
+ if (!touched.ok) {
153
+ return {
154
+ state: 'unknown',
155
+ why: why(touched.err, 'git log failed')
156
+ };
157
+ }
158
+ let commits = lines(touched.out);
159
+ if (!commits.length) return {
160
+ state: 'current'
161
+ };
162
+ let narrow = place(to, path);
163
+ if (!narrow.length) return {
164
+ state: 'moved',
165
+ changes: commits
166
+ };
167
+ // `-L` takes the path itself and refuses a pathspec beside it. A path that
168
+ // is gone at HEAD makes it fail, which is unknown rather than current: a
169
+ // deleted or renamed file is precisely what nobody can vouch for.
170
+ let log = await ask([
171
+ 'log',
172
+ '-s',
173
+ '--format=%h',
174
+ ...narrow,
175
+ `${commit}..HEAD`
176
+ ], at.cwd);
177
+ if (!log.ok) return {
178
+ state: 'unknown',
179
+ why: why(log.err, 'git log failed')
180
+ };
181
+ let changes = lines(log.out);
182
+ return changes.length ? {
183
+ state: 'moved',
184
+ changes
185
+ } : {
186
+ state: 'current'
187
+ };
188
+ };
189
+ //# sourceMappingURL=cites.js.map
package/cites.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cites.js","sources":["./cites.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,+EAA+E;AAC/E,8EAA8E;AAC9E,8EAA8E;AAC9E,+EAA+E;AAC/E,4EAA4E;AAC5E,sDAAsD;AACtD,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,mEAAmE;AACnE,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;AAC9E,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,6CAA6C;AAC7C,EAAE;AACF,uEAAuE;AACvE,6EAA6E;AAC7E,iCAAiC;AACjC,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,0EAA0E;AAC1E,qBAAqB;AAGrB,SAAS,KAAK,EAAe,UAAU,YAAY,4BAAiC;AAEpF,SAAmB,OAAO,GAAG,oBAAmB;AAEhD,SAAS,KAAK,GAAE;AAEhB;;UAEU,GACV,OAAO,IAAI,OAAO,OAAM;AAExB;uCACuC,GACvC,OAAO,IAAI,QAAQ,QAAO;AAE1B,sEAAsE,GACtE,OAAO,IAAI,aAAa,aAAY;AAEpC,yEAAyE,GACzE,OAAO,IAAI,WAAW,WAAU;AAEhC;8BAC8B,GAC9B,OAAO,IAAI,SAAS,SAAQ;AAE5B;uEACuE,GACvE,OAAO,IAAI,WAAW,WAAU;AAmBhC,IAAI,OAAO,CAAC,GAAuB,OACjC,GAAG,CAAC,KAAK;AACX,IAAI,OAAO,CAAC,IAAuB,OAAO,KAAK,WAAW,EAAE,IAAI,KAAK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AE,OAAO;IAAE,OAAO;EAAU;EAC/C,IAAI,SAAS,MAAM,IAAI;EACvB,IAAI,CAAC,OAAO,MAAM,EAAE,OAAO;IAAE,OAAO;IAAS,SAAS;EAAQ;EAC9D,2EAA2E;EAC3E,yEAAyE;EACzE,kEAAkE;EAClE,IAAI,MAAM,MAAM,IACd;IAAC;IAAO;IAAM;OAAkB;IAAQ,GAAG,OAAO,MAAM,CAAC;GAAC,EAC1D,GAAG,GAAG;EAER,IAAI,CAAC,IAAI,EAAE,EAAE,OAAO;IAAE,OAAO;IAAW,KAAK,IAAI,IAAI,GAAG,EAAE;EAAkB;EAC5E,IAAI,UAAU,MAAM,IAAI,GAAG;EAC3B,OAAO,QAAQ,MAAM,GAAG;IAAE,OAAO;IAAS;EAAQ,IAAI;IAAE,OAAO;EAAU;AAC3E,EAAC"}
package/cites.ts ADDED
@@ -0,0 +1,206 @@
1
+ // How a citation stands right now, derived and never stored.
2
+ //
3
+ // A citation is an edge — `A cites B` — carrying the commit it was last checked
4
+ // against (`revision{commit}`) and the `verified` mark somebody wrote when they
5
+ // checked it. What B is names the place: a @yaks/file `file` for a whole file,
6
+ // an entity wearing `lines{file, start, end}` for some lines of one (a place,
7
+ // holding the text the citer quoted as `content.body`), a @yaks/code `symbol`
8
+ // for a definition, whose file is its module, or any entity at all. Whether it
9
+ // is still true is not a property: it is re-derived here, so a document can
10
+ // never claim a freshness the repository contradicts.
11
+ //
12
+ // For a file of a repository, the question is Git's, asked in a checkout of
13
+ // that repository: which commits after `revision.commit` touched the place the
14
+ // citation names. `git log <commit>..HEAD` answers it, narrowed by
15
+ // `-L :<symbol>:<path>` or `-L <start>,<end>:<path>` when the citation named a
16
+ // place, so a commit elsewhere in the same file is not reported. The commit is
17
+ // checked with `cat-file` first, because a commit this checkout does not have
18
+ // (rebased away, or from another clone) makes `log` fail the same way an empty
19
+ // range succeeds-empty would look, and that must read as unknown rather than
20
+ // current: a citation that reads fresh on an answer nothing could establish is
21
+ // worse than one that admits it cannot tell.
22
+ //
23
+ // For anything else, a file on a volume and the lines of one included,
24
+ // @yaks/kernel compares the content hash kept when the citation was verified
25
+ // with the entity's content now.
26
+ //
27
+ // Nothing here writes: `cites verify` (./tools.ts) is the only thing that
28
+ // writes the mark. It runs `git` as a subprocess, so like ./host.ts and
29
+ // ./land.ts it stays out of ./mod.ts, which type-checks with only the web
30
+ // platform in scope.
31
+
32
+ import type { Bundle, Comp, Eid } from 'jsr:@yaks/graph@0.2.36'
33
+ import { CITES, type Status, status as entityStatus } from '@yaks/kernel'
34
+ import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
35
+ import { type Run, run as git } from './land.js'
36
+
37
+ export { CITES }
38
+
39
+ /** @yaks/file's component naming a file, a path in a root. (./tree.ts `FILE`
40
+ * is a tree entry's mode, a different thing, which is why these names live
41
+ * here.) */
42
+ export let FILE = 'file'
43
+
44
+ /** @yaks/file's component naming the lines of a file an entity sits at, which
45
+ * a citation of some lines points at. */
46
+ export let LINES = 'lines'
47
+
48
+ /** The component a file's root wears when Git answers for its files. */
49
+ export let REPOSITORY = 'repository'
50
+
51
+ /** The component naming the commit a citation was last checked against. */
52
+ export let REVISION = 'revision'
53
+
54
+ /** @yaks/code's component for an exported definition, named here because a
55
+ * citation may point at one. */
56
+ export let SYMBOL = 'symbol'
57
+
58
+ /** @yaks/kernel's mark, named here because a citation carries one. Only the
59
+ * act of checking writes it, so its absence means nobody has checked. */
60
+ export let VERIFIED = 'verified'
61
+
62
+ /**
63
+ * Where a citation stands. For a file, `changes` names the commits that
64
+ * touched the cited place.
65
+ */
66
+ export type { Status }
67
+
68
+ /** A checkout to ask Git in: its top directory, and the repository it is a
69
+ * checkout of. A file is checked only in a checkout of its own root. */
70
+ export type Checkout = { cwd: string; repository: Eid }
71
+
72
+ /** The checkout for files, and the vocabulary for graph entities. */
73
+ export type Ops = {
74
+ checkout?: Checkout
75
+ run?: Run
76
+ vocab: Vocab
77
+ }
78
+
79
+ let comp = (b: Bundle | undefined, name: string) =>
80
+ b?.[name] as Comp | undefined
81
+ let text = (v: unknown): string => typeof v == 'string' ? v.trim() : ''
82
+ let count = (v: unknown): number | undefined =>
83
+ typeof v == 'number' && Number.isFinite(v) ? v : undefined
84
+
85
+ /// within({ entity: { eid: 's' }, symbol: { module: 'f' } }) -> 'f'
86
+ /// within({ entity: { eid: 'p' }, lines: { file: 'f', start: 3 } }) -> 'f'
87
+ /// within({ entity: { eid: 'f' }, file: { path: 'a.ts' } }) -> undefined
88
+ /** The file a cited symbol or place is in, by id: a symbol's module, a place's
89
+ * file. Nothing for a file itself, or for anything that sits in no file. */
90
+ export let within = (to: Bundle): Eid | undefined =>
91
+ text(comp(to, SYMBOL)?.module) || text(comp(to, LINES)?.file) || undefined
92
+
93
+ /**
94
+ * The file of a repository a citation of `to` is checked against in Git: `to`
95
+ * itself when it is one, the module a symbol is in, or the file a place is in.
96
+ * Nothing when that file is not in a repository (a file on a volume, the lines
97
+ * of a transcript) or `to` is in no file at all: a citation of those holds to
98
+ * the cited content. `get` answers the file and its root by id.
99
+ */
100
+ export let tracked = (
101
+ to: Bundle,
102
+ get: (eid: Eid) => Bundle | undefined,
103
+ ): Bundle | undefined => {
104
+ let ref = within(to)
105
+ let file = ref ? get(ref) : to
106
+ let at = comp(file, FILE)
107
+ return text(at?.path) && get(text(at?.root))?.[REPOSITORY] ? file : undefined
108
+ }
109
+
110
+ // The `-L` arguments narrowing the log to the place a citation names: the
111
+ // definition by name, else the lines, else nothing and the whole file is the
112
+ // place. A symbol is preferred over a range because it survives the file
113
+ // moving around it, which is the whole reason Git has the form.
114
+ let place = (to: Bundle, path: string): string[] => {
115
+ let name = text(comp(to, SYMBOL)?.name)
116
+ if (name) return ['-L', `:${name}:${path}`]
117
+ let lines = comp(to, LINES)
118
+ let start = count(lines?.start)
119
+ if (start == null) return []
120
+ return ['-L', `${start},${count(lines?.end) ?? start}:${path}`]
121
+ }
122
+
123
+ let short = (commit: string) => commit.slice(0, 8)
124
+
125
+ let lines = (out: string) =>
126
+ out.split('\n').map((l) => l.trim()).filter(Boolean)
127
+
128
+ // Git's complaint, first line only: `-L` naming a definition the file no
129
+ // longer has says so in one line, and the rest is a usage note.
130
+ let why = (err: string, fallback: string) =>
131
+ err.trim().split('\n').find(Boolean) ?? fallback
132
+
133
+ /**
134
+ * Derive how one citation stands. `cite` is the edge bundle, `to` the bundle
135
+ * it points at, and `file` the file of a repository it is checked against in
136
+ * Git ({@link tracked}), absent for a citation of content. For one whose lines
137
+ * a later commit touched,
138
+ * `status(cite, place, { checkout: { cwd: '/home/me/project', repository }, vocab }, file)`
139
+ * answers `{ state: 'moved', changes: ['b8b0f89'] }`.
140
+ */
141
+ export let status = async (
142
+ cite: Bundle,
143
+ to: Bundle,
144
+ ops: Ops,
145
+ file?: Bundle,
146
+ ): Promise<Status> => {
147
+ let mark = comp(cite, VERIFIED)
148
+ if (!mark) return { state: 'unverified' }
149
+ if (!file && comp(to, SYMBOL)) {
150
+ return { state: 'unknown', why: 'the cited symbol has no file to check' }
151
+ }
152
+ if (!file) return entityStatus(cite, to, ops.vocab)
153
+ let at = ops.checkout
154
+ if (!at) {
155
+ return {
156
+ state: 'unknown',
157
+ why: 'this citation names a file, and no checkout was given',
158
+ }
159
+ }
160
+ if (text(comp(file, FILE)?.root) != at.repository) {
161
+ return {
162
+ state: 'unknown',
163
+ why: 'the cited file is in another repository than this checkout',
164
+ }
165
+ }
166
+ let path = text(comp(file, FILE)?.path)
167
+
168
+ let commit = text(comp(cite, REVISION)?.commit)
169
+ if (!commit) {
170
+ return { state: 'unknown', why: 'verified against no commit' }
171
+ }
172
+ let ask = ops.run ?? git
173
+ let known = await ask(['cat-file', '-e', `${commit}^{commit}`], at.cwd)
174
+ if (!known.ok) {
175
+ return {
176
+ state: 'unknown',
177
+ why: `commit ${short(commit)} is not in this checkout`,
178
+ }
179
+ }
180
+ // Two questions, coarse first: did anything touch the FILE, and only then
181
+ // did anything touch the place in it. The order is not an optimization —
182
+ // `git log -L` refuses an empty revision range ("No commit specified?"), and
183
+ // a citation verified at HEAD has exactly that range, so asking `-L` first
184
+ // would make every freshly verified citation read unknown.
185
+ let touched = await ask(
186
+ ['log', '--format=%h', `${commit}..HEAD`, '--', path],
187
+ at.cwd,
188
+ )
189
+ if (!touched.ok) {
190
+ return { state: 'unknown', why: why(touched.err, 'git log failed') }
191
+ }
192
+ let commits = lines(touched.out)
193
+ if (!commits.length) return { state: 'current' }
194
+ let narrow = place(to, path)
195
+ if (!narrow.length) return { state: 'moved', changes: commits }
196
+ // `-L` takes the path itself and refuses a pathspec beside it. A path that
197
+ // is gone at HEAD makes it fail, which is unknown rather than current: a
198
+ // deleted or renamed file is precisely what nobody can vouch for.
199
+ let log = await ask(
200
+ ['log', '-s', '--format=%h', ...narrow, `${commit}..HEAD`],
201
+ at.cwd,
202
+ )
203
+ if (!log.ok) return { state: 'unknown', why: why(log.err, 'git log failed') }
204
+ let changes = lines(log.out)
205
+ return changes.length ? { state: 'moved', changes } : { state: 'current' }
206
+ }