@scolladon/tsgit 2.0.1 → 3.1.0

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 (154) hide show
  1. package/README.md +14 -2
  2. package/dist/cjs/adapters/browser/index.cjs +1 -2
  3. package/dist/cjs/adapters/memory/index.cjs +1 -2
  4. package/dist/cjs/adapters/node/index.cjs +1 -2
  5. package/dist/cjs/chunks/adapter-detect-DW9fsw9d.cjs +1 -0
  6. package/dist/cjs/chunks/browser-http-transport-DGwW5YL7.cjs +1 -0
  7. package/dist/cjs/chunks/context-BcoAzPuU.cjs +0 -1
  8. package/dist/cjs/chunks/error-CfLWDui_.cjs +1 -0
  9. package/dist/cjs/chunks/index-Cy44GVR6.cjs +1 -0
  10. package/dist/cjs/chunks/inflate-CmCtM4-w.cjs +1 -0
  11. package/dist/cjs/chunks/lru-cache-1OU7JhD8.cjs +0 -1
  12. package/dist/cjs/chunks/memory-http-transport-CGriODcQ.cjs +1 -0
  13. package/dist/cjs/chunks/node-ssh-transport-PFu3ijfp.cjs +1 -0
  14. package/dist/cjs/chunks/{progress-CxU62NC1.cjs → progress-D8Dqbftk.cjs} +1 -2
  15. package/dist/cjs/chunks/readable-stream-MTA6D0Zh.cjs +0 -1
  16. package/dist/cjs/chunks/repository-Ci-BBxk0.cjs +1 -0
  17. package/dist/cjs/chunks/write-sparse-checkout-C1dsHCAD.cjs +1 -0
  18. package/dist/cjs/commands/index.cjs +1 -2
  19. package/dist/cjs/index.browser.cjs +1 -2
  20. package/dist/cjs/index.cjs +1 -2
  21. package/dist/cjs/index.default.cjs +1 -2
  22. package/dist/cjs/index.node.cjs +1 -2
  23. package/dist/cjs/operators/index.cjs +0 -1
  24. package/dist/cjs/primitives/index.cjs +1 -2
  25. package/dist/cjs/transport/index.cjs +0 -1
  26. package/dist/esm/adapters/browser/index.js +1 -2
  27. package/dist/esm/adapters/memory/index.js +1 -2
  28. package/dist/esm/adapters/node/index.js +1 -2
  29. package/dist/esm/chunks/adapter-detect-BkCMnjrI.js +1 -0
  30. package/dist/esm/chunks/browser-http-transport-CSxAte5h.js +1 -0
  31. package/dist/esm/chunks/context-CumKOV7K.js +0 -1
  32. package/dist/esm/chunks/error-BotOd-nD.js +1 -0
  33. package/dist/esm/chunks/index-DsvINN8n.js +1 -0
  34. package/dist/esm/chunks/inflate-BCIXqeeE.js +1 -0
  35. package/dist/esm/chunks/lru-cache-Cy7C7Lx2.js +0 -1
  36. package/dist/esm/chunks/memory-http-transport-caqmMGR1.js +1 -0
  37. package/dist/esm/chunks/node-ssh-transport-BgSv2IhT.js +1 -0
  38. package/dist/esm/chunks/{progress-BZobfl7p.js → progress-B_AJnOHx.js} +1 -2
  39. package/dist/esm/chunks/readable-stream-CGuf8k1J.js +0 -1
  40. package/dist/esm/chunks/repository-DyxknzvE.js +1 -0
  41. package/dist/esm/chunks/write-sparse-checkout-BwHbNKNS.js +1 -0
  42. package/dist/esm/commands/index.js +1 -2
  43. package/dist/esm/index.browser.js +1 -2
  44. package/dist/esm/index.default.js +1 -2
  45. package/dist/esm/index.js +1 -2
  46. package/dist/esm/index.node.js +1 -2
  47. package/dist/esm/operators/index.js +0 -1
  48. package/dist/esm/primitives/index.js +1 -2
  49. package/dist/esm/transport/index.js +0 -1
  50. package/dist/types/adapters/browser/index.d.cts +5 -3
  51. package/dist/types/adapters/browser/index.d.ts +5 -3
  52. package/dist/types/adapters/memory/index.d.cts +31 -4
  53. package/dist/types/adapters/memory/index.d.ts +31 -4
  54. package/dist/types/adapters/node/index.d.cts +146 -40
  55. package/dist/types/adapters/node/index.d.ts +146 -40
  56. package/dist/types/chunks/{context-YDw6qicq.d.cts → context-CF1YF2S8.d.cts} +165 -6
  57. package/dist/types/chunks/{context-CCL0_F8R.d.ts → context-sIhhtk2u.d.ts} +165 -6
  58. package/dist/types/chunks/{http-transport--_NdQOiw.d.cts → http-transport-DirKfK2S.d.cts} +1 -1
  59. package/dist/types/chunks/{http-transport--_NdQOiw.d.ts → http-transport-DirKfK2S.d.ts} +1 -1
  60. package/dist/types/chunks/index-B5Dps3fg.d.ts +2468 -0
  61. package/dist/types/chunks/index-B_A8VLaf.d.ts +1221 -0
  62. package/dist/types/chunks/index-Dfh8cvEs.d.cts +2468 -0
  63. package/dist/types/chunks/index-Dqxddhav.d.cts +1221 -0
  64. package/dist/types/chunks/progress-BjAKfkam.d.ts +1217 -0
  65. package/dist/types/chunks/progress-Ldnfb8st.d.cts +1217 -0
  66. package/dist/types/chunks/reflog-entry-Cqh3QrPH.d.ts +697 -0
  67. package/dist/types/chunks/reflog-entry-Dy-O27Dd.d.cts +697 -0
  68. package/dist/types/chunks/{repository-FoS_Laoy.d.ts → repository-D8QBTkEz.d.ts} +58 -20
  69. package/dist/types/chunks/{repository-BeifCqp0.d.cts → repository-D9YrVhcH.d.cts} +58 -20
  70. package/dist/types/commands/index.d.cts +4 -1259
  71. package/dist/types/commands/index.d.ts +4 -1259
  72. package/dist/types/index.browser.d.cts +7 -8
  73. package/dist/types/index.browser.d.ts +7 -8
  74. package/dist/types/index.d.cts +61 -124
  75. package/dist/types/index.d.ts +61 -124
  76. package/dist/types/index.default.d.cts +7 -8
  77. package/dist/types/index.default.d.ts +7 -8
  78. package/dist/types/index.node.d.cts +7 -8
  79. package/dist/types/index.node.d.ts +7 -8
  80. package/dist/types/primitives/index.d.cts +4 -692
  81. package/dist/types/primitives/index.d.ts +4 -692
  82. package/dist/types/transport/index.d.cts +1 -1
  83. package/dist/types/transport/index.d.ts +1 -1
  84. package/package.json +94 -28
  85. package/dist/cjs/adapters/browser/index.cjs.map +0 -1
  86. package/dist/cjs/adapters/memory/index.cjs.map +0 -1
  87. package/dist/cjs/adapters/node/index.cjs.map +0 -1
  88. package/dist/cjs/chunks/adapter-detect-CD_LcgaH.cjs +0 -2
  89. package/dist/cjs/chunks/adapter-detect-CD_LcgaH.cjs.map +0 -1
  90. package/dist/cjs/chunks/browser-http-transport-CiMRqtDS.cjs +0 -2
  91. package/dist/cjs/chunks/browser-http-transport-CiMRqtDS.cjs.map +0 -1
  92. package/dist/cjs/chunks/context-BcoAzPuU.cjs.map +0 -1
  93. package/dist/cjs/chunks/error-CfjFO3x_.cjs +0 -2
  94. package/dist/cjs/chunks/error-CfjFO3x_.cjs.map +0 -1
  95. package/dist/cjs/chunks/index-BWCq_5BJ.cjs +0 -2
  96. package/dist/cjs/chunks/index-BWCq_5BJ.cjs.map +0 -1
  97. package/dist/cjs/chunks/lru-cache-1OU7JhD8.cjs.map +0 -1
  98. package/dist/cjs/chunks/memory-http-transport-BVL6VgB-.cjs +0 -2
  99. package/dist/cjs/chunks/memory-http-transport-BVL6VgB-.cjs.map +0 -1
  100. package/dist/cjs/chunks/node-http-transport-BvfVcf02.cjs +0 -2
  101. package/dist/cjs/chunks/node-http-transport-BvfVcf02.cjs.map +0 -1
  102. package/dist/cjs/chunks/progress-CxU62NC1.cjs.map +0 -1
  103. package/dist/cjs/chunks/readable-stream-MTA6D0Zh.cjs.map +0 -1
  104. package/dist/cjs/chunks/repository-BEg2zNtx.cjs +0 -2
  105. package/dist/cjs/chunks/repository-BEg2zNtx.cjs.map +0 -1
  106. package/dist/cjs/chunks/walk-submodules-D2Sp7JEB.cjs +0 -2
  107. package/dist/cjs/chunks/walk-submodules-D2Sp7JEB.cjs.map +0 -1
  108. package/dist/cjs/commands/index.cjs.map +0 -1
  109. package/dist/cjs/index.browser.cjs.map +0 -1
  110. package/dist/cjs/index.cjs.map +0 -1
  111. package/dist/cjs/index.default.cjs.map +0 -1
  112. package/dist/cjs/index.node.cjs.map +0 -1
  113. package/dist/cjs/operators/index.cjs.map +0 -1
  114. package/dist/cjs/primitives/index.cjs.map +0 -1
  115. package/dist/cjs/transport/index.cjs.map +0 -1
  116. package/dist/esm/adapters/browser/index.js.map +0 -1
  117. package/dist/esm/adapters/memory/index.js.map +0 -1
  118. package/dist/esm/adapters/node/index.js.map +0 -1
  119. package/dist/esm/chunks/adapter-detect-DkZhhUhd.js +0 -2
  120. package/dist/esm/chunks/adapter-detect-DkZhhUhd.js.map +0 -1
  121. package/dist/esm/chunks/browser-http-transport-4rJkHcQu.js +0 -2
  122. package/dist/esm/chunks/browser-http-transport-4rJkHcQu.js.map +0 -1
  123. package/dist/esm/chunks/context-CumKOV7K.js.map +0 -1
  124. package/dist/esm/chunks/error-Dc-SRSJK.js +0 -2
  125. package/dist/esm/chunks/error-Dc-SRSJK.js.map +0 -1
  126. package/dist/esm/chunks/index-jH0UMhh-.js +0 -2
  127. package/dist/esm/chunks/index-jH0UMhh-.js.map +0 -1
  128. package/dist/esm/chunks/lru-cache-Cy7C7Lx2.js.map +0 -1
  129. package/dist/esm/chunks/memory-http-transport-CA1WxWBp.js +0 -2
  130. package/dist/esm/chunks/memory-http-transport-CA1WxWBp.js.map +0 -1
  131. package/dist/esm/chunks/node-http-transport-DPa2lK3T.js +0 -2
  132. package/dist/esm/chunks/node-http-transport-DPa2lK3T.js.map +0 -1
  133. package/dist/esm/chunks/progress-BZobfl7p.js.map +0 -1
  134. package/dist/esm/chunks/readable-stream-CGuf8k1J.js.map +0 -1
  135. package/dist/esm/chunks/repository-DF6ePd1x.js +0 -2
  136. package/dist/esm/chunks/repository-DF6ePd1x.js.map +0 -1
  137. package/dist/esm/chunks/walk-submodules-Dq9oGwP8.js +0 -2
  138. package/dist/esm/chunks/walk-submodules-Dq9oGwP8.js.map +0 -1
  139. package/dist/esm/commands/index.js.map +0 -1
  140. package/dist/esm/index.browser.js.map +0 -1
  141. package/dist/esm/index.default.js.map +0 -1
  142. package/dist/esm/index.js.map +0 -1
  143. package/dist/esm/index.node.js.map +0 -1
  144. package/dist/esm/operators/index.js.map +0 -1
  145. package/dist/esm/primitives/index.js.map +0 -1
  146. package/dist/esm/transport/index.js.map +0 -1
  147. package/dist/types/chunks/index-entry-DtEbVpOG.d.cts +0 -47
  148. package/dist/types/chunks/index-entry-UD4dvtKh.d.ts +0 -47
  149. package/dist/types/chunks/progress-7KKiXXfX.d.ts +0 -405
  150. package/dist/types/chunks/progress-By8yFaUE.d.cts +0 -405
  151. package/dist/types/chunks/reflog-entry-BbNnXCTC.d.cts +0 -368
  152. package/dist/types/chunks/reflog-entry-CSzjnZd4.d.ts +0 -368
  153. package/dist/types/chunks/write-tree-C3oNxOlX.d.cts +0 -196
  154. package/dist/types/chunks/write-tree-DRI-LzSr.d.ts +0 -196
