shell-dsl 0.0.34 → 0.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -3
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/fs/memfs-adapter.cjs +56 -2
- package/dist/cjs/src/fs/memfs-adapter.cjs.map +3 -3
- package/dist/cjs/src/fs/real-fs.cjs +134 -3
- package/dist/cjs/src/fs/real-fs.cjs.map +3 -3
- package/dist/cjs/src/fs/special-files.cjs +3 -2
- package/dist/cjs/src/fs/special-files.cjs.map +3 -3
- package/dist/cjs/src/fs/web-fs.cjs +72 -3
- package/dist/cjs/src/fs/web-fs.cjs.map +3 -3
- package/dist/cjs/src/index.cjs.map +2 -2
- package/dist/cjs/src/types.cjs.map +2 -2
- package/dist/cjs/src/vcs/content.cjs +106 -0
- package/dist/cjs/src/vcs/content.cjs.map +10 -0
- package/dist/cjs/src/vcs/diff.cjs +72 -28
- package/dist/cjs/src/vcs/diff.cjs.map +3 -3
- package/dist/cjs/src/vcs/index.cjs.map +1 -1
- package/dist/cjs/src/vcs/objects.cjs +141 -0
- package/dist/cjs/src/vcs/objects.cjs.map +10 -0
- package/dist/cjs/src/vcs/rules.cjs +6 -3
- package/dist/cjs/src/vcs/rules.cjs.map +3 -3
- package/dist/cjs/src/vcs/snapshot.cjs +89 -39
- package/dist/cjs/src/vcs/snapshot.cjs.map +3 -3
- package/dist/cjs/src/vcs/storage.cjs +44 -3
- package/dist/cjs/src/vcs/storage.cjs.map +3 -3
- package/dist/cjs/src/vcs/text-diff.cjs +219 -0
- package/dist/cjs/src/vcs/text-diff.cjs.map +10 -0
- package/dist/cjs/src/vcs/vcs.cjs +108 -61
- package/dist/cjs/src/vcs/vcs.cjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/src/fs/memfs-adapter.mjs +57 -2
- package/dist/mjs/src/fs/memfs-adapter.mjs.map +3 -3
- package/dist/mjs/src/fs/real-fs.mjs +135 -3
- package/dist/mjs/src/fs/real-fs.mjs.map +3 -3
- package/dist/mjs/src/fs/special-files.mjs +3 -2
- package/dist/mjs/src/fs/special-files.mjs.map +3 -3
- package/dist/mjs/src/fs/web-fs.mjs +72 -3
- package/dist/mjs/src/fs/web-fs.mjs.map +3 -3
- package/dist/mjs/src/index.mjs.map +2 -2
- package/dist/mjs/src/types.mjs.map +2 -2
- package/dist/mjs/src/vcs/content.mjs +66 -0
- package/dist/mjs/src/vcs/content.mjs.map +10 -0
- package/dist/mjs/src/vcs/diff.mjs +72 -28
- package/dist/mjs/src/vcs/diff.mjs.map +3 -3
- package/dist/mjs/src/vcs/index.mjs.map +1 -1
- package/dist/mjs/src/vcs/objects.mjs +106 -0
- package/dist/mjs/src/vcs/objects.mjs.map +10 -0
- package/dist/mjs/src/vcs/rules.mjs +6 -3
- package/dist/mjs/src/vcs/rules.mjs.map +3 -3
- package/dist/mjs/src/vcs/snapshot.mjs +89 -39
- package/dist/mjs/src/vcs/snapshot.mjs.map +3 -3
- package/dist/mjs/src/vcs/storage.mjs +45 -3
- package/dist/mjs/src/vcs/storage.mjs.map +3 -3
- package/dist/mjs/src/vcs/text-diff.mjs +179 -0
- package/dist/mjs/src/vcs/text-diff.mjs.map +10 -0
- package/dist/mjs/src/vcs/vcs.mjs +115 -63
- package/dist/mjs/src/vcs/vcs.mjs.map +3 -3
- package/dist/types/src/fs/real-fs.d.ts +12 -1
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/types.d.ts +10 -0
- package/dist/types/src/vcs/content.d.ts +6 -0
- package/dist/types/src/vcs/diff.d.ts +10 -7
- package/dist/types/src/vcs/index.d.ts +1 -1
- package/dist/types/src/vcs/objects.d.ts +22 -0
- package/dist/types/src/vcs/snapshot.d.ts +13 -8
- package/dist/types/src/vcs/storage.d.ts +7 -1
- package/dist/types/src/vcs/text-diff.d.ts +1 -0
- package/dist/types/src/vcs/types.d.ts +20 -5
- package/dist/types/src/vcs/vcs.d.ts +6 -0
- package/package.json +7 -2
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/vcs/rules.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { matchGlobPath } from \"./match.mjs\";\nimport type { VCSAttributeRule, VCSResolvedAttributes } from \"./types.mjs\";\n\ninterface VCSRulesConfig {\n internalPath?: string;\n internalDirName?: string;\n ignore?: string[];\n attributes?: VCSAttributeRule[];\n}\n\nexport class VCSRules {\n private readonly internalPath: string;\n private readonly ignorePatterns: string[];\n private readonly attributeRules: VCSAttributeRule[];\n\n constructor(config: VCSRulesConfig = {}) {\n this.internalPath = normalizePath(config.internalPath ?? config.internalDirName ?? \"\");\n this.ignorePatterns = [...(config.ignore ?? [])];\n this.attributeRules = [...(config.attributes ?? [])];\n }\n\n isInternalPath(relPath: string): boolean {\n if (!this.internalPath) return false;\n const normalizedPath = normalizePath(relPath);\n if (!normalizedPath) return false;\n return normalizedPath === this.internalPath || normalizedPath.startsWith(`${this.internalPath}/`);\n }\n\n isIgnored(relPath: string): boolean {\n if (this.isInternalPath(relPath)) return true;\n return this.ignorePatterns.some((pattern) => matchVCSPath(pattern, relPath));\n }\n\n shouldEnterDirectory(relPath: string, trackedPaths: Iterable<string>): boolean {\n if (this.isInternalPath(relPath)) return false;\n if (!this.isIgnored(relPath)) return true;\n return hasTrackedPathAtOrBelow(relPath, trackedPaths);\n }\n\n shouldIncludeWorkingFile(relPath: string, trackedPaths: ReadonlySet<string>): boolean {\n if (this.isInternalPath(relPath)) return false;\n if (trackedPaths.has(relPath)) return true;\n return !this.isIgnored(relPath);\n }\n\n shouldIncludeEmptyDirectory(relPath: string, trackedPaths: ReadonlySet<string>): boolean {\n if (this.isInternalPath(relPath)) return false;\n if (trackedPaths.has(relPath)) return true;\n return !this.isIgnored(relPath);\n }\n\n shouldIncludeRestoreScanFile(relPath: string): boolean {\n return !this.isInternalPath(relPath);\n }\n\n shouldPreserveUntrackedIgnored(relPath: string, trackedPaths: ReadonlySet<string>): boolean {\n if (trackedPaths.has(relPath)) return false;\n return this.isIgnored(relPath);\n }\n\n resolveAttributes(relPath: string): VCSResolvedAttributes {\n let binary
|
|
5
|
+
"import { matchGlobPath } from \"./match.mjs\";\nimport type { VCSAttributeRule, VCSResolvedAttributes } from \"./types.mjs\";\n\ninterface VCSRulesConfig {\n internalPath?: string;\n internalDirName?: string;\n ignore?: string[];\n attributes?: VCSAttributeRule[];\n}\n\nexport class VCSRules {\n private readonly internalPath: string;\n private readonly ignorePatterns: string[];\n private readonly attributeRules: VCSAttributeRule[];\n\n constructor(config: VCSRulesConfig = {}) {\n this.internalPath = normalizePath(config.internalPath ?? config.internalDirName ?? \"\");\n this.ignorePatterns = [...(config.ignore ?? [])];\n this.attributeRules = [...(config.attributes ?? [])];\n }\n\n isInternalPath(relPath: string): boolean {\n if (!this.internalPath) return false;\n const normalizedPath = normalizePath(relPath);\n if (!normalizedPath) return false;\n return normalizedPath === this.internalPath || normalizedPath.startsWith(`${this.internalPath}/`);\n }\n\n isIgnored(relPath: string): boolean {\n if (this.isInternalPath(relPath)) return true;\n return this.ignorePatterns.some((pattern) => matchVCSPath(pattern, relPath));\n }\n\n shouldEnterDirectory(relPath: string, trackedPaths: Iterable<string>): boolean {\n if (this.isInternalPath(relPath)) return false;\n if (!this.isIgnored(relPath)) return true;\n return hasTrackedPathAtOrBelow(relPath, trackedPaths);\n }\n\n shouldIncludeWorkingFile(relPath: string, trackedPaths: ReadonlySet<string>): boolean {\n if (this.isInternalPath(relPath)) return false;\n if (trackedPaths.has(relPath)) return true;\n return !this.isIgnored(relPath);\n }\n\n shouldIncludeEmptyDirectory(relPath: string, trackedPaths: ReadonlySet<string>): boolean {\n if (this.isInternalPath(relPath)) return false;\n if (trackedPaths.has(relPath)) return true;\n return !this.isIgnored(relPath);\n }\n\n shouldIncludeRestoreScanFile(relPath: string): boolean {\n return !this.isInternalPath(relPath);\n }\n\n shouldPreserveUntrackedIgnored(relPath: string, trackedPaths: ReadonlySet<string>): boolean {\n if (trackedPaths.has(relPath)) return false;\n return this.isIgnored(relPath);\n }\n\n resolveAttributes(relPath: string): VCSResolvedAttributes {\n let binary: boolean | undefined;\n let diff: VCSResolvedAttributes[\"diff\"];\n\n for (const rule of this.attributeRules) {\n if (!matchVCSPath(rule.pattern, relPath)) continue;\n if (rule.binary !== undefined) {\n binary = rule.binary;\n }\n if (rule.diff !== undefined) {\n diff = rule.diff;\n }\n }\n\n if (diff === \"binary\") {\n binary = true;\n }\n if (diff === \"text\") {\n binary = false;\n }\n\n return { binary, diff };\n }\n}\n\nexport function matchVCSPath(pattern: string, relPath: string): boolean {\n const normalizedPattern = normalizePattern(pattern);\n const normalizedPath = normalizePath(relPath);\n\n if (!normalizedPattern || !normalizedPath) return false;\n\n if (normalizedPattern.mode === \"root-path\") {\n return matchGlobPath(normalizedPattern.pattern, normalizedPath);\n }\n\n if (normalizedPattern.mode === \"root-segment\") {\n const [firstSegment] = normalizedPath.split(\"/\");\n return firstSegment ? matchGlobPath(normalizedPattern.pattern, firstSegment) : false;\n }\n\n if (normalizedPattern.mode === \"root-prefix\") {\n return (\n matchGlobPath(normalizedPattern.pattern, normalizedPath) ||\n matchGlobPath(`${normalizedPattern.pattern}/**`, normalizedPath)\n );\n }\n\n const segments = normalizedPath.split(\"/\");\n return segments.some((segment) => matchGlobPath(normalizedPattern.pattern, segment));\n}\n\nfunction normalizePath(relPath: string): string {\n return relPath.replace(/\\\\/g, \"/\").replace(/^\\/+/, \"\").replace(/\\/+$/, \"\");\n}\n\nfunction normalizePattern(pattern: string): {\n pattern: string;\n mode: \"root-path\" | \"root-prefix\" | \"root-segment\" | \"segment\";\n} | null {\n let normalized = pattern.trim();\n if (!normalized) return null;\n\n normalized = normalized.replace(/\\\\/g, \"/\");\n const anchored = normalized.startsWith(\"/\");\n const directoryOnly = normalized.endsWith(\"/\");\n normalized = normalized.replace(/^\\/+/, \"\").replace(/\\/+$/, \"\");\n if (!normalized) return null;\n\n if (normalized.includes(\"/\")) {\n return {\n pattern: normalized,\n mode: directoryOnly ? \"root-prefix\" : \"root-path\",\n };\n }\n\n if (anchored) {\n return {\n pattern: normalized,\n mode: \"root-segment\",\n };\n }\n\n return {\n pattern: normalized,\n mode: \"segment\",\n };\n}\n\nfunction hasTrackedPathAtOrBelow(relPath: string, trackedPaths: Iterable<string>): boolean {\n const normalizedPath = normalizePath(relPath);\n if (!normalizedPath) return false;\n\n const prefix = normalizedPath + \"/\";\n for (const trackedPath of trackedPaths) {\n const normalizedTrackedPath = normalizePath(trackedPath);\n if (\n normalizedTrackedPath === normalizedPath ||\n normalizedTrackedPath.startsWith(prefix)\n ) {\n return true;\n }\n }\n return false;\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAAA;AAAA;AAUO,MAAM,SAAS;AAAA,EACH;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,WAAW,CAAC,SAAyB,CAAC,GAAG;AAAA,IACvC,KAAK,eAAe,cAAc,OAAO,gBAAgB,OAAO,mBAAmB,EAAE;AAAA,IACrF,KAAK,iBAAiB,CAAC,GAAI,OAAO,UAAU,CAAC,CAAE;AAAA,IAC/C,KAAK,iBAAiB,CAAC,GAAI,OAAO,cAAc,CAAC,CAAE;AAAA;AAAA,EAGrD,cAAc,CAAC,SAA0B;AAAA,IACvC,IAAI,CAAC,KAAK;AAAA,MAAc,OAAO;AAAA,IAC/B,MAAM,iBAAiB,cAAc,OAAO;AAAA,IAC5C,IAAI,CAAC;AAAA,MAAgB,OAAO;AAAA,IAC5B,OAAO,mBAAmB,KAAK,gBAAgB,eAAe,WAAW,GAAG,KAAK,eAAe;AAAA;AAAA,EAGlG,SAAS,CAAC,SAA0B;AAAA,IAClC,IAAI,KAAK,eAAe,OAAO;AAAA,MAAG,OAAO;AAAA,IACzC,OAAO,KAAK,eAAe,KAAK,CAAC,YAAY,aAAa,SAAS,OAAO,CAAC;AAAA;AAAA,EAG7E,oBAAoB,CAAC,SAAiB,cAAyC;A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AAE,QAAQ,QAAQ,EAAE;AAAA;AAG3E,SAAS,gBAAgB,CAAC,SAGjB;AAAA,EACP,IAAI,aAAa,QAAQ,KAAK;AAAA,EAC9B,IAAI,CAAC;AAAA,IAAY,OAAO;AAAA,EAExB,aAAa,WAAW,QAAQ,OAAO,GAAG;AAAA,EAC1C,MAAM,WAAW,WAAW,WAAW,GAAG;AAAA,EAC1C,MAAM,gBAAgB,WAAW,SAAS,GAAG;AAAA,EAC7C,aAAa,WAAW,QAAQ,QAAQ,EAAE,EAAE,QAAQ,QAAQ,EAAE;AAAA,EAC9D,IAAI,CAAC;AAAA,IAAY,OAAO;AAAA,EAExB,IAAI,WAAW,SAAS,GAAG,GAAG;AAAA,IAC5B,OAAO;AAAA,MACL,SAAS;AAAA,MACT,MAAM,gBAAgB,gBAAgB;AAAA,IACxC;AAAA,EACF;AAAA,EAEA,IAAI,UAAU;AAAA,IACZ,OAAO;AAAA,MACL,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,IACL,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AAAA;AAGF,SAAS,uBAAuB,CAAC,SAAiB,cAAyC;AAAA,EACzF,MAAM,iBAAiB,cAAc,OAAO;AAAA,EAC5C,IAAI,CAAC;AAAA,IAAgB,OAAO;AAAA,EAE5B,MAAM,SAAS,iBAAiB;AAAA,EAChC,WAAW,eAAe,cAAc;AAAA,IACtC,MAAM,wBAAwB,cAAc,WAAW;AAAA,IACvD,IACE,0BAA0B,kBAC1B,sBAAsB,WAAW,MAAM,GACvC;AAAA,MACA,OAAO;AAAA,IACT;AAAA,EACF;AAAA,EACA,OAAO;AAAA;",
|
|
8
|
+
"debugId": "B359D27A071846E264756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// src/vcs/snapshot.ts
|
|
2
|
+
import { hashSample, readStreamSample } from "./content.mjs";
|
|
2
3
|
import { matchVCSPath, VCSRules } from "./rules.mjs";
|
|
3
4
|
import { walkTreeEntries } from "./walk.mjs";
|
|
4
5
|
async function buildTreeManifest(fs, rootPath, options) {
|
|
5
6
|
const manifest = {};
|
|
6
|
-
const
|
|
7
|
-
const
|
|
7
|
+
const nextIndexEntries = {};
|
|
8
|
+
const rules = options.rules ?? new VCSRules({ internalDirName: ".vcs" });
|
|
9
|
+
const trackedPaths = new Set(options.trackedPaths ?? []);
|
|
8
10
|
const entries = await walkTreeEntries(fs, rootPath, {
|
|
9
11
|
enterDirectory: (relPath) => rules.shouldEnterDirectory(relPath, trackedPaths),
|
|
10
12
|
includeFile: (relPath) => rules.shouldIncludeWorkingFile(relPath, trackedPaths),
|
|
@@ -16,43 +18,37 @@ async function buildTreeManifest(fs, rootPath, options) {
|
|
|
16
18
|
continue;
|
|
17
19
|
}
|
|
18
20
|
const fullPath = fs.resolve(rootPath, entry.path);
|
|
19
|
-
const content = await fs.readFile(fullPath);
|
|
20
|
-
const buf = Buffer.from(content);
|
|
21
|
-
manifest[entry.path] = {
|
|
22
|
-
kind: "file",
|
|
23
|
-
content: buf.toString("base64"),
|
|
24
|
-
size: buf.length
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
return manifest;
|
|
28
|
-
}
|
|
29
|
-
async function buildPartialManifest(fs, rootPath, paths) {
|
|
30
|
-
const manifest = {};
|
|
31
|
-
for (const relPath of paths) {
|
|
32
|
-
const fullPath = fs.resolve(rootPath, relPath);
|
|
33
|
-
if (!await fs.exists(fullPath))
|
|
34
|
-
continue;
|
|
35
21
|
const stat = await fs.stat(fullPath);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
22
|
+
const cached = options.indexEntries?.[entry.path];
|
|
23
|
+
if (cached && cached.size === stat.size && cached.mtimeMs === stat.mtimeMs && await options.objectStore.hasBlob(cached.blobId)) {
|
|
24
|
+
const sampleHash = hashSample(await readStreamSample(fs.readStream(fullPath)));
|
|
25
|
+
if (sampleHash === cached.sampleHash) {
|
|
26
|
+
manifest[entry.path] = {
|
|
27
|
+
kind: "file",
|
|
28
|
+
blobId: cached.blobId,
|
|
29
|
+
size: cached.size
|
|
30
|
+
};
|
|
31
|
+
nextIndexEntries[entry.path] = cached;
|
|
32
|
+
continue;
|
|
40
33
|
}
|
|
41
|
-
continue;
|
|
42
34
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const content = await fs.readFile(fullPath);
|
|
46
|
-
const buf = Buffer.from(content);
|
|
47
|
-
manifest[relPath] = {
|
|
35
|
+
const stored = await options.objectStore.store(fs.readStream(fullPath));
|
|
36
|
+
manifest[entry.path] = {
|
|
48
37
|
kind: "file",
|
|
49
|
-
|
|
50
|
-
size:
|
|
38
|
+
blobId: stored.blobId,
|
|
39
|
+
size: stored.size
|
|
40
|
+
};
|
|
41
|
+
nextIndexEntries[entry.path] = {
|
|
42
|
+
blobId: stored.blobId,
|
|
43
|
+
size: stored.size,
|
|
44
|
+
mtimeMs: stat.mtimeMs,
|
|
45
|
+
binary: stored.binary,
|
|
46
|
+
sampleHash: stored.sampleHash
|
|
51
47
|
};
|
|
52
48
|
}
|
|
53
|
-
return manifest;
|
|
49
|
+
return { manifest, indexEntries: nextIndexEntries };
|
|
54
50
|
}
|
|
55
|
-
async function restoreTree(fs, rootPath, manifest, options) {
|
|
51
|
+
async function restoreTree(fs, rootPath, manifest, objectStore, options) {
|
|
56
52
|
const fullRestore = options?.fullRestore ?? false;
|
|
57
53
|
const rules = options?.rules ?? new VCSRules({ internalDirName: ".vcs" });
|
|
58
54
|
const trackedPaths = new Set(options?.trackedPaths ?? []);
|
|
@@ -87,7 +83,7 @@ async function restoreTree(fs, rootPath, manifest, options) {
|
|
|
87
83
|
await ensureDirectoryExists(fs, fs.resolve(rootPath, relPath));
|
|
88
84
|
continue;
|
|
89
85
|
}
|
|
90
|
-
await writeFileFromEntry(fs, rootPath, relPath, entry);
|
|
86
|
+
await writeFileFromEntry(fs, rootPath, relPath, entry, objectStore);
|
|
91
87
|
}
|
|
92
88
|
if (shouldDeleteExtras) {
|
|
93
89
|
const currentEntries = await walkTreeEntries(fs, rootPath, {
|
|
@@ -108,12 +104,65 @@ async function restoreTree(fs, rootPath, manifest, options) {
|
|
|
108
104
|
}
|
|
109
105
|
}
|
|
110
106
|
}
|
|
111
|
-
async function
|
|
107
|
+
async function rebuildIndexForManifest(fs, rootPath, manifest, objectStore) {
|
|
108
|
+
const entries = {};
|
|
109
|
+
for (const [relPath, entry] of Object.entries(manifest)) {
|
|
110
|
+
if (isDirectoryEntry(entry)) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const fullPath = fs.resolve(rootPath, relPath);
|
|
114
|
+
const stat = await fs.stat(fullPath);
|
|
115
|
+
entries[relPath] = {
|
|
116
|
+
blobId: entry.blobId,
|
|
117
|
+
size: entry.size,
|
|
118
|
+
mtimeMs: stat.mtimeMs,
|
|
119
|
+
binary: await objectStore.isBinaryBlob(entry.blobId),
|
|
120
|
+
sampleHash: hashSample(await readStreamSample(fs.readStream(fullPath)))
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return entries;
|
|
124
|
+
}
|
|
125
|
+
async function updateIndexForScopedPaths(fs, rootPath, manifest, objectStore, existingIndex, patterns) {
|
|
126
|
+
const nextIndex = { ...existingIndex };
|
|
127
|
+
for (const relPath of Object.keys(existingIndex)) {
|
|
128
|
+
if (isPathInScope(relPath, patterns) && !manifest[relPath]) {
|
|
129
|
+
delete nextIndex[relPath];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
for (const [relPath, entry] of Object.entries(manifest)) {
|
|
133
|
+
if (!isPathInScope(relPath, patterns) || isDirectoryEntry(entry)) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const fullPath = fs.resolve(rootPath, relPath);
|
|
137
|
+
if (!await fs.exists(fullPath)) {
|
|
138
|
+
delete nextIndex[relPath];
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const stat = await fs.stat(fullPath);
|
|
142
|
+
nextIndex[relPath] = {
|
|
143
|
+
blobId: entry.blobId,
|
|
144
|
+
size: entry.size,
|
|
145
|
+
mtimeMs: stat.mtimeMs,
|
|
146
|
+
binary: await objectStore.isBinaryBlob(entry.blobId),
|
|
147
|
+
sampleHash: hashSample(await readStreamSample(fs.readStream(fullPath)))
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return nextIndex;
|
|
151
|
+
}
|
|
152
|
+
async function writeFileFromEntry(fs, rootPath, relPath, entry, objectStore) {
|
|
112
153
|
const fullPath = fs.resolve(rootPath, relPath);
|
|
113
154
|
await ensureDirectoryExists(fs, fs.dirname(fullPath));
|
|
114
155
|
await removeDirectoryAtPath(fs, fullPath);
|
|
115
|
-
const
|
|
116
|
-
|
|
156
|
+
const writer = await fs.writeStream(fullPath);
|
|
157
|
+
try {
|
|
158
|
+
for await (const chunk of objectStore.readBlobStream(entry.blobId)) {
|
|
159
|
+
await writer.write(chunk);
|
|
160
|
+
}
|
|
161
|
+
await writer.close();
|
|
162
|
+
} catch (error) {
|
|
163
|
+
await writer.abort?.(error);
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
117
166
|
}
|
|
118
167
|
function isDirectoryEntry(entry) {
|
|
119
168
|
return entry.kind === "directory";
|
|
@@ -180,9 +229,10 @@ async function isEmptyDirectory(fs, dirPath) {
|
|
|
180
229
|
}
|
|
181
230
|
}
|
|
182
231
|
export {
|
|
232
|
+
updateIndexForScopedPaths,
|
|
183
233
|
restoreTree,
|
|
184
|
-
|
|
185
|
-
|
|
234
|
+
rebuildIndexForManifest,
|
|
235
|
+
buildTreeManifest
|
|
186
236
|
};
|
|
187
237
|
|
|
188
|
-
//# debugId=
|
|
238
|
+
//# debugId=651BD3C5CF51DA6064756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/vcs/snapshot.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { VirtualFS } from \"../types.mjs\";\nimport type { TreeManifest, FileEntry, TreeEntry } from \"./types.mjs\";\nimport { matchVCSPath, VCSRules } from \"./rules.mjs\";\nimport { walkTreeEntries } from \"./walk.mjs\";\n\n/**\n * Build a TreeManifest from the current working tree.\n */\nexport async function buildTreeManifest(\n fs: VirtualFS,\n rootPath: string,\n options?: {\n rules?: VCSRules;\n trackedPaths?: Iterable<string>;\n },\n): Promise<TreeManifest> {\n const manifest: TreeManifest = {};\n const rules = options?.rules ?? new VCSRules({ internalDirName: \".vcs\" });\n const trackedPaths = new Set(options?.trackedPaths ?? []);\n const entries = await walkTreeEntries(fs, rootPath, {\n enterDirectory: (relPath) => rules.shouldEnterDirectory(relPath, trackedPaths),\n includeFile: (relPath) => rules.shouldIncludeWorkingFile(relPath, trackedPaths),\n includeDirectory: (relPath, info) =>\n info.empty && rules.shouldIncludeEmptyDirectory(relPath, trackedPaths),\n });\n\n for (const entry of entries) {\n if (entry.kind === \"directory\") {\n manifest[entry.path] = { kind: \"directory\", size: 0 };\n continue;\n }\n\n const fullPath = fs.resolve(rootPath, entry.path);\n const content = await fs.readFile(fullPath);\n const buf = Buffer.from(content);\n manifest[entry.path] = {\n kind: \"file\",\n content: buf.toString(\"base64\"),\n size: buf.length,\n };\n }\n\n return manifest;\n}\n\n/**\n * Build a TreeManifest for only the specified relative paths.\n */\nexport async function buildPartialManifest(\n fs: VirtualFS,\n rootPath: string,\n paths: string[],\n): Promise<TreeManifest> {\n const manifest: TreeManifest = {};\n\n for (const relPath of paths) {\n const fullPath = fs.resolve(rootPath, relPath);\n if (!(await fs.exists(fullPath))) continue;\n const stat = await fs.stat(fullPath);\n if (stat.isDirectory()) {\n const entries = await fs.readdir(fullPath);\n if (entries.length === 0) {\n manifest[relPath] = { kind: \"directory\", size: 0 };\n }\n continue;\n }\n if (!stat.isFile()) continue;\n\n const content = await fs.readFile(fullPath);\n const buf = Buffer.from(content);\n manifest[relPath] = {\n kind: \"file\",\n content: buf.toString(\"base64\"),\n size: buf.length,\n };\n }\n\n return manifest;\n}\n\n/**\n * Restore a working tree from a TreeManifest.\n *\n * If `fullRestore` is true, deletes working tree files not in the manifest.\n * If `paths` is provided, only restores matching files.\n */\nexport async function restoreTree(\n fs: VirtualFS,\n rootPath: string,\n manifest: TreeManifest,\n options?: {\n fullRestore?: boolean;\n paths?: string[];\n rules?: VCSRules;\n trackedPaths?: Iterable<string>;\n },\n): Promise<void> {\n const fullRestore = options?.fullRestore ?? false;\n const rules = options?.rules ?? new VCSRules({ internalDirName: \".vcs\" });\n const trackedPaths = new Set(options?.trackedPaths ?? []);\n const scopePatterns = options?.paths ?? null;\n const scopedEntries = Object.entries(manifest)\n .filter(([relPath]) => isPathInScope(relPath, scopePatterns))\n .sort(([a], [b]) => a.localeCompare(b));\n const targetPaths = new Set(scopedEntries.map(([relPath]) => relPath));\n const requiredDirectories = collectRequiredDirectories(scopedEntries);\n const shouldDeleteExtras = fullRestore || scopePatterns !== null;\n\n if (shouldDeleteExtras) {\n const currentEntries = await walkTreeEntries(fs, rootPath, {\n enterDirectory: (relPath) => !rules.isInternalPath(relPath),\n includeFile: (relPath) => rules.shouldIncludeRestoreScanFile(relPath),\n includeDirectory: () => true,\n });\n\n for (const current of currentEntries) {\n if (current.kind !== \"file\") continue;\n if (!isPathInScope(current.path, scopePatterns)) continue;\n if (targetPaths.has(current.path)) continue;\n if (rules.shouldPreserveUntrackedIgnored(current.path, trackedPaths)) continue;\n await fs.rm(fs.resolve(rootPath, current.path));\n }\n }\n\n for (const directory of [...requiredDirectories].sort(comparePathDepth)) {\n await ensureDirectoryExists(fs, fs.resolve(rootPath, directory));\n }\n\n for (const [relPath, entry] of scopedEntries) {\n if (isDirectoryEntry(entry)) {\n await ensureDirectoryExists(fs, fs.resolve(rootPath, relPath));\n continue;\n }\n await writeFileFromEntry(fs, rootPath, relPath, entry);\n }\n\n if (shouldDeleteExtras) {\n const currentEntries = await walkTreeEntries(fs, rootPath, {\n enterDirectory: (relPath) => !rules.isInternalPath(relPath),\n includeFile: () => true,\n includeDirectory: () => true,\n });\n\n const directories = currentEntries\n .filter((entry) => entry.kind === \"directory\")\n .map((entry) => entry.path)\n .filter((relPath) => isPathInScope(relPath, scopePatterns))\n .sort((a, b) => comparePathDepth(b, a));\n\n for (const relPath of directories) {\n if (requiredDirectories.has(relPath)) continue;\n if (rules.shouldPreserveUntrackedIgnored(relPath, trackedPaths)) continue;\n const fullPath = fs.resolve(rootPath, relPath);\n if (await isEmptyDirectory(fs, fullPath)) {\n await fs.rm(fullPath);\n }\n }\n }\n}\n\nasync function writeFileFromEntry(\n fs: VirtualFS,\n rootPath: string,\n relPath: string,\n entry: FileEntry,\n): Promise<void> {\n const fullPath = fs.resolve(rootPath, relPath);\n await ensureDirectoryExists(fs, fs.dirname(fullPath));\n await removeDirectoryAtPath(fs, fullPath);\n\n const buf = Buffer.from(entry.content, \"base64\");\n await fs.writeFile(fullPath, buf);\n}\n\nfunction isDirectoryEntry(entry: TreeEntry): entry is Extract<TreeEntry, { kind: \"directory\" }> {\n return entry.kind === \"directory\";\n}\n\nfunction isPathInScope(relPath: string, patterns: string[] | null): boolean {\n if (!patterns || patterns.length === 0) return true;\n return patterns.some((pattern) => matchVCSPath(pattern, relPath));\n}\n\nfunction collectRequiredDirectories(entries: Array<[string, TreeEntry]>): Set<string> {\n const directories = new Set<string>();\n\n for (const [relPath, entry] of entries) {\n if (isDirectoryEntry(entry)) {\n directories.add(relPath);\n }\n for (const parent of parentDirectories(relPath)) {\n directories.add(parent);\n }\n }\n\n return directories;\n}\n\nfunction parentDirectories(relPath: string): string[] {\n const parts = relPath.split(\"/\").filter(Boolean);\n const parents: string[] = [];\n\n for (let i = 1; i < parts.length; i++) {\n parents.push(parts.slice(0, i).join(\"/\"));\n }\n\n return parents;\n}\n\nfunction comparePathDepth(a: string, b: string): number {\n const depthA = a.split(\"/\").filter(Boolean).length;\n const depthB = b.split(\"/\").filter(Boolean).length;\n if (depthA !== depthB) return depthA - depthB;\n return a.localeCompare(b);\n}\n\nasync function ensureDirectoryExists(fs: VirtualFS, dirPath: string): Promise<void> {\n const parent = fs.dirname(dirPath);\n if (parent !== dirPath) {\n await ensureDirectoryExists(fs, parent);\n }\n\n if (await fs.exists(dirPath)) {\n const stat = await fs.stat(dirPath);\n if (stat.isDirectory()) return;\n await fs.rm(dirPath, { recursive: true, force: true });\n }\n\n await fs.mkdir(dirPath, { recursive: true });\n}\n\nasync function removeDirectoryAtPath(fs: VirtualFS, path: string): Promise<void> {\n if (!(await fs.exists(path))) return;\n const stat = await fs.stat(path);\n if (stat.isDirectory()) {\n await fs.rm(path, { recursive: true, force: true });\n }\n}\n\nasync function isEmptyDirectory(fs: VirtualFS, dirPath: string): Promise<boolean> {\n try {\n const entries = await fs.readdir(dirPath);\n return entries.length === 0;\n } catch {\n return false;\n }\n}\n"
|
|
5
|
+
"import type { VirtualFS } from \"../types.mjs\";\nimport type { TreeManifest, FileEntry, TreeEntry, VCSIndexEntry } from \"./types.mjs\";\nimport { hashSample, readStreamSample } from \"./content.mjs\";\nimport { matchVCSPath, VCSRules } from \"./rules.mjs\";\nimport { walkTreeEntries } from \"./walk.mjs\";\nimport { VCSObjectStore } from \"./objects.mjs\";\n\nexport interface BuildTreeManifestResult {\n manifest: TreeManifest;\n indexEntries: Record<string, VCSIndexEntry>;\n}\n\n/**\n * Build a TreeManifest from the current working tree.\n */\nexport async function buildTreeManifest(\n fs: VirtualFS,\n rootPath: string,\n options: {\n objectStore: VCSObjectStore;\n rules?: VCSRules;\n trackedPaths?: Iterable<string>;\n indexEntries?: Record<string, VCSIndexEntry>;\n },\n): Promise<BuildTreeManifestResult> {\n const manifest: TreeManifest = {};\n const nextIndexEntries: Record<string, VCSIndexEntry> = {};\n const rules = options.rules ?? new VCSRules({ internalDirName: \".vcs\" });\n const trackedPaths = new Set(options.trackedPaths ?? []);\n const entries = await walkTreeEntries(fs, rootPath, {\n enterDirectory: (relPath) => rules.shouldEnterDirectory(relPath, trackedPaths),\n includeFile: (relPath) => rules.shouldIncludeWorkingFile(relPath, trackedPaths),\n includeDirectory: (relPath, info) =>\n info.empty && rules.shouldIncludeEmptyDirectory(relPath, trackedPaths),\n });\n\n for (const entry of entries) {\n if (entry.kind === \"directory\") {\n manifest[entry.path] = { kind: \"directory\", size: 0 };\n continue;\n }\n\n const fullPath = fs.resolve(rootPath, entry.path);\n const stat = await fs.stat(fullPath);\n const cached = options.indexEntries?.[entry.path];\n\n if (\n cached &&\n cached.size === stat.size &&\n cached.mtimeMs === stat.mtimeMs &&\n await options.objectStore.hasBlob(cached.blobId)\n ) {\n const sampleHash = hashSample(await readStreamSample(fs.readStream(fullPath)));\n if (sampleHash === cached.sampleHash) {\n manifest[entry.path] = {\n kind: \"file\",\n blobId: cached.blobId,\n size: cached.size,\n };\n nextIndexEntries[entry.path] = cached;\n continue;\n }\n }\n\n const stored = await options.objectStore.store(fs.readStream(fullPath));\n manifest[entry.path] = {\n kind: \"file\",\n blobId: stored.blobId,\n size: stored.size,\n };\n nextIndexEntries[entry.path] = {\n blobId: stored.blobId,\n size: stored.size,\n mtimeMs: stat.mtimeMs,\n binary: stored.binary,\n sampleHash: stored.sampleHash,\n };\n }\n\n return { manifest, indexEntries: nextIndexEntries };\n}\n\n/**\n * Restore a working tree from a TreeManifest.\n *\n * If `fullRestore` is true, deletes working tree files not in the manifest.\n * If `paths` is provided, only restores matching files.\n */\nexport async function restoreTree(\n fs: VirtualFS,\n rootPath: string,\n manifest: TreeManifest,\n objectStore: VCSObjectStore,\n options?: {\n fullRestore?: boolean;\n paths?: string[];\n rules?: VCSRules;\n trackedPaths?: Iterable<string>;\n },\n): Promise<void> {\n const fullRestore = options?.fullRestore ?? false;\n const rules = options?.rules ?? new VCSRules({ internalDirName: \".vcs\" });\n const trackedPaths = new Set(options?.trackedPaths ?? []);\n const scopePatterns = options?.paths ?? null;\n const scopedEntries = Object.entries(manifest)\n .filter(([relPath]) => isPathInScope(relPath, scopePatterns))\n .sort(([a], [b]) => a.localeCompare(b));\n const targetPaths = new Set(scopedEntries.map(([relPath]) => relPath));\n const requiredDirectories = collectRequiredDirectories(scopedEntries);\n const shouldDeleteExtras = fullRestore || scopePatterns !== null;\n\n if (shouldDeleteExtras) {\n const currentEntries = await walkTreeEntries(fs, rootPath, {\n enterDirectory: (relPath) => !rules.isInternalPath(relPath),\n includeFile: (relPath) => rules.shouldIncludeRestoreScanFile(relPath),\n includeDirectory: () => true,\n });\n\n for (const current of currentEntries) {\n if (current.kind !== \"file\") continue;\n if (!isPathInScope(current.path, scopePatterns)) continue;\n if (targetPaths.has(current.path)) continue;\n if (rules.shouldPreserveUntrackedIgnored(current.path, trackedPaths)) continue;\n await fs.rm(fs.resolve(rootPath, current.path));\n }\n }\n\n for (const directory of [...requiredDirectories].sort(comparePathDepth)) {\n await ensureDirectoryExists(fs, fs.resolve(rootPath, directory));\n }\n\n for (const [relPath, entry] of scopedEntries) {\n if (isDirectoryEntry(entry)) {\n await ensureDirectoryExists(fs, fs.resolve(rootPath, relPath));\n continue;\n }\n await writeFileFromEntry(fs, rootPath, relPath, entry, objectStore);\n }\n\n if (shouldDeleteExtras) {\n const currentEntries = await walkTreeEntries(fs, rootPath, {\n enterDirectory: (relPath) => !rules.isInternalPath(relPath),\n includeFile: () => true,\n includeDirectory: () => true,\n });\n\n const directories = currentEntries\n .filter((entry) => entry.kind === \"directory\")\n .map((entry) => entry.path)\n .filter((relPath) => isPathInScope(relPath, scopePatterns))\n .sort((a, b) => comparePathDepth(b, a));\n\n for (const relPath of directories) {\n if (requiredDirectories.has(relPath)) continue;\n if (rules.shouldPreserveUntrackedIgnored(relPath, trackedPaths)) continue;\n const fullPath = fs.resolve(rootPath, relPath);\n if (await isEmptyDirectory(fs, fullPath)) {\n await fs.rm(fullPath);\n }\n }\n }\n}\n\nexport async function rebuildIndexForManifest(\n fs: VirtualFS,\n rootPath: string,\n manifest: TreeManifest,\n objectStore: VCSObjectStore,\n): Promise<Record<string, VCSIndexEntry>> {\n const entries: Record<string, VCSIndexEntry> = {};\n\n for (const [relPath, entry] of Object.entries(manifest)) {\n if (isDirectoryEntry(entry)) {\n continue;\n }\n\n const fullPath = fs.resolve(rootPath, relPath);\n const stat = await fs.stat(fullPath);\n entries[relPath] = {\n blobId: entry.blobId,\n size: entry.size,\n mtimeMs: stat.mtimeMs,\n binary: await objectStore.isBinaryBlob(entry.blobId),\n sampleHash: hashSample(await readStreamSample(fs.readStream(fullPath))),\n };\n }\n\n return entries;\n}\n\nexport async function updateIndexForScopedPaths(\n fs: VirtualFS,\n rootPath: string,\n manifest: TreeManifest,\n objectStore: VCSObjectStore,\n existingIndex: Record<string, VCSIndexEntry>,\n patterns: string[],\n): Promise<Record<string, VCSIndexEntry>> {\n const nextIndex = { ...existingIndex };\n\n for (const relPath of Object.keys(existingIndex)) {\n if (isPathInScope(relPath, patterns) && !manifest[relPath]) {\n delete nextIndex[relPath];\n }\n }\n\n for (const [relPath, entry] of Object.entries(manifest)) {\n if (!isPathInScope(relPath, patterns) || isDirectoryEntry(entry)) {\n continue;\n }\n\n const fullPath = fs.resolve(rootPath, relPath);\n if (!(await fs.exists(fullPath))) {\n delete nextIndex[relPath];\n continue;\n }\n const stat = await fs.stat(fullPath);\n nextIndex[relPath] = {\n blobId: entry.blobId,\n size: entry.size,\n mtimeMs: stat.mtimeMs,\n binary: await objectStore.isBinaryBlob(entry.blobId),\n sampleHash: hashSample(await readStreamSample(fs.readStream(fullPath))),\n };\n }\n\n return nextIndex;\n}\n\nasync function writeFileFromEntry(\n fs: VirtualFS,\n rootPath: string,\n relPath: string,\n entry: FileEntry,\n objectStore: VCSObjectStore,\n): Promise<void> {\n const fullPath = fs.resolve(rootPath, relPath);\n await ensureDirectoryExists(fs, fs.dirname(fullPath));\n await removeDirectoryAtPath(fs, fullPath);\n\n const writer = await fs.writeStream(fullPath);\n try {\n for await (const chunk of objectStore.readBlobStream(entry.blobId)) {\n await writer.write(chunk);\n }\n await writer.close();\n } catch (error) {\n await writer.abort?.(error);\n throw error;\n }\n}\n\nfunction isDirectoryEntry(entry: TreeEntry): entry is Extract<TreeEntry, { kind: \"directory\" }> {\n return entry.kind === \"directory\";\n}\n\nfunction isPathInScope(relPath: string, patterns: string[] | null): boolean {\n if (!patterns || patterns.length === 0) return true;\n return patterns.some((pattern) => matchVCSPath(pattern, relPath));\n}\n\nfunction collectRequiredDirectories(entries: Array<[string, TreeEntry]>): Set<string> {\n const directories = new Set<string>();\n\n for (const [relPath, entry] of entries) {\n if (isDirectoryEntry(entry)) {\n directories.add(relPath);\n }\n for (const parent of parentDirectories(relPath)) {\n directories.add(parent);\n }\n }\n\n return directories;\n}\n\nfunction parentDirectories(relPath: string): string[] {\n const parts = relPath.split(\"/\").filter(Boolean);\n const parents: string[] = [];\n\n for (let i = 1; i < parts.length; i++) {\n parents.push(parts.slice(0, i).join(\"/\"));\n }\n\n return parents;\n}\n\nfunction comparePathDepth(a: string, b: string): number {\n const depthA = a.split(\"/\").filter(Boolean).length;\n const depthB = b.split(\"/\").filter(Boolean).length;\n if (depthA !== depthB) return depthA - depthB;\n return a.localeCompare(b);\n}\n\nasync function ensureDirectoryExists(fs: VirtualFS, dirPath: string): Promise<void> {\n const parent = fs.dirname(dirPath);\n if (parent !== dirPath) {\n await ensureDirectoryExists(fs, parent);\n }\n\n if (await fs.exists(dirPath)) {\n const stat = await fs.stat(dirPath);\n if (stat.isDirectory()) return;\n await fs.rm(dirPath, { recursive: true, force: true });\n }\n\n await fs.mkdir(dirPath, { recursive: true });\n}\n\nasync function removeDirectoryAtPath(fs: VirtualFS, path: string): Promise<void> {\n if (!(await fs.exists(path))) return;\n const stat = await fs.stat(path);\n if (stat.isDirectory()) {\n await fs.rm(path, { recursive: true, force: true });\n }\n}\n\nasync function isEmptyDirectory(fs: VirtualFS, dirPath: string): Promise<boolean> {\n try {\n const entries = await fs.readdir(dirPath);\n return entries.length === 0;\n } catch {\n return false;\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mapp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MAAM,GAAG,MAAM,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA;AAG7C,eAAe,qBAAqB,CAAC,IAAe,MAA6B;AAAA,EAC/E,IAAI,CAAE,MAAM,GAAG,OAAO,IAAI;AAAA,IAAI;AAAA,EAC9B,MAAM,OAAO,MAAM,GAAG,KAAK,IAAI;AAAA,EAC/B,IAAI,KAAK,YAAY,GAAG;AAAA,IACtB,MAAM,GAAG,GAAG,MAAM,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EACpD;AAAA;AAGF,eAAe,gBAAgB,CAAC,IAAe,SAAmC;AAAA,EAChF,IAAI;AAAA,IACF,MAAM,UAAU,MAAM,GAAG,QAAQ,OAAO;AAAA,IACxC,OAAO,QAAQ,WAAW;AAAA,IAC1B,MAAM;AAAA,IACN,OAAO;AAAA;AAAA;",
|
|
8
|
+
"debugId": "651BD3C5CF51DA6064756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// src/vcs/storage.ts
|
|
2
|
+
var VCS_FORMAT_VERSION = 2;
|
|
3
|
+
|
|
2
4
|
class VCSStorage {
|
|
3
5
|
fs;
|
|
4
6
|
basePath;
|
|
@@ -16,9 +18,18 @@ class VCSStorage {
|
|
|
16
18
|
await this.fs.mkdir(this.basePath, { recursive: true });
|
|
17
19
|
await this.fs.mkdir(this.path("refs", "heads"), { recursive: true });
|
|
18
20
|
await this.fs.mkdir(this.path("revisions"), { recursive: true });
|
|
21
|
+
await this.fs.mkdir(this.path("objects", "blobs"), { recursive: true });
|
|
22
|
+
await this.fs.mkdir(this.path("tmp"), { recursive: true });
|
|
19
23
|
await this.writeHead({ ref: `refs/heads/${defaultBranch}` });
|
|
20
24
|
await this.writeJSON(["counter.json"], { next: 1 });
|
|
21
|
-
await this.writeJSON(["config.json"], {
|
|
25
|
+
await this.writeJSON(["config.json"], {
|
|
26
|
+
version: VCS_FORMAT_VERSION,
|
|
27
|
+
defaultBranch
|
|
28
|
+
});
|
|
29
|
+
await this.writeJSON(["index.json"], {
|
|
30
|
+
version: VCS_FORMAT_VERSION,
|
|
31
|
+
entries: {}
|
|
32
|
+
});
|
|
22
33
|
}
|
|
23
34
|
async readHead() {
|
|
24
35
|
return this.readJSON("HEAD");
|
|
@@ -60,7 +71,33 @@ class VCSStorage {
|
|
|
60
71
|
return id;
|
|
61
72
|
}
|
|
62
73
|
async readConfig() {
|
|
63
|
-
|
|
74
|
+
const config = await this.readJSON("config.json");
|
|
75
|
+
this.assertSupportedVersion(config.version);
|
|
76
|
+
return config;
|
|
77
|
+
}
|
|
78
|
+
async assertSupportedFormat() {
|
|
79
|
+
await this.readConfig();
|
|
80
|
+
}
|
|
81
|
+
async readIndex() {
|
|
82
|
+
const indexPath = this.path("index.json");
|
|
83
|
+
if (!await this.fs.exists(indexPath)) {
|
|
84
|
+
return {};
|
|
85
|
+
}
|
|
86
|
+
const index = await this.readJSON("index.json");
|
|
87
|
+
this.assertSupportedVersion(index.version);
|
|
88
|
+
return index.entries;
|
|
89
|
+
}
|
|
90
|
+
async writeIndex(entries) {
|
|
91
|
+
await this.writeJSON(["index.json"], {
|
|
92
|
+
version: VCS_FORMAT_VERSION,
|
|
93
|
+
entries
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
resolve(...segments) {
|
|
97
|
+
return this.path(...segments);
|
|
98
|
+
}
|
|
99
|
+
get fileSystem() {
|
|
100
|
+
return this.fs;
|
|
64
101
|
}
|
|
65
102
|
async readJSON(...segments) {
|
|
66
103
|
const filePath = this.path(...segments);
|
|
@@ -71,9 +108,14 @@ class VCSStorage {
|
|
|
71
108
|
const filePath = this.path(...segments);
|
|
72
109
|
await this.fs.writeFile(filePath, JSON.stringify(data, null, 2));
|
|
73
110
|
}
|
|
111
|
+
assertSupportedVersion(version) {
|
|
112
|
+
if (version !== VCS_FORMAT_VERSION) {
|
|
113
|
+
throw new Error(`unsupported VCS format version ${version ?? "unknown"}; reinitialize the repository`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
74
116
|
}
|
|
75
117
|
export {
|
|
76
118
|
VCSStorage
|
|
77
119
|
};
|
|
78
120
|
|
|
79
|
-
//# debugId=
|
|
121
|
+
//# debugId=EA414EA422238A7C64756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/vcs/storage.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { VirtualFS } from \"../types.mjs\";\nimport type {\n HeadRef,\n BranchRef,\n RevisionCounter,\n VCSConfigFile,\n Revision,\n} from \"./types.mjs\";\n\nexport class VCSStorage {\n constructor(\n private readonly fs: VirtualFS,\n private readonly basePath: string,\n ) {}\n\n private path(...segments: string[]): string {\n return this.fs.resolve(this.basePath, ...segments);\n }\n\n // --- Init ---\n\n async isInitialized(): Promise<boolean> {\n return this.fs.exists(this.path(\"HEAD\"));\n }\n\n async initialize(defaultBranch: string = \"main\"): Promise<void> {\n await this.fs.mkdir(this.basePath, { recursive: true });\n await this.fs.mkdir(this.path(\"refs\", \"heads\"), { recursive: true });\n await this.fs.mkdir(this.path(\"revisions\"), { recursive: true });\n\n await this.writeHead({ ref: `refs/heads/${defaultBranch}` });\n await this.writeJSON([\"counter.json\"], { next: 1 } satisfies RevisionCounter);\n await this.writeJSON([\"config.json\"], { defaultBranch
|
|
5
|
+
"import type { VirtualFS } from \"../types.mjs\";\nimport type {\n HeadRef,\n BranchRef,\n RevisionCounter,\n VCSConfigFile,\n VCSIndexEntry,\n VCSIndexFile,\n Revision,\n} from \"./types.mjs\";\n\nconst VCS_FORMAT_VERSION = 2;\n\nexport class VCSStorage {\n constructor(\n private readonly fs: VirtualFS,\n private readonly basePath: string,\n ) {}\n\n private path(...segments: string[]): string {\n return this.fs.resolve(this.basePath, ...segments);\n }\n\n // --- Init ---\n\n async isInitialized(): Promise<boolean> {\n return this.fs.exists(this.path(\"HEAD\"));\n }\n\n async initialize(defaultBranch: string = \"main\"): Promise<void> {\n await this.fs.mkdir(this.basePath, { recursive: true });\n await this.fs.mkdir(this.path(\"refs\", \"heads\"), { recursive: true });\n await this.fs.mkdir(this.path(\"revisions\"), { recursive: true });\n await this.fs.mkdir(this.path(\"objects\", \"blobs\"), { recursive: true });\n await this.fs.mkdir(this.path(\"tmp\"), { recursive: true });\n\n await this.writeHead({ ref: `refs/heads/${defaultBranch}` });\n await this.writeJSON([\"counter.json\"], { next: 1 } satisfies RevisionCounter);\n await this.writeJSON([\"config.json\"], {\n version: VCS_FORMAT_VERSION,\n defaultBranch,\n } satisfies VCSConfigFile);\n await this.writeJSON([\"index.json\"], {\n version: VCS_FORMAT_VERSION,\n entries: {},\n } satisfies VCSIndexFile);\n }\n\n // --- HEAD ---\n\n async readHead(): Promise<HeadRef> {\n return this.readJSON<HeadRef>(\"HEAD\");\n }\n\n async writeHead(head: HeadRef): Promise<void> {\n await this.writeJSON([\"HEAD\"], head);\n }\n\n // --- Branches ---\n\n async readBranch(name: string): Promise<BranchRef | null> {\n const branchPath = this.path(\"refs\", \"heads\", name);\n if (!(await this.fs.exists(branchPath))) return null;\n return this.readJSON<BranchRef>(\"refs\", \"heads\", name);\n }\n\n async writeBranch(name: string, ref: BranchRef): Promise<void> {\n await this.writeJSON([\"refs\", \"heads\", name], ref);\n }\n\n async deleteBranch(name: string): Promise<void> {\n const branchPath = this.path(\"refs\", \"heads\", name);\n await this.fs.rm(branchPath);\n }\n\n async listBranches(): Promise<string[]> {\n const headsPath = this.path(\"refs\", \"heads\");\n try {\n return await this.fs.readdir(headsPath);\n } catch {\n return [];\n }\n }\n\n // --- Revisions ---\n\n async readRevision(id: number): Promise<Revision> {\n return this.readJSON<Revision>(\"revisions\", `${id}.json`);\n }\n\n async writeRevision(rev: Revision): Promise<void> {\n await this.writeJSON([\"revisions\", `${rev.id}.json`], rev);\n }\n\n // --- Counter ---\n\n async nextRevisionId(): Promise<number> {\n const counter = await this.readJSON<RevisionCounter>(\"counter.json\");\n const id = counter.next;\n await this.writeJSON([\"counter.json\"], { next: id + 1 } satisfies RevisionCounter);\n return id;\n }\n\n // --- Config ---\n\n async readConfig(): Promise<VCSConfigFile> {\n const config = await this.readJSON<VCSConfigFile>(\"config.json\");\n this.assertSupportedVersion(config.version);\n return config;\n }\n\n async assertSupportedFormat(): Promise<void> {\n await this.readConfig();\n }\n\n async readIndex(): Promise<Record<string, VCSIndexEntry>> {\n const indexPath = this.path(\"index.json\");\n if (!(await this.fs.exists(indexPath))) {\n return {};\n }\n const index = await this.readJSON<VCSIndexFile>(\"index.json\");\n this.assertSupportedVersion(index.version);\n return index.entries;\n }\n\n async writeIndex(entries: Record<string, VCSIndexEntry>): Promise<void> {\n await this.writeJSON([\"index.json\"], {\n version: VCS_FORMAT_VERSION,\n entries,\n } satisfies VCSIndexFile);\n }\n\n resolve(...segments: string[]): string {\n return this.path(...segments);\n }\n\n get fileSystem(): VirtualFS {\n return this.fs;\n }\n\n // --- Helpers ---\n\n private async readJSON<T>(...segments: string[]): Promise<T> {\n const filePath = this.path(...segments);\n const content = await this.fs.readFile(filePath, \"utf8\");\n return JSON.parse(content) as T;\n }\n\n private async writeJSON(segments: string[], data: unknown): Promise<void> {\n const filePath = this.path(...segments);\n await this.fs.writeFile(filePath, JSON.stringify(data, null, 2));\n }\n\n private assertSupportedVersion(version: number | undefined): void {\n if (version !== VCS_FORMAT_VERSION) {\n throw new Error(\n `unsupported VCS format version ${version ?? \"unknown\"}; reinitialize the repository`,\n );\n }\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAWA,IAAM,qBAAqB;AAAA;AAEpB,MAAM,WAAW;AAAA,EAEH;AAAA,EACA;AAAA,EAFnB,WAAW,CACQ,IACA,UACjB;AAAA,IAFiB;AAAA,IACA;AAAA;AAAA,EAGX,IAAI,IAAI,UAA4B;AAAA,IAC1C,OAAO,KAAK,GAAG,QAAQ,KAAK,UAAU,G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KAAK,GAAG,OAAO,SAAS,GAAI;AAAA,MACtC,OAAO,CAAC;AAAA,IACV;AAAA,IACA,MAAM,QAAQ,MAAM,KAAK,SAAuB,YAAY;AAAA,IAC5D,KAAK,uBAAuB,MAAM,OAAO;AAAA,IACzC,OAAO,MAAM;AAAA;AAAA,OAGT,WAAU,CAAC,SAAuD;AAAA,IACtE,MAAM,KAAK,UAAU,CAAC,YAAY,GAAG;AAAA,MACnC,SAAS;AAAA,MACT;AAAA,IACF,CAAwB;AAAA;AAAA,EAG1B,OAAO,IAAI,UAA4B;AAAA,IACrC,OAAO,KAAK,KAAK,GAAG,QAAQ;AAAA;AAAA,MAG1B,UAAU,GAAc;AAAA,IAC1B,OAAO,KAAK;AAAA;AAAA,OAKA,SAAW,IAAI,UAAgC;AAAA,IAC3D,MAAM,WAAW,KAAK,KAAK,GAAG,QAAQ;AAAA,IACtC,MAAM,UAAU,MAAM,KAAK,GAAG,SAAS,UAAU,MAAM;AAAA,IACvD,OAAO,KAAK,MAAM,OAAO;AAAA;AAAA,OAGb,UAAS,CAAC,UAAoB,MAA8B;AAAA,IACxE,MAAM,WAAW,KAAK,KAAK,GAAG,QAAQ;AAAA,IACtC,MAAM,KAAK,GAAG,UAAU,UAAU,KAAK,UAAU,MAAM,MAAM,CAAC,CAAC;AAAA;AAAA,EAGzD,sBAAsB,CAAC,SAAmC;AAAA,IAChE,IAAI,YAAY,oBAAoB;AAAA,MAClC,MAAM,IAAI,MACR,kCAAkC,WAAW,wCAC/C;AAAA,IACF;AAAA;AAEJ;",
|
|
8
|
+
"debugId": "EA414EA422238A7C64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// src/vcs/text-diff.ts
|
|
2
|
+
var CONTEXT_LINES = 3;
|
|
3
|
+
function createUnifiedPatch(path, previousText, nextText) {
|
|
4
|
+
if (previousText === nextText) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const previousLines = splitLines(previousText);
|
|
8
|
+
const nextLines = splitLines(nextText);
|
|
9
|
+
const operations = diffLines(previousLines, nextLines);
|
|
10
|
+
const hunks = collectHunks(operations);
|
|
11
|
+
if (hunks.length === 0) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const lines = [`--- a/${path}`, `+++ b/${path}`];
|
|
15
|
+
for (const hunk of hunks) {
|
|
16
|
+
lines.push(formatHunkHeader(operations, hunk));
|
|
17
|
+
for (let i = hunk.start;i < hunk.end; i++) {
|
|
18
|
+
const operation = operations[i];
|
|
19
|
+
const prefix = operation.type === "equal" ? " " : operation.type === "delete" ? "-" : "+";
|
|
20
|
+
lines.push(prefix + operation.line);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return lines.join(`
|
|
24
|
+
`);
|
|
25
|
+
}
|
|
26
|
+
function splitLines(text) {
|
|
27
|
+
if (!text) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const normalized = text.replace(/\r\n/g, `
|
|
31
|
+
`);
|
|
32
|
+
const parts = normalized.split(`
|
|
33
|
+
`);
|
|
34
|
+
if (normalized.endsWith(`
|
|
35
|
+
`)) {
|
|
36
|
+
parts.pop();
|
|
37
|
+
}
|
|
38
|
+
return parts;
|
|
39
|
+
}
|
|
40
|
+
function diffLines(previousLines, nextLines) {
|
|
41
|
+
const previousCount = previousLines.length;
|
|
42
|
+
const nextCount = nextLines.length;
|
|
43
|
+
const max = previousCount + nextCount;
|
|
44
|
+
const trace = [];
|
|
45
|
+
let frontier = new Map;
|
|
46
|
+
frontier.set(1, 0);
|
|
47
|
+
for (let depth = 0;depth <= max; depth++) {
|
|
48
|
+
trace.push(new Map(frontier));
|
|
49
|
+
for (let diagonal = -depth;diagonal <= depth; diagonal += 2) {
|
|
50
|
+
const nextX = frontier.get(diagonal + 1) ?? 0;
|
|
51
|
+
const prevX = frontier.get(diagonal - 1) ?? 0;
|
|
52
|
+
let x;
|
|
53
|
+
if (diagonal === -depth || diagonal !== depth && prevX < nextX) {
|
|
54
|
+
x = nextX;
|
|
55
|
+
} else {
|
|
56
|
+
x = prevX + 1;
|
|
57
|
+
}
|
|
58
|
+
let y = x - diagonal;
|
|
59
|
+
while (x < previousCount && y < nextCount && previousLines[x] === nextLines[y]) {
|
|
60
|
+
x++;
|
|
61
|
+
y++;
|
|
62
|
+
}
|
|
63
|
+
frontier.set(diagonal, x);
|
|
64
|
+
if (x >= previousCount && y >= nextCount) {
|
|
65
|
+
return backtrack(trace, previousLines, nextLines);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
function backtrack(trace, previousLines, nextLines) {
|
|
72
|
+
const operations = [];
|
|
73
|
+
let x = previousLines.length;
|
|
74
|
+
let y = nextLines.length;
|
|
75
|
+
for (let depth = trace.length - 1;depth >= 0; depth--) {
|
|
76
|
+
const frontier = trace[depth];
|
|
77
|
+
const diagonal = x - y;
|
|
78
|
+
let previousDiagonal;
|
|
79
|
+
if (diagonal === -depth || diagonal !== depth && (frontier.get(diagonal - 1) ?? 0) < (frontier.get(diagonal + 1) ?? 0)) {
|
|
80
|
+
previousDiagonal = diagonal + 1;
|
|
81
|
+
} else {
|
|
82
|
+
previousDiagonal = diagonal - 1;
|
|
83
|
+
}
|
|
84
|
+
const previousX = frontier.get(previousDiagonal) ?? 0;
|
|
85
|
+
const previousY = previousX - previousDiagonal;
|
|
86
|
+
while (x > previousX && y > previousY) {
|
|
87
|
+
operations.push({ type: "equal", line: previousLines[x - 1] });
|
|
88
|
+
x--;
|
|
89
|
+
y--;
|
|
90
|
+
}
|
|
91
|
+
if (depth === 0) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (x === previousX) {
|
|
95
|
+
operations.push({ type: "insert", line: nextLines[y - 1] });
|
|
96
|
+
y--;
|
|
97
|
+
} else {
|
|
98
|
+
operations.push({ type: "delete", line: previousLines[x - 1] });
|
|
99
|
+
x--;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
while (x > 0 && y > 0) {
|
|
103
|
+
operations.push({ type: "equal", line: previousLines[x - 1] });
|
|
104
|
+
x--;
|
|
105
|
+
y--;
|
|
106
|
+
}
|
|
107
|
+
while (x > 0) {
|
|
108
|
+
operations.push({ type: "delete", line: previousLines[x - 1] });
|
|
109
|
+
x--;
|
|
110
|
+
}
|
|
111
|
+
while (y > 0) {
|
|
112
|
+
operations.push({ type: "insert", line: nextLines[y - 1] });
|
|
113
|
+
y--;
|
|
114
|
+
}
|
|
115
|
+
return operations.reverse();
|
|
116
|
+
}
|
|
117
|
+
function collectHunks(operations) {
|
|
118
|
+
const changeRanges = [];
|
|
119
|
+
let rangeStart = null;
|
|
120
|
+
for (let index = 0;index < operations.length; index++) {
|
|
121
|
+
if (operations[index].type === "equal") {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (rangeStart === null) {
|
|
125
|
+
rangeStart = Math.max(0, index - CONTEXT_LINES);
|
|
126
|
+
}
|
|
127
|
+
let rangeEnd = Math.min(operations.length, index + CONTEXT_LINES + 1);
|
|
128
|
+
while (rangeEnd < operations.length && operations.slice(index + 1, rangeEnd).some((op) => op.type !== "equal")) {
|
|
129
|
+
rangeEnd = Math.min(operations.length, rangeEnd + CONTEXT_LINES);
|
|
130
|
+
}
|
|
131
|
+
const previousRange = changeRanges[changeRanges.length - 1];
|
|
132
|
+
if (previousRange && rangeStart <= previousRange.end) {
|
|
133
|
+
previousRange.end = Math.max(previousRange.end, rangeEnd);
|
|
134
|
+
} else {
|
|
135
|
+
changeRanges.push({ start: rangeStart, end: rangeEnd });
|
|
136
|
+
}
|
|
137
|
+
rangeStart = null;
|
|
138
|
+
}
|
|
139
|
+
return changeRanges;
|
|
140
|
+
}
|
|
141
|
+
function formatHunkHeader(operations, hunk) {
|
|
142
|
+
let oldStart = 1;
|
|
143
|
+
let newStart = 1;
|
|
144
|
+
for (let index = 0;index < hunk.start; index++) {
|
|
145
|
+
const operation = operations[index];
|
|
146
|
+
if (operation.type !== "insert") {
|
|
147
|
+
oldStart++;
|
|
148
|
+
}
|
|
149
|
+
if (operation.type !== "delete") {
|
|
150
|
+
newStart++;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
let oldCount = 0;
|
|
154
|
+
let newCount = 0;
|
|
155
|
+
for (let index = hunk.start;index < hunk.end; index++) {
|
|
156
|
+
const operation = operations[index];
|
|
157
|
+
if (operation.type !== "insert") {
|
|
158
|
+
oldCount++;
|
|
159
|
+
}
|
|
160
|
+
if (operation.type !== "delete") {
|
|
161
|
+
newCount++;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return `@@ -${formatRange(oldStart, oldCount)} +${formatRange(newStart, newCount)} @@`;
|
|
165
|
+
}
|
|
166
|
+
function formatRange(start, count) {
|
|
167
|
+
if (count === 0) {
|
|
168
|
+
return `${start - 1},0`;
|
|
169
|
+
}
|
|
170
|
+
if (count === 1) {
|
|
171
|
+
return String(start);
|
|
172
|
+
}
|
|
173
|
+
return `${start},${count}`;
|
|
174
|
+
}
|
|
175
|
+
export {
|
|
176
|
+
createUnifiedPatch
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
//# debugId=9428FE9E0FC0D7BB64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/vcs/text-diff.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"interface DiffOp {\n type: \"equal\" | \"insert\" | \"delete\";\n line: string;\n}\n\ninterface HunkRange {\n start: number;\n end: number;\n}\n\nconst CONTEXT_LINES = 3;\n\nexport function createUnifiedPatch(path: string, previousText: string, nextText: string): string | undefined {\n if (previousText === nextText) {\n return undefined;\n }\n\n const previousLines = splitLines(previousText);\n const nextLines = splitLines(nextText);\n const operations = diffLines(previousLines, nextLines);\n const hunks = collectHunks(operations);\n\n if (hunks.length === 0) {\n return undefined;\n }\n\n const lines = [`--- a/${path}`, `+++ b/${path}`];\n for (const hunk of hunks) {\n lines.push(formatHunkHeader(operations, hunk));\n for (let i = hunk.start; i < hunk.end; i++) {\n const operation = operations[i]!;\n const prefix =\n operation.type === \"equal\" ? \" \" : operation.type === \"delete\" ? \"-\" : \"+\";\n lines.push(prefix + operation.line);\n }\n }\n\n return lines.join(\"\\n\");\n}\n\nfunction splitLines(text: string): string[] {\n if (!text) {\n return [];\n }\n const normalized = text.replace(/\\r\\n/g, \"\\n\");\n const parts = normalized.split(\"\\n\");\n if (normalized.endsWith(\"\\n\")) {\n parts.pop();\n }\n return parts;\n}\n\nfunction diffLines(previousLines: string[], nextLines: string[]): DiffOp[] {\n const previousCount = previousLines.length;\n const nextCount = nextLines.length;\n const max = previousCount + nextCount;\n const trace: Map<number, number>[] = [];\n let frontier = new Map<number, number>();\n frontier.set(1, 0);\n\n for (let depth = 0; depth <= max; depth++) {\n trace.push(new Map(frontier));\n\n for (let diagonal = -depth; diagonal <= depth; diagonal += 2) {\n const nextX = frontier.get(diagonal + 1) ?? 0;\n const prevX = frontier.get(diagonal - 1) ?? 0;\n let x: number;\n\n if (diagonal === -depth || (diagonal !== depth && prevX < nextX)) {\n x = nextX;\n } else {\n x = prevX + 1;\n }\n\n let y = x - diagonal;\n while (\n x < previousCount &&\n y < nextCount &&\n previousLines[x] === nextLines[y]\n ) {\n x++;\n y++;\n }\n\n frontier.set(diagonal, x);\n\n if (x >= previousCount && y >= nextCount) {\n return backtrack(trace, previousLines, nextLines);\n }\n }\n }\n\n return [];\n}\n\nfunction backtrack(\n trace: Map<number, number>[],\n previousLines: string[],\n nextLines: string[],\n): DiffOp[] {\n const operations: DiffOp[] = [];\n let x = previousLines.length;\n let y = nextLines.length;\n\n for (let depth = trace.length - 1; depth >= 0; depth--) {\n const frontier = trace[depth]!;\n const diagonal = x - y;\n\n let previousDiagonal: number;\n if (\n diagonal === -depth ||\n (diagonal !== depth && (frontier.get(diagonal - 1) ?? 0) < (frontier.get(diagonal + 1) ?? 0))\n ) {\n previousDiagonal = diagonal + 1;\n } else {\n previousDiagonal = diagonal - 1;\n }\n\n const previousX = frontier.get(previousDiagonal) ?? 0;\n const previousY = previousX - previousDiagonal;\n\n while (x > previousX && y > previousY) {\n operations.push({ type: \"equal\", line: previousLines[x - 1]! });\n x--;\n y--;\n }\n\n if (depth === 0) {\n break;\n }\n\n if (x === previousX) {\n operations.push({ type: \"insert\", line: nextLines[y - 1]! });\n y--;\n } else {\n operations.push({ type: \"delete\", line: previousLines[x - 1]! });\n x--;\n }\n }\n\n while (x > 0 && y > 0) {\n operations.push({ type: \"equal\", line: previousLines[x - 1]! });\n x--;\n y--;\n }\n while (x > 0) {\n operations.push({ type: \"delete\", line: previousLines[x - 1]! });\n x--;\n }\n while (y > 0) {\n operations.push({ type: \"insert\", line: nextLines[y - 1]! });\n y--;\n }\n\n return operations.reverse();\n}\n\nfunction collectHunks(operations: DiffOp[]): HunkRange[] {\n const changeRanges: HunkRange[] = [];\n let rangeStart: number | null = null;\n\n for (let index = 0; index < operations.length; index++) {\n if (operations[index]!.type === \"equal\") {\n continue;\n }\n if (rangeStart === null) {\n rangeStart = Math.max(0, index - CONTEXT_LINES);\n }\n let rangeEnd = Math.min(operations.length, index + CONTEXT_LINES + 1);\n\n while (\n rangeEnd < operations.length &&\n operations.slice(index + 1, rangeEnd).some((op) => op.type !== \"equal\")\n ) {\n rangeEnd = Math.min(operations.length, rangeEnd + CONTEXT_LINES);\n }\n\n const previousRange = changeRanges[changeRanges.length - 1];\n if (previousRange && rangeStart <= previousRange.end) {\n previousRange.end = Math.max(previousRange.end, rangeEnd);\n } else {\n changeRanges.push({ start: rangeStart, end: rangeEnd });\n }\n rangeStart = null;\n }\n\n return changeRanges;\n}\n\nfunction formatHunkHeader(operations: DiffOp[], hunk: HunkRange): string {\n let oldStart = 1;\n let newStart = 1;\n\n for (let index = 0; index < hunk.start; index++) {\n const operation = operations[index]!;\n if (operation.type !== \"insert\") {\n oldStart++;\n }\n if (operation.type !== \"delete\") {\n newStart++;\n }\n }\n\n let oldCount = 0;\n let newCount = 0;\n for (let index = hunk.start; index < hunk.end; index++) {\n const operation = operations[index]!;\n if (operation.type !== \"insert\") {\n oldCount++;\n }\n if (operation.type !== \"delete\") {\n newCount++;\n }\n }\n\n return `@@ -${formatRange(oldStart, oldCount)} +${formatRange(newStart, newCount)} @@`;\n}\n\nfunction formatRange(start: number, count: number): string {\n if (count === 0) {\n return `${start - 1},0`;\n }\n if (count === 1) {\n return String(start);\n }\n return `${start},${count}`;\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAUA,IAAM,gBAAgB;AAEf,SAAS,kBAAkB,CAAC,MAAc,cAAsB,UAAsC;AAAA,EAC3G,IAAI,iBAAiB,UAAU;AAAA,IAC7B;AAAA,EACF;AAAA,EAEA,MAAM,gBAAgB,WAAW,YAAY;AAAA,EAC7C,MAAM,YAAY,WAAW,QAAQ;AAAA,EACrC,MAAM,aAAa,UAAU,eAAe,SAAS;AAAA,EACrD,MAAM,QAAQ,aAAa,UAAU;AAAA,EAErC,IAAI,MAAM,WAAW,GAAG;AAAA,IACtB;AAAA,EACF;AAAA,EAEA,MAAM,QAAQ,CAAC,SAAS,QAAQ,SAAS,MAAM;AAAA,EAC/C,WAAW,QAAQ,OAAO;AAAA,IACxB,MAAM,KAAK,iBAAiB,YAAY,IAAI,CAAC;AAAA,IAC7C,SAAS,IAAI,KAAK,MAAO,IAAI,KAAK,KAAK,KAAK;AAAA,MAC1C,MAAM,YAAY,WAAW;AAAA,MAC7B,MAAM,SACJ,UAAU,SAAS,UAAU,MAAM,UAAU,SAAS,WAAW,MAAM;AAAA,MACzE,MAAM,KAAK,SAAS,UAAU,IAAI;AAAA,IACpC;AAAA,EACF;AAAA,EAEA,OAAO,MAAM,KAAK;AAAA,CAAI;AAAA;AAGxB,SAAS,UAAU,CAAC,MAAwB;AAAA,EAC1C,IAAI,CAAC,MAAM;AAAA,IACT,OAAO,CAA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