@@ -0,0 +1,697 @@
1
+ import { O as ObjectId, H as HashConfig, F as FilePath, R as RefName, f as FileStat } from './context-CF1YF2S8.cjs';
2
+
3
+ /**
4
+ * A validated git-config key. Branded to prevent string-typed callers from
5
+ * passing a raw, unvalidated string into config primitives. Construct via
6
+ * `parseConfigKey` only.
7
+ */
8
+ type ConfigKey = string & {
9
+ readonly __brand: 'ConfigKey';
10
+ };
11
+ /**
12
+ * The four canonical git-config scopes. Order in the union is also the read
13
+ * precedence (lowest precedence first): system → global → local → worktree.
14
+ */
15
+ type ConfigScope = 'system' | 'global' | 'local' | 'worktree';
16
+
17
+ declare const FILE_MODE: {
18
+ readonly REGULAR: "100644";
19
+ readonly EXECUTABLE: "100755";
20
+ readonly SYMLINK: "120000";
21
+ readonly DIRECTORY: "40000";
22
+ readonly GITLINK: "160000";
23
+ };
24
+ type FileMode = (typeof FILE_MODE)[keyof typeof FILE_MODE];
25
+ declare function validateFileMode(mode: string): FileMode;
26
+ declare function normalizeFileMode(mode: string): FileMode;
27
+ declare function isDirectory(mode: FileMode): boolean;
28
+ /**
29
+ * Derive a working-tree file's git mode from its `lstat`. A symbolic link is
30
+ * `120000` regardless of its permission bits; a regular file is `100755` when
31
+ * any of the `0o111` execute bits is set, else `100644`. This is the single
32
+ * definition staging and the working-tree comparison both use, so an added file
33
+ * and a later modified-check agree on the mode.
34
+ */
35
+ declare function deriveWorkingMode(stat: {
36
+ readonly isSymbolicLink: boolean;
37
+ readonly mode: number;
38
+ }): FileMode;
39
+
40
+ interface AuthorIdentity {
41
+ readonly name: string;
42
+ readonly email: string;
43
+ readonly timestamp: number;
44
+ readonly timezoneOffset: string;
45
+ }
46
+ declare function parseIdentity(line: string): AuthorIdentity;
47
+ declare function serializeIdentity(identity: AuthorIdentity): string;
48
+
49
+ interface Blob {
50
+ readonly type: 'blob';
51
+ readonly id: ObjectId;
52
+ readonly content: Uint8Array;
53
+ }
54
+ declare function parseBlobContent(id: ObjectId, content: Uint8Array): Blob;
55
+ declare function serializeBlobContent(blob: Blob): Uint8Array;
56
+
57
+ /**
58
+ * Commit serializer. Produces the canonical Git commit-object payload
59
+ * (`tree <sha>\nparent <sha>*\nauthor …\ncommitter …\n\n<message>`) that
60
+ * sits inside a loose commit object. SHA equality is the contract;
61
+ * disk-bytes vary by zlib compression level (loose object caveat).
62
+ *
63
+ * @writes
64
+ * surface: commit
65
+ * kind: equivalent-under-readback
66
+ * format: git-commit-object
67
+ */
68
+
69
+ interface ExtraHeader {
70
+ readonly key: string;
71
+ readonly value: string;
72
+ }
73
+ interface CommitData {
74
+ readonly tree: ObjectId;
75
+ readonly parents: ReadonlyArray<ObjectId>;
76
+ readonly author: AuthorIdentity;
77
+ readonly committer: AuthorIdentity;
78
+ readonly message: string;
79
+ readonly gpgSignature?: string;
80
+ readonly extraHeaders: ReadonlyArray<ExtraHeader>;
81
+ }
82
+ interface Commit {
83
+ readonly type: 'commit';
84
+ readonly id: ObjectId;
85
+ readonly data: CommitData;
86
+ }
87
+ declare function parseCommitContent(id: ObjectId, content: Uint8Array): Commit;
88
+ declare function serializeCommitContent(commit: Commit): Uint8Array;
89
+
90
+ type ObjectType = 'blob' | 'tree' | 'commit' | 'tag';
91
+ declare function parseHeader(rawBytes: Uint8Array): {
92
+ readonly type: ObjectType;
93
+ readonly size: number;
94
+ readonly contentOffset: number;
95
+ };
96
+ declare function serializeHeader(type: ObjectType, contentSize: number): Uint8Array;
97
+
98
+ /**
99
+ * Tag serializer. Produces the canonical annotated-tag payload
100
+ * (`object <sha>\ntype <type>\ntag <name>\ntagger …\n\n<message>`) inside a
101
+ * loose tag object.
102
+ *
103
+ * @writes
104
+ * surface: tag
105
+ * kind: equivalent-under-readback
106
+ * format: git-tag-object
107
+ */
108
+
109
+ interface TagData {
110
+ readonly object: ObjectId;
111
+ readonly objectType: ObjectType;
112
+ readonly tagName: string;
113
+ readonly tagger?: AuthorIdentity;
114
+ readonly message: string;
115
+ readonly gpgSignature?: string;
116
+ readonly extraHeaders: ReadonlyArray<ExtraHeader>;
117
+ }
118
+ interface Tag {
119
+ readonly type: 'tag';
120
+ readonly id: ObjectId;
121
+ readonly data: TagData;
122
+ }
123
+ declare function parseTagContent(id: ObjectId, content: Uint8Array): Tag;
124
+ declare function serializeTagContent(tag: Tag): Uint8Array;
125
+
126
+ interface TreeEntry {
127
+ readonly mode: FileMode;
128
+ readonly name: string;
129
+ readonly id: ObjectId;
130
+ }
131
+ interface Tree {
132
+ readonly type: 'tree';
133
+ readonly id: ObjectId;
134
+ readonly entries: ReadonlyArray<TreeEntry>;
135
+ }
136
+ declare function parseTreeContent(id: ObjectId, content: Uint8Array, hash: HashConfig): Tree;
137
+ declare function serializeTreeContent(tree: Tree, hash: HashConfig): Uint8Array;
138
+ declare function sortTreeEntries(entries: ReadonlyArray<TreeEntry>): ReadonlyArray<TreeEntry>;
139
+ declare function treeEntryCompare(a: TreeEntry, b: TreeEntry): number;
140
+
141
+ type GitObject = Blob | Tree | Commit | Tag;
142
+ declare function parseObject(id: ObjectId, rawBytes: Uint8Array, hash: HashConfig): GitObject;
143
+ declare function serializeObject(object: GitObject, hash: HashConfig): Uint8Array;
144
+
145
+ interface IndexEntryFlags {
146
+ readonly assumeValid: boolean;
147
+ readonly stage: 0 | 1 | 2 | 3;
148
+ /** Index v3 extended flag — the path is intentionally absent from the working tree. */
149
+ readonly skipWorktree: boolean;
150
+ /** Index v3 extended flag — `git add -N` placeholder. Modelled for faithful round-tripping. */
151
+ readonly intentToAdd: boolean;
152
+ }
153
+ /** The common case — a freshly staged, materialised, stage-0 entry. */
154
+ declare const STAGE0_FLAGS: IndexEntryFlags;
155
+ interface IndexEntry {
156
+ readonly ctimeSeconds: number;
157
+ readonly ctimeNanoseconds: number;
158
+ readonly mtimeSeconds: number;
159
+ readonly mtimeNanoseconds: number;
160
+ readonly dev: number;
161
+ readonly ino: number;
162
+ readonly mode: FileMode;
163
+ readonly uid: number;
164
+ readonly gid: number;
165
+ readonly fileSize: number;
166
+ readonly id: ObjectId;
167
+ readonly flags: IndexEntryFlags;
168
+ readonly path: FilePath;
169
+ }
170
+ interface IndexExtension {
171
+ readonly signature: string;
172
+ readonly data: Uint8Array;
173
+ }
174
+ interface GitIndex {
175
+ readonly version: 2 | 3;
176
+ readonly entries: ReadonlyArray<IndexEntry>;
177
+ readonly extensions: ReadonlyArray<IndexExtension>;
178
+ /**
179
+ * Trailing hash bytes (SHA-1: 20 bytes, SHA-256: 32 bytes) that close the
180
+ * index file format. Read but historically discarded; surfaced here so
181
+ * `CachingIndexResolver` can use it for the racy-stat fallback path
182
+ * (compare trailing bytes when `(mtime, size, ino)` match an observed
183
+ * stat but the underlying file may have been mutated in the racy-stat
184
+ * window — see design §10.4). Empty (`Uint8Array(0)`) when constructed
185
+ * from the empty-index defaults in `readIndex` (no underlying file).
186
+ */
187
+ readonly trailerSha: Uint8Array;
188
+ }
189
+ interface StatData {
190
+ readonly ctimeSeconds: number;
191
+ readonly ctimeNanoseconds: number;
192
+ readonly mtimeSeconds: number;
193
+ readonly mtimeNanoseconds: number;
194
+ readonly dev: number;
195
+ readonly ino: number;
196
+ readonly mode: FileMode;
197
+ readonly uid: number;
198
+ readonly gid: number;
199
+ readonly fileSize: number;
200
+ }
201
+ declare function isStatClean(entry: IndexEntry, stat: StatData): boolean;
202
+ /**
203
+ * Build a stage-0 index entry for a tree path that is absent from the working
204
+ * tree: every stat field zeroed, the `skipWorktree` flag set. `status` skips
205
+ * skip-worktree entries, so the zeroed stats are never consulted.
206
+ *
207
+ * Shared by the sparse-aware primitives (`materializeTree`,
208
+ * `buildIndexFromTree`) so the synthesised-entry shape lives in one place.
209
+ */
210
+ declare const skipWorktreeEntry: (entry: {
211
+ readonly path: FilePath;
212
+ readonly id: ObjectId;
213
+ readonly mode: FileMode;
214
+ }) => IndexEntry;
215
+
216
+ /**
217
+ * Pure spanhash similarity scorer — git's diffcore-delta.c algorithm.
218
+ * I/O-free; never imports platform adapters.
219
+ *
220
+ * Algorithm (mirrors git's `hash_chars` + `diffcore_count_changes`):
221
+ * 1. Split each blob into chunks delimited by LF or up to 64 bytes, whichever
222
+ * comes first (same rule git applies for text vs binary).
223
+ * 2. Hash each chunk with git's two-accumulator rolling hash and store its byte
224
+ * count in a hash-map keyed by `(accum1 + accum2 * 0x61) % HASHBASE`.
225
+ * 3. For each chunk hash present in BOTH src and dst, count min(src_cnt, dst_cnt)
226
+ * bytes as "copied".
227
+ * 4. score = (src_copied * MAX_SCORE) / max(src_size, dst_size)
228
+ */
229
+ /** Raw score ceiling; mirrors git's MAX_SCORE = 60000. */
230
+ declare const MAX_SCORE = 60000;
231
+ /** Default rename threshold (50% of MAX_SCORE). */
232
+ declare const DEFAULT_RENAME_THRESHOLD = 30000;
233
+ /** Default -B break-attempt gate (50% of MAX_SCORE). */
234
+ declare const DEFAULT_BREAK_SCORE = 30000;
235
+ /** Default -B keep-broken gate (60% of MAX_SCORE). */
236
+ declare const DEFAULT_MERGE_SCORE = 36000;
237
+ /**
238
+ * Structured similarity datum shared by RenameChange, CopyChange, and the
239
+ * broken field on ModifyChange. score is in 0..MAX_SCORE; maxScore is always
240
+ * MAX_SCORE so callers can reconstruct the denominator.
241
+ */
242
+ interface SimilarityScore {
243
+ readonly score: number;
244
+ readonly maxScore: number;
245
+ }
246
+ /**
247
+ * Estimate the similarity between two byte blobs using git's spanhash algorithm.
248
+ * Returns a raw score in 0..MAX_SCORE.
249
+ *
250
+ * Special cases:
251
+ * - Both empty → MAX_SCORE (identical trivially)
252
+ * - Identical content → MAX_SCORE (checked via reference equality for speed)
253
+ * - One empty, other non-empty → 0
254
+ */
255
+ declare function estimateSimilarity(src: Uint8Array, dst: Uint8Array): number;
256
+ /**
257
+ * Project a raw score to an integer percent, truncating (not rounding).
258
+ * Mirrors git's `(int)(score * 100 / MAX_SCORE)`.
259
+ */
260
+ declare function toSimilarityPercent(score: number): number;
261
+
262
+ type DiffChangeType = 'add' | 'delete' | 'modify' | 'rename' | 'type-change' | 'copy';
263
+ interface AddChange {
264
+ readonly type: 'add';
265
+ readonly newPath: FilePath;
266
+ readonly newId: ObjectId;
267
+ readonly newMode: FileMode;
268
+ }
269
+ interface DeleteChange {
270
+ readonly type: 'delete';
271
+ readonly oldPath: FilePath;
272
+ readonly oldId: ObjectId;
273
+ readonly oldMode: FileMode;
274
+ }
275
+ interface ModifyChange {
276
+ readonly type: 'modify';
277
+ readonly path: FilePath;
278
+ readonly oldId: ObjectId;
279
+ readonly newId: ObjectId;
280
+ readonly oldMode: FileMode;
281
+ readonly newMode: FileMode;
282
+ /** Dissimilarity datum when -B kept this modify broken. score = MAX_SCORE − similarity. */
283
+ readonly broken?: SimilarityScore;
284
+ }
285
+ interface RenameChange {
286
+ readonly type: 'rename';
287
+ readonly oldPath: FilePath;
288
+ readonly newPath: FilePath;
289
+ readonly oldId: ObjectId;
290
+ readonly newId: ObjectId;
291
+ readonly oldMode: FileMode;
292
+ readonly newMode: FileMode;
293
+ readonly similarity: SimilarityScore;
294
+ }
295
+ interface TypeChangeChange {
296
+ readonly type: 'type-change';
297
+ readonly path: FilePath;
298
+ readonly oldId: ObjectId;
299
+ readonly newId: ObjectId;
300
+ readonly oldMode: FileMode;
301
+ readonly newMode: FileMode;
302
+ }
303
+ interface CopyChange {
304
+ readonly type: 'copy';
305
+ readonly oldPath: FilePath;
306
+ readonly newPath: FilePath;
307
+ readonly oldId: ObjectId;
308
+ readonly newId: ObjectId;
309
+ readonly oldMode: FileMode;
310
+ readonly newMode: FileMode;
311
+ readonly similarity: SimilarityScore;
312
+ }
313
+ type DiffChange = AddChange | DeleteChange | ModifyChange | RenameChange | TypeChangeChange | CopyChange;
314
+ interface TreeDiff {
315
+ readonly changes: ReadonlyArray<DiffChange>;
316
+ }
317
+
318
+ interface FlatTreeEntry {
319
+ readonly id: ObjectId;
320
+ readonly mode: FileMode;
321
+ }
322
+ interface FlatTree {
323
+ readonly entries: ReadonlyMap<FilePath, FlatTreeEntry>;
324
+ }
325
+ declare const MAX_FLAT_TREE_ENTRIES = 1000000;
326
+
327
+ type WhitespaceMode = 'all' | 'change' | 'at-eol' | 'none';
328
+ interface LineKey {
329
+ readonly mode: WhitespaceMode;
330
+ readonly ignoreCrAtEol: boolean;
331
+ }
332
+ declare function normalizeLine(bytes: Uint8Array, key: LineKey): Uint8Array;
333
+ declare function linesEqualUnder(a: Uint8Array, b: Uint8Array, key: LineKey): boolean;
334
+ declare function resolveLineKey(fields: {
335
+ readonly ignoreWhitespace?: 'all' | 'change' | 'at-eol';
336
+ readonly ignoreCrAtEol?: boolean;
337
+ readonly ignoreBlankLines?: boolean;
338
+ }): LineKey;
339
+ declare function lineKeyIsActive(key: LineKey): boolean;
340
+
341
+ interface RenameDetectOptions {
342
+ readonly limit?: number;
343
+ readonly maxSameIdDeletes?: number;
344
+ readonly threshold?: number;
345
+ readonly copies?: 'off' | 'on' | 'harder';
346
+ /** Per-copy threshold (0..MAX_SCORE). Defaults to `threshold` when absent. */
347
+ readonly copyThreshold?: number;
348
+ /**
349
+ * Break-rewrite detection (-B).
350
+ * score: dissimilarity gate (>= score → attempt break; default DEFAULT_BREAK_SCORE).
351
+ * merge: keep-broken gate (>= merge → emit broken modify; default DEFAULT_MERGE_SCORE).
352
+ * A merge value of 0 maps to DEFAULT_MERGE_SCORE.
353
+ * false (default) → no break detection.
354
+ */
355
+ readonly breakRewrites?: {
356
+ readonly score: number;
357
+ readonly merge: number;
358
+ } | false;
359
+ }
360
+ declare function detectRenames(diff: TreeDiff, options?: RenameDetectOptions): TreeDiff;
361
+
362
+ /**
363
+ * Per-file line counts for one changed path — the data half of git's
364
+ * `--numstat`. `binary` flags a file whose either side trips binary detection
365
+ * (then `added`/`deleted` are zero, matching git's `-`); otherwise the counts
366
+ * come from the line diff. The cosmetic graph (`--stat` widths, `Bin … bytes`)
367
+ * is the caller's to render from these counts plus the blob sizes.
368
+ */
369
+ interface StatFields {
370
+ readonly added: number;
371
+ readonly deleted: number;
372
+ readonly binary: boolean;
373
+ }
374
+ /** A `DiffChange` carrying its per-file line counts (populated via `withStat`). */
375
+ type StatDiffChange = DiffChange & StatFields;
376
+ /** A tree diff whose every change carries `StatFields`. */
377
+ interface StatTreeDiff {
378
+ readonly changes: ReadonlyArray<StatDiffChange>;
379
+ }
380
+ /** Options for `computeStatFields` controlling line normalization and blank suppression. */
381
+ interface StatFieldsOptions {
382
+ readonly lineKey?: LineKey;
383
+ readonly ignoreBlankLines?: boolean;
384
+ /** Override the binary-vs-text decision for the numstat surface. `'binary'` ⇒
385
+ * `{ added: 0, deleted: 0, binary: true }`; `'text'` ⇒ count lines even over NUL;
386
+ * `undefined` ⇒ today's `isBinary` content-sniff. */
387
+ readonly numstatBinaryOverride?: 'binary' | 'text';
388
+ }
389
+ /**
390
+ * Count added/deleted lines between two blob contents. A binary side short-
391
+ * circuits to `{ 0, 0, binary: true }`; otherwise added lines are the
392
+ * theirs-only hunks and deleted lines the ours-only hunks of the line diff
393
+ * (`old` is ours, `next` is theirs).
394
+ *
395
+ * When `options.lineKey` is set the line-equality is whitespace-normalized.
396
+ * When `options.ignoreBlankLines` is true, hunks whose lines are all blank
397
+ * (empty after the active line-key normalization) do not contribute to counts.
398
+ */
399
+ declare const computeStatFields: (old: Uint8Array, next: Uint8Array, options?: StatFieldsOptions) => StatFields;
400
+
401
+ /**
402
+ * Primitive option shapes, walker value types, and shared constants.
403
+ * Defined in one location to avoid circular imports between primitive modules.
404
+ */
405
+
406
+ /** Max symbolic-ref dereferences resolveRef will follow. */
407
+ declare const MAX_SYMBOLIC_REF_DEPTH = 5;
408
+ /** Max tag-peel hops resolveRef / readTree will follow when peeling. */
409
+ declare const MAX_PEEL_DEPTH = 5;
410
+ /** Max seeds walkCommits.from can contain. */
411
+ declare const MAX_WALK_SEEDS = 1024;
412
+ /** Hard cap on walkCommits' pending queue size to prevent unbounded heap growth. */
413
+ declare const MAX_WALK_QUEUE_SIZE: number;
414
+ /** Max.git/index file size readIndex will accept. */
415
+ declare const MAX_INDEX_BYTES: number;
416
+ /** Max commit message byte length createCommit will accept. */
417
+ declare const MAX_COMMIT_MESSAGE_BYTES: number;
418
+ /**
419
+ * Per-file size cap enforced by `add --all` before reading working-tree
420
+ * bytes into memory. Mirrors `MAX_CONFLICT_OUTPUT_BYTES` (256 MiB) so the
421
+ * write-side memory ceiling matches the read-side ceiling.
422
+ * See `docs/adr/032-add-all-large-file-guard.md`.
423
+ */
424
+ declare const MAX_WORKING_TREE_BLOB_BYTES: number;
425
+ /**
426
+ * Per-file cap on `.gitignore`, `.git/info/exclude`, and the global
427
+ * excludesFile. 1 MiB leaves a 20× margin over real-world max-size
428
+ * gitignore corpora. See `docs/adr/036-gitignore-bounded-read.md`.
429
+ */
430
+ declare const MAX_GITIGNORE_BYTES: number;
431
+ /**
432
+ * Per-file cap on `.gitattributes`, `.git/info/attributes`, and the global
433
+ * attributesFile. 1 MiB matches the `.gitignore` cap — both are small text
434
+ * files in practice; the guard only stops a pathological input.
435
+ */
436
+ declare const MAX_GITATTRIBUTES_BYTES: number;
437
+ /**
438
+ * Per-file cap on a single `.git/logs/<ref>` reflog file. 16 MiB is generous
439
+ * — `reflog expire` is the size-management story; this guard only stops an
440
+ * adversarial or corrupt log from being buffered unbounded into memory.
441
+ */
442
+ declare const MAX_REFLOG_BYTES: number;
443
+ interface ReadObjectOptions {
444
+ readonly verifyHash?: boolean;
445
+ /**
446
+ * Reject objects whose serialised payload exceeds this byte count, before
447
+ * inflating the full content into memory. Counts the raw object content
448
+ * (post-inflate, pre-loose-header). When unset, no cap applies.
449
+ *
450
+ * Used by `merge`'s content merger to bound peak memory when an adversarial
451
+ * remote ships pathologically large blobs. See `docs/design/phase-13-8-
452
+ * bounded-object-reads.md`.
453
+ */
454
+ readonly maxBytes?: number;
455
+ }
456
+ interface ResolveRefOptions {
457
+ readonly peel?: boolean;
458
+ readonly maxSymbolicDepth?: number;
459
+ readonly maxPeelDepth?: number;
460
+ }
461
+ /**
462
+ * `updateRef` option shapes. A write requires a `reflogMessage` — git's
463
+ * builtins always supply a reason string; the type checker forces every
464
+ * present and future ref write to state why the ref moved. A delete drops the
465
+ * reflog file, so it carries no message.
466
+ */
467
+ type UpdateRefOptions = {
468
+ readonly delete?: false;
469
+ readonly expected?: ObjectId | 'absent';
470
+ readonly reflogMessage: string;
471
+ } | {
472
+ readonly delete: true;
473
+ readonly expected?: ObjectId | 'absent';
474
+ };
475
+ interface WalkCommitsOptions {
476
+ readonly from: ReadonlyArray<ObjectId>;
477
+ readonly until?: ReadonlyArray<ObjectId>;
478
+ readonly order?: 'topo' | 'first-parent';
479
+ readonly ignoreMissing?: boolean;
480
+ readonly verifyHash?: boolean;
481
+ /**
482
+ * Commits whose parents must NOT be enqueued. Used for shallow boundaries
483
+ * . The commit itself is still yielded — only its parents are
484
+ * skipped. Callers that want to also skip the boundary commit pass it in
485
+ * `until`.
486
+ */
487
+ readonly shallow?: ReadonlySet<ObjectId>;
488
+ }
489
+ /**
490
+ * Options for `walkCommitsByDate` — the all-parents, commit-date-ordered history
491
+ * walk (newest committer-date first, oid-ascending tie-break). Mirrors the
492
+ * boundary/missing/hash knobs of {@link WalkCommitsOptions} but carries no
493
+ * `order`: the date order is the primitive's identity.
494
+ */
495
+ interface WalkCommitsByDateOptions {
496
+ readonly from: ReadonlyArray<ObjectId>;
497
+ readonly until?: ReadonlyArray<ObjectId>;
498
+ /**
499
+ * Commits whose parents must NOT be walked (shallow boundary). The commit
500
+ * itself is still yielded — only its parents are skipped.
501
+ */
502
+ readonly shallow?: ReadonlySet<ObjectId>;
503
+ readonly ignoreMissing?: boolean;
504
+ readonly verifyHash?: boolean;
505
+ }
506
+ /** Maximum `have` lines a single-round fetch will send. */
507
+ declare const MAX_HAVES = 256;
508
+ /** Hard cap on objects enumerated for a single push. design */
509
+ declare const MAX_PUSH_OBJECTS = 1000000;
510
+ interface WalkTreeEntry {
511
+ readonly path: FilePath;
512
+ readonly id: ObjectId;
513
+ readonly mode: FileMode;
514
+ }
515
+ interface WalkTreeOptions {
516
+ readonly recursive?: boolean;
517
+ readonly maxDepth?: number;
518
+ readonly maxEntries?: number;
519
+ }
520
+ interface WalkWorkingTreeEntry {
521
+ readonly path: FilePath;
522
+ readonly stat: FileStat;
523
+ }
524
+ type WalkIgnorePredicate = (path: FilePath, isDirectory: boolean) => boolean | Promise<boolean>;
525
+ interface WalkWorkingTreeOptions {
526
+ readonly maxDepth?: number;
527
+ readonly maxEntries?: number;
528
+ /**
529
+ * predicate. Invoked on every directory BEFORE descent
530
+ * (returning `true` prunes the entire subtree, skipping its `lstat`
531
+ * cost) and on every leaf BEFORE yielding (returning `true` drops
532
+ * the leaf). May be sync or async.
533
+ */
534
+ readonly ignore?: WalkIgnorePredicate;
535
+ }
536
+ interface CreateCommitInput {
537
+ readonly tree: ObjectId;
538
+ readonly parents: ReadonlyArray<ObjectId>;
539
+ readonly author: AuthorIdentity;
540
+ readonly committer: AuthorIdentity;
541
+ readonly message: string;
542
+ readonly gpgSignature?: string;
543
+ readonly extraHeaders?: ReadonlyArray<ExtraHeader>;
544
+ }
545
+ interface CreateTagInput {
546
+ readonly object: ObjectId;
547
+ readonly objectType: ObjectType;
548
+ readonly tagName: string;
549
+ readonly tagger: AuthorIdentity;
550
+ readonly message: string;
551
+ readonly gpgSignature?: string;
552
+ readonly extraHeaders?: ReadonlyArray<ExtraHeader>;
553
+ }
554
+ type DiffTreesInput = Tree | ObjectId | undefined;
555
+ interface DiffTreesOptions {
556
+ readonly detectRenames?: boolean;
557
+ readonly renameOptions?: RenameDetectOptions;
558
+ /**
559
+ * Recurse into sub-directories, surfacing nested blobs as full-path changes
560
+ * (git's recursive diff) instead of one change per top-level sub-tree. Both
561
+ * sides are flattened to full-path blob entries before classification.
562
+ */
563
+ readonly recursive?: boolean;
564
+ /**
565
+ * Attach per-file line counts (`added` / `deleted` / `binary`) to every change
566
+ * — the data half of git's `--numstat`. Off by default: the tree-level diff
567
+ * reads no blob contents; `withStat` opts into the line-level pass (blob loads +
568
+ * line diff), so the result is a `StatTreeDiff`.
569
+ */
570
+ readonly withStat?: boolean;
571
+ /**
572
+ * Whitespace normalization mode applied to line equality during diff. Mirrors
573
+ * git's `-w` (`'all'`), `-b` (`'change'`), and `--ignore-space-at-eol`
574
+ * (`'at-eol'`). Absent means exact byte comparison.
575
+ */
576
+ readonly ignoreWhitespace?: 'all' | 'change' | 'at-eol';
577
+ /**
578
+ * When true, a trailing CR immediately before the line terminator is ignored
579
+ * during line comparison. Mirrors git's `--ignore-cr-at-eol`.
580
+ */
581
+ readonly ignoreCrAtEol?: boolean;
582
+ /**
583
+ * When true, change groups consisting solely of blank lines are omitted from
584
+ * line counts and treated as no-change for the drop pass. Mirrors git's
585
+ * `--ignore-blank-lines`.
586
+ */
587
+ readonly ignoreBlankLines?: boolean;
588
+ }
589
+ /**
590
+ * Per-file cap on a single `.gitmodules` blob. 1 MiB matches the
591
+ * `MAX_GITIGNORE_BYTES` budget: real `.gitmodules` files are KB-scale even in
592
+ * very large superprojects, so a 1 MiB ceiling is a generous DoS guard
593
+ * applied before inflate.
594
+ */
595
+ declare const MAX_GITMODULES_BYTES: number;
596
+ /**
597
+ * Recursion backstop for `walkSubmodules` — the cycle guard (visited gitdir
598
+ * set) handles the genuine-cycle case; this cap stops a pathologically deep
599
+ * but acyclic nest from running away.
600
+ */
601
+ declare const MAX_SUBMODULE_DEPTH = 100;
602
+ /** One submodule surfaced by `walkSubmodules`: a gitlink joined with its `.gitmodules` row. */
603
+ interface SubmoduleEntry {
604
+ /**
605
+ * The `[submodule "<name>"]` subsection name in the `.gitmodules` of the
606
+ * tree that contains this gitlink. Falls back to `path` when no row matches
607
+ * the gitlink (a gitlink committed without a corresponding config entry).
608
+ */
609
+ readonly name: string;
610
+ /** Slash-joined path from the *superproject* root to the gitlink. */
611
+ readonly path: FilePath;
612
+ /** `submodule.<name>.url` — absent when no `.gitmodules` row matched. */
613
+ readonly url?: string;
614
+ /** `submodule.<name>.branch` — absent when the key is unset. */
615
+ readonly branch?: string;
616
+ /** The commit object id the gitlink pins (the tree entry's id). */
617
+ readonly commit: ObjectId;
618
+ /** Recursion depth; 0 for a direct submodule of the superproject. */
619
+ readonly depth: number;
620
+ /** Path of the containing submodule; absent for `depth === 0` entries. */
621
+ readonly parent?: FilePath;
622
+ }
623
+ /**
624
+ * One entry yielded by `catFileBatch` — a discriminated union so that a
625
+ * single bad id never aborts the stream. `ok: true` carries the parsed
626
+ * object plus its canonical payload size (matches the `<size>` field of
627
+ * `git cat-file --batch`'s header). `ok: false` is shaped to extend later:
628
+ * `reason` is a literal union so a future variant is an additive change.
629
+ */
630
+ /**
631
+ * Optional knobs for the `catFileBatch` primitive — currently a single
632
+ * `maxBytes` cap forwarded to each per-id `readObject` call so a long
633
+ * batch over untrusted ids cannot exhaust the heap. Defaults to no cap.
634
+ */
635
+ interface CatFileBatchOptions {
636
+ /**
637
+ * Per-object byte cap. Rejected pre-inflate; same semantics as
638
+ * `ReadObjectOptions.maxBytes`. When unset, no cap applies (parity
639
+ * with `readObject`).
640
+ */
641
+ readonly maxBytes?: number;
642
+ }
643
+ type CatFileBatchEntry = {
644
+ readonly ok: true;
645
+ readonly id: ObjectId;
646
+ readonly type: GitObject['type'];
647
+ readonly size: number;
648
+ readonly object: GitObject;
649
+ } | {
650
+ readonly ok: false;
651
+ readonly id: ObjectId;
652
+ readonly reason: 'missing';
653
+ };
654
+ interface WalkSubmodulesOptions {
655
+ /** Tree-ish to walk. Default: `HEAD`. */
656
+ readonly ref?: RefName | ObjectId;
657
+ /** Descend into nested submodules' own `.gitmodules`. Default: `false`. */
658
+ readonly recursive?: boolean;
659
+ /**
660
+ * Cap on recursion depth. Default: `MAX_SUBMODULE_DEPTH`. Entries at exactly
661
+ * this depth are yielded but not recursed into.
662
+ */
663
+ readonly maxDepth?: number;
664
+ }
665
+
666
+ /**
667
+ * Structured result returned by `bisectMidpoint`.
668
+ *
669
+ * Field semantics are faithful to `git rev-list --bisect-vars`:
670
+ * - `candidateCount` = `bisect_all`
671
+ * - `remainingIfGood` = `bisect_good` = candidateCount − reaches − 1
672
+ * (negative sentinel −1 when candidateCount = 1, meaning "no candidates
673
+ * remain if the midpoint tests good").
674
+ * - `remainingIfBad` = `bisect_bad` = reaches − 1
675
+ * - `remainingSteps` = `bisect_steps` = estimateSteps(candidateCount)
676
+ */
677
+ interface BisectMidpoint {
678
+ readonly nextCommit: ObjectId;
679
+ readonly candidateCount: number;
680
+ /** Candidates still to test if `nextCommit` proves good; −1 when candidateCount = 1. */
681
+ readonly remainingIfGood: number;
682
+ /** Candidates still to test if `nextCommit` proves bad. */
683
+ readonly remainingIfBad: number;
684
+ /** Rough number of test rounds remaining; mirrors `git bisect_steps`. */
685
+ readonly remainingSteps: number;
686
+ }
687
+
688
+ /** One line of a reflog file: a single ref movement from `oldId` to `newId`. */
689
+ interface ReflogEntry {
690
+ readonly oldId: ObjectId;
691
+ readonly newId: ObjectId;
692
+ readonly identity: AuthorIdentity;
693
+ readonly message: string;
694
+ }
695
+
696
+ export { DEFAULT_BREAK_SCORE as D, FILE_MODE as F, MAX_PEEL_DEPTH as H, MAX_PUSH_OBJECTS as J, MAX_REFLOG_BYTES as K, MAX_COMMIT_MESSAGE_BYTES as M, MAX_SCORE as N, MAX_SUBMODULE_DEPTH as O, MAX_SYMBOLIC_REF_DEPTH as P, MAX_WALK_QUEUE_SIZE as Q, MAX_WALK_SEEDS as R, MAX_WORKING_TREE_BLOB_BYTES as S, STAGE0_FLAGS as Z, resolveLineKey as aA, serializeBlobContent as aB, serializeCommitContent as aC, serializeHeader as aD, serializeIdentity as aE, serializeObject as aF, serializeTagContent as aG, serializeTreeContent as aH, skipWorktreeEntry as aI, sortTreeEntries as aJ, toSimilarityPercent as aK, treeEntryCompare as aL, validateFileMode as aM, computeStatFields as aj, deriveWorkingMode as ak, detectRenames as al, estimateSimilarity as am, isDirectory as an, isStatClean as ao, lineKeyIsActive as ap, linesEqualUnder as aq, normalizeFileMode as ar, normalizeLine as as, parseBlobContent as at, parseCommitContent as au, parseHeader as av, parseIdentity as aw, parseObject as ax, parseTagContent as ay, parseTreeContent as az, DEFAULT_MERGE_SCORE as i, DEFAULT_RENAME_THRESHOLD as j, MAX_FLAT_TREE_ENTRIES as u, MAX_GITATTRIBUTES_BYTES as v, MAX_GITIGNORE_BYTES as w, MAX_GITMODULES_BYTES as x, MAX_HAVES as y, MAX_INDEX_BYTES as z };
697
+ export type { StatData as $, AddChange as A, BisectMidpoint as B, CatFileBatchEntry as C, ExtraHeader as E, GitIndex as G, IndexEntryFlags as I, LineKey as L, ModifyChange as T, ObjectType as U, ReadObjectOptions as V, RenameChange as W, RenameDetectOptions as X, ResolveRefOptions as Y, SimilarityScore as _, AuthorIdentity as a, StatDiffChange as a0, StatFields as a1, StatFieldsOptions as a2, StatTreeDiff as a3, SubmoduleEntry as a4, Tag as a5, TagData as a6, Tree as a7, TreeDiff as a8, TypeChangeChange as a9, ConfigScope as aN, IndexEntry as aO, ConfigKey as aP, ReflogEntry as aQ, TreeEntry as aR, WalkIgnorePredicate as aS, UpdateRefOptions as aa, WalkCommitsByDateOptions as ab, WalkCommitsOptions as ac, WalkSubmodulesOptions as ad, WalkTreeEntry as ae, WalkTreeOptions as af, WalkWorkingTreeEntry as ag, WalkWorkingTreeOptions as ah, WhitespaceMode as ai, Blob as b, CatFileBatchOptions as c, Commit as d, CommitData as e, CopyChange as f, CreateCommitInput as g, CreateTagInput as h, DeleteChange as k, DiffChange as l, DiffChangeType as m, DiffTreesInput as n, DiffTreesOptions as o, FileMode as p, FlatTree as q, FlatTreeEntry as r, GitObject as s, IndexExtension as t };