@intra-mart/accel 0.5.0-dev.202608030656 → 0.5.0-dev.202608180918

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 (117) hide show
  1. package/README.md +103 -32
  2. package/dist/asset/deployer.d.ts +2 -0
  3. package/dist/asset/deployer.js +11 -9
  4. package/dist/asset/git-provider.d.ts +1 -0
  5. package/dist/asset/git-provider.js +20 -9
  6. package/dist/asset/updater.d.ts +9 -2
  7. package/dist/asset/updater.js +12 -6
  8. package/dist/asset/walker.d.ts +2 -1
  9. package/dist/asset/walker.js +36 -0
  10. package/dist/commands/asset-provider.d.ts +1 -1
  11. package/dist/commands/asset-provider.js +2 -2
  12. package/dist/commands/attach.d.ts +116 -82
  13. package/dist/commands/attach.js +176 -145
  14. package/dist/commands/cache.js +11 -19
  15. package/dist/commands/deploy.d.ts +53 -32
  16. package/dist/commands/deploy.js +112 -75
  17. package/dist/commands/detach.d.ts +18 -0
  18. package/dist/commands/detach.js +69 -54
  19. package/dist/commands/init.d.ts +117 -83
  20. package/dist/commands/init.js +119 -98
  21. package/dist/commands/login.d.ts +12 -10
  22. package/dist/commands/login.js +14 -10
  23. package/dist/commands/preset.d.ts +31 -0
  24. package/dist/commands/preset.js +389 -0
  25. package/dist/commands/run-wrapper.d.ts +15 -0
  26. package/dist/commands/run-wrapper.js +62 -0
  27. package/dist/commands/switch.d.ts +49 -17
  28. package/dist/commands/switch.js +206 -122
  29. package/dist/commands/update.d.ts +142 -83
  30. package/dist/commands/update.js +359 -261
  31. package/dist/core/color-env.d.ts +1 -0
  32. package/dist/core/color-env.js +6 -0
  33. package/dist/core/constants.d.ts +0 -1
  34. package/dist/core/constants.js +0 -3
  35. package/dist/core/errors.d.ts +6 -0
  36. package/dist/core/errors.js +16 -0
  37. package/dist/core/logger.d.ts +15 -0
  38. package/dist/core/logger.js +1 -0
  39. package/dist/core/paths.d.ts +6 -0
  40. package/dist/core/paths.js +22 -0
  41. package/dist/core/types.d.ts +14 -1
  42. package/dist/core/validation.d.ts +34 -0
  43. package/dist/core/validation.js +87 -0
  44. package/dist/core/validators.d.ts +2 -0
  45. package/dist/core/validators.js +7 -0
  46. package/dist/deploy/api-client.d.ts +1 -0
  47. package/dist/deploy/api-client.js +7 -1
  48. package/dist/git/config-file.d.ts +3 -0
  49. package/dist/git/config-file.js +178 -0
  50. package/dist/git/errors.d.ts +5 -0
  51. package/dist/git/errors.js +21 -2
  52. package/dist/git/git-objects.d.ts +11 -0
  53. package/dist/git/git-objects.js +49 -0
  54. package/dist/git/http.d.ts +2 -2
  55. package/dist/git/http.js +22 -10
  56. package/dist/git/index-file.d.ts +17 -0
  57. package/dist/git/index-file.js +111 -0
  58. package/dist/git/object-cache.d.ts +1 -0
  59. package/dist/git/object-cache.js +11 -15
  60. package/dist/git/object-store.d.ts +4 -0
  61. package/dist/git/object-store.js +82 -107
  62. package/dist/git/pack-parse.d.ts +19 -0
  63. package/dist/git/pack-parse.js +261 -0
  64. package/dist/git/pack-store.d.ts +20 -0
  65. package/dist/git/pack-store.js +144 -0
  66. package/dist/git/read-capped.d.ts +1 -0
  67. package/dist/git/read-capped.js +26 -0
  68. package/dist/git/redact-url.d.ts +1 -0
  69. package/dist/git/redact-url.js +14 -0
  70. package/dist/git/repo-layout.d.ts +5 -0
  71. package/dist/git/repo-layout.js +44 -0
  72. package/dist/git/smart-http.d.ts +3 -2
  73. package/dist/git/smart-http.js +5 -5
  74. package/dist/git/untracked.d.ts +11 -0
  75. package/dist/git/untracked.js +93 -0
  76. package/dist/git/worktree-status.d.ts +4 -0
  77. package/dist/git/worktree-status.js +140 -0
  78. package/dist/git/zlib-inflate.d.ts +7 -0
  79. package/dist/git/zlib-inflate.js +78 -0
  80. package/dist/i18n/en.js +47 -0
  81. package/dist/i18n/index.js +1 -1
  82. package/dist/i18n/ja.js +47 -0
  83. package/dist/i18n/zh_CN.js +47 -0
  84. package/dist/index.d.ts +1 -1
  85. package/dist/index.js +5 -2
  86. package/dist/interactive/asset-messages.d.ts +2 -1
  87. package/dist/interactive/asset-messages.js +4 -4
  88. package/dist/interactive/clack-logger.d.ts +2 -0
  89. package/dist/interactive/clack-logger.js +11 -0
  90. package/dist/interactive/credential-auth.d.ts +2 -0
  91. package/dist/interactive/credential-auth.js +7 -6
  92. package/dist/interactive/credentials-prompts.js +10 -6
  93. package/dist/interactive/next-steps.d.ts +2 -1
  94. package/dist/interactive/next-steps.js +3 -3
  95. package/dist/interactive/progress.d.ts +8 -1
  96. package/dist/interactive/progress.js +0 -0
  97. package/dist/interactive/prompts.d.ts +3 -33
  98. package/dist/interactive/prompts.js +23 -111
  99. package/dist/interactive/summary.d.ts +2 -1
  100. package/dist/interactive/summary.js +3 -3
  101. package/dist/juggling/resolve.d.ts +7 -0
  102. package/dist/juggling/resolve.js +18 -0
  103. package/dist/lib.d.ts +34 -0
  104. package/dist/lib.js +29 -0
  105. package/dist/utils/args.d.ts +4 -1
  106. package/dist/utils/args.js +26 -3
  107. package/dist/utils/githooks-sync.d.ts +3 -1
  108. package/dist/utils/githooks-sync.js +37 -37
  109. package/dist/utils/mcp-generate.d.ts +26 -0
  110. package/dist/utils/mcp-generate.js +313 -0
  111. package/dist/utils/preset-io.d.ts +24 -0
  112. package/dist/utils/preset-io.js +167 -0
  113. package/dist/utils/settings-io.d.ts +2 -0
  114. package/dist/utils/settings-io.js +2 -2
  115. package/package.json +20 -13
  116. package/dist/utils/mcp-sync.d.ts +0 -4
  117. package/dist/utils/mcp-sync.js +0 -103
package/dist/git/http.js CHANGED
@@ -1,45 +1,56 @@
1
1
  import { fetch as undiciFetch, EnvHttpProxyAgent } from "undici";
2
- import { createGitAuthError } from "./errors.js";
2
+ import { createGitAuthError, createGitProxyError, hasProxyConnectionCause, } from "./errors.js";
3
+ import { redactUrlCredentials } from "./redact-url.js";
4
+ import { sanitizeDisplayText } from "../utils/sanitize-text.js";
3
5
  let dispatcher = null;
4
6
  const getDispatcher = () => {
5
7
  dispatcher ??= new EnvHttpProxyAgent();
6
8
  return dispatcher;
7
9
  };
8
10
  export const normalizeRepoUrl = (url) => url.replace(/\/+$/, "");
11
+ const identifyProxyFailure = (err, url) => {
12
+ if (hasProxyConnectionCause(err)) {
13
+ throw createGitProxyError(url, err);
14
+ }
15
+ throw err;
16
+ };
9
17
  const MAX_RESPONSE_BYTES = 256 * 1024 * 1024;
10
18
  const ensureOk = (status, url, body) => {
11
19
  if (status === 401 || status === 403) {
12
20
  throw createGitAuthError(status, url);
13
21
  }
14
- throw new Error(`HTTP ${status} from ${url}${body ? `: ${body.slice(0, 200)}` : ""}`);
22
+ const detail = sanitizeDisplayText(body.slice(0, 200));
23
+ throw new Error(`HTTP ${status} from ${redactUrlCredentials(url)}${detail ? `: ${detail}` : ""}`);
15
24
  };
16
- const readBody = async (res, url) => {
25
+ const readBody = async (res, url, signal) => {
17
26
  if (!res.body)
18
27
  return Buffer.alloc(0);
19
28
  const chunks = [];
20
29
  let total = 0;
21
30
  for await (const chunk of res.body) {
31
+ signal?.throwIfAborted();
22
32
  const buf = Buffer.from(chunk);
23
33
  total += buf.length;
24
34
  if (total > MAX_RESPONSE_BYTES) {
25
- throw new Error(`Response from ${url} exceeded the maximum allowed size (${MAX_RESPONSE_BYTES} bytes)`);
35
+ throw new Error(`Response from ${redactUrlCredentials(url)} exceeded the maximum allowed size (${MAX_RESPONSE_BYTES} bytes)`);
26
36
  }
27
37
  chunks.push(buf);
28
38
  }
29
39
  return Buffer.concat(chunks);
30
40
  };
31
- export const getInfoRefs = async (repoUrl) => {
41
+ export const getInfoRefs = async (repoUrl, signal) => {
32
42
  const url = `${normalizeRepoUrl(repoUrl)}/info/refs?service=git-upload-pack`;
33
43
  const res = await undiciFetch(url, {
34
44
  headers: { "Git-Protocol": "version=2" },
35
45
  dispatcher: getDispatcher(),
36
- });
46
+ signal,
47
+ }).catch((err) => identifyProxyFailure(err, url));
37
48
  if (!res.ok) {
38
49
  ensureOk(res.status, url, await res.text().catch(() => ""));
39
50
  }
40
- return readBody(res, url);
51
+ return readBody(res, url, signal);
41
52
  };
42
- export const postUploadPack = async (repoUrl, body) => {
53
+ export const postUploadPack = async (repoUrl, body, signal) => {
43
54
  const url = `${normalizeRepoUrl(repoUrl)}/git-upload-pack`;
44
55
  const res = await undiciFetch(url, {
45
56
  method: "POST",
@@ -50,9 +61,10 @@ export const postUploadPack = async (repoUrl, body) => {
50
61
  },
51
62
  body,
52
63
  dispatcher: getDispatcher(),
53
- });
64
+ signal,
65
+ }).catch((err) => identifyProxyFailure(err, url));
54
66
  if (!res.ok) {
55
67
  ensureOk(res.status, url, await res.text().catch(() => ""));
56
68
  }
57
- return readBody(res, url);
69
+ return readBody(res, url, signal);
58
70
  };
@@ -0,0 +1,17 @@
1
+ export type IndexEntry = {
2
+ path: string;
3
+ mode: number;
4
+ size: number;
5
+ mtimeSec: number;
6
+ mtimeNsec: number;
7
+ oid: string;
8
+ stage: number;
9
+ assumeValid: boolean;
10
+ skipWorktree: boolean;
11
+ intentToAdd: boolean;
12
+ };
13
+ export type GitIndex = {
14
+ entries: IndexEntry[];
15
+ indexMtimeSec: number;
16
+ };
17
+ export declare const readGitIndex: (gitDir: string) => Promise<GitIndex | null>;
@@ -0,0 +1,111 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFile, stat } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ const HEADER_SIZE = 12;
5
+ const CHECKSUM_SIZE = 20;
6
+ const FIXED_ENTRY_SIZE = 62;
7
+ const parseIndex = (buf, indexMtimeSec) => {
8
+ if (buf.length < HEADER_SIZE + CHECKSUM_SIZE)
9
+ return null;
10
+ if (buf.toString("latin1", 0, 4) !== "DIRC")
11
+ return null;
12
+ const version = buf.readUInt32BE(4);
13
+ if (version !== 2 && version !== 3)
14
+ return null;
15
+ const entryCount = buf.readUInt32BE(8);
16
+ const dataEnd = buf.length - CHECKSUM_SIZE;
17
+ const checksum = createHash("sha1").update(buf.subarray(0, dataEnd)).digest();
18
+ if (!checksum.equals(buf.subarray(dataEnd)))
19
+ return null;
20
+ const entries = [];
21
+ let pos = HEADER_SIZE;
22
+ for (let i = 0; i < entryCount; i++) {
23
+ if (pos + FIXED_ENTRY_SIZE > dataEnd)
24
+ return null;
25
+ const mtimeSec = buf.readUInt32BE(pos + 8);
26
+ const mtimeNsec = buf.readUInt32BE(pos + 12);
27
+ const mode = buf.readUInt32BE(pos + 24);
28
+ const size = buf.readUInt32BE(pos + 36);
29
+ const oid = buf.toString("hex", pos + 40, pos + 60);
30
+ const flags = buf.readUInt16BE(pos + 60);
31
+ const assumeValid = (flags & 0x8000) !== 0;
32
+ const extended = (flags & 0x4000) !== 0;
33
+ const stage = (flags >> 12) & 0x3;
34
+ if (extended && version === 2)
35
+ return null;
36
+ let skipWorktree = false;
37
+ let intentToAdd = false;
38
+ let fixedSize = FIXED_ENTRY_SIZE;
39
+ if (extended) {
40
+ if (pos + FIXED_ENTRY_SIZE + 2 > dataEnd)
41
+ return null;
42
+ const flags2 = buf.readUInt16BE(pos + FIXED_ENTRY_SIZE);
43
+ skipWorktree = (flags2 & 0x4000) !== 0;
44
+ intentToAdd = (flags2 & 0x2000) !== 0;
45
+ fixedSize += 2;
46
+ }
47
+ const nameStart = pos + fixedSize;
48
+ const nameLenField = flags & 0x0fff;
49
+ let nameEnd;
50
+ if (nameLenField < 0x0fff) {
51
+ nameEnd = nameStart + nameLenField;
52
+ if (nameEnd > dataEnd)
53
+ return null;
54
+ }
55
+ else {
56
+ nameEnd = buf.indexOf(0, nameStart);
57
+ if (nameEnd === -1 || nameEnd > dataEnd)
58
+ return null;
59
+ }
60
+ const path = buf.toString("utf-8", nameStart, nameEnd);
61
+ entries.push({
62
+ path,
63
+ mode,
64
+ size,
65
+ mtimeSec,
66
+ mtimeNsec,
67
+ oid,
68
+ stage,
69
+ assumeValid,
70
+ skipWorktree,
71
+ intentToAdd,
72
+ });
73
+ const nameLen = nameEnd - nameStart;
74
+ pos += Math.ceil((fixedSize + nameLen + 1) / 8) * 8;
75
+ }
76
+ while (pos < dataEnd) {
77
+ if (pos + 8 > dataEnd)
78
+ return null;
79
+ const signature = buf.toString("latin1", pos, pos + 4);
80
+ const firstChar = signature.charCodeAt(0);
81
+ if (firstChar >= 0x61 && firstChar <= 0x7a)
82
+ return null;
83
+ const size = buf.readUInt32BE(pos + 4);
84
+ pos += 8 + size;
85
+ if (pos > dataEnd)
86
+ return null;
87
+ }
88
+ return { entries, indexMtimeSec };
89
+ };
90
+ export const readGitIndex = async (gitDir) => {
91
+ const indexPath = join(gitDir, "index");
92
+ let buf;
93
+ let indexMtimeSec;
94
+ try {
95
+ const stats = await stat(indexPath);
96
+ indexMtimeSec = Math.floor(stats.mtimeMs / 1000);
97
+ buf = await readFile(indexPath);
98
+ }
99
+ catch (err) {
100
+ if (err.code === "ENOENT") {
101
+ return { entries: [], indexMtimeSec: 0 };
102
+ }
103
+ return null;
104
+ }
105
+ try {
106
+ return parseIndex(buf, indexMtimeSec);
107
+ }
108
+ catch {
109
+ return null;
110
+ }
111
+ };
@@ -10,3 +10,4 @@ export type CacheRepoEntry = {
10
10
  };
11
11
  export declare const directorySize: (dir: string) => Promise<number>;
12
12
  export declare const listCacheRepos: (cacheRoot: string) => Promise<CacheRepoEntry[]>;
13
+ export declare const clearCacheRepos: (cacheRoot: string) => Promise<number>;
@@ -1,25 +1,13 @@
1
1
  import { randomBytes } from "node:crypto";
2
- import { lstat, mkdir, readdir, readFile, rename, stat, writeFile, } from "node:fs/promises";
2
+ import { lstat, mkdir, readdir, readFile, rename, rm, stat, writeFile, } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import { join, resolve } from "node:path";
5
5
  import { computeSha256 } from "../utils/hash.js";
6
+ import { redactUrlCredentials } from "./redact-url.js";
6
7
  const REPOS_DIR = "repos";
7
8
  const URL_SIDECAR = "url";
8
9
  const STORE_KEY_PATTERN = /^[0-9a-f]{16}$/;
9
- export const normalizeRepoUrl = (url) => {
10
- let normalized = url.replace(/\/+$/, "").replace(/\.git$/, "");
11
- try {
12
- const parsed = new URL(normalized);
13
- if (parsed.username || parsed.password) {
14
- parsed.username = "";
15
- parsed.password = "";
16
- normalized = parsed.toString().replace(/\/+$/, "");
17
- }
18
- }
19
- catch {
20
- }
21
- return normalized;
22
- };
10
+ export const normalizeRepoUrl = (url) => redactUrlCredentials(url.replace(/\/+$/, "").replace(/\.git$/, "")).replace(/\/+$/, "");
23
11
  export const resolveCacheRoot = (env = process.env) => {
24
12
  const override = env["ACCEL_CACHE_DIR"];
25
13
  if (override && override.trim() !== "")
@@ -93,3 +81,11 @@ export const listCacheRepos = async (cacheRoot) => {
93
81
  }
94
82
  return entries;
95
83
  };
84
+ export const clearCacheRepos = async (cacheRoot) => {
85
+ const reposDir = cacheReposDir(cacheRoot);
86
+ const size = await directorySize(reposDir);
87
+ if (size === 0)
88
+ return 0;
89
+ await rm(reposDir, { recursive: true, force: true });
90
+ return size;
91
+ };
@@ -14,4 +14,8 @@ export type ObjectStore = {
14
14
  };
15
15
  export declare const createObjectStore: (options?: {
16
16
  dir?: string;
17
+ walkLimits?: {
18
+ maxDepth?: number;
19
+ maxVisits?: number;
20
+ };
17
21
  }) => Promise<ObjectStore>;
@@ -1,53 +1,33 @@
1
- import fs from "node:fs";
2
1
  import { randomBytes } from "node:crypto";
3
- import { mkdtemp, mkdir, readdir, readFile, rename, rm, writeFile, } from "node:fs/promises";
2
+ import { mkdtemp, mkdir, rm } from "node:fs/promises";
4
3
  import { tmpdir } from "node:os";
5
4
  import { join } from "node:path";
6
- import git, { Errors } from "isomorphic-git";
7
- import { createGitObjectMissingError } from "./errors.js";
8
- const topSegmentOf = (filepath) => {
9
- const slash = filepath.indexOf("/");
10
- return slash === -1 ? filepath : filepath.slice(0, slash);
11
- };
5
+ import { createGitObjectMissingError, createGitPackCorruptError, } from "./errors.js";
6
+ import { commitTreeOid, isGitlinkMode, isTreeMode, parseTree, } from "./git-objects.js";
7
+ import { parsePack } from "./pack-parse.js";
8
+ import { openPackStore } from "./pack-store.js";
9
+ const sanitizeLabel = (label) => label.replace(/[^A-Za-z0-9.-]/g, "");
10
+ const MAX_TREE_DEPTH = 1024;
11
+ const MAX_TREE_VISITS = 500_000;
12
12
  export const createObjectStore = async (options = {}) => {
13
+ const maxTreeDepth = options.walkLimits?.maxDepth ?? MAX_TREE_DEPTH;
14
+ const maxTreeVisits = options.walkLimits?.maxVisits ?? MAX_TREE_VISITS;
13
15
  const persistent = options.dir !== undefined;
14
16
  const dir = options.dir ?? (await mkdtemp(join(tmpdir(), "accel-assets-")));
15
- const packDir = join(dir, ".git", "objects", "pack");
16
17
  if (persistent) {
17
18
  await mkdir(dir, { recursive: true, mode: 0o700 });
19
+ await rm(join(dir, ".git"), { recursive: true, force: true }).catch(() => { });
18
20
  }
19
- if (!fs.existsSync(join(dir, ".git", "config"))) {
20
- await git.init({ fs, dir, defaultBranch: "main" });
21
- }
22
- await mkdir(packDir, { recursive: true });
21
+ const packStore = await openPackStore(dir);
23
22
  const storeUid = `${process.pid.toString(36)}-${randomBytes(4).toString("hex")}`;
24
23
  let packSeq = 0;
25
- const cache = {};
26
24
  const indexByCommit = new Map();
27
- const knownOids = new Set();
28
- if (persistent) {
29
- const names = await readdir(packDir).catch(() => []);
30
- for (const name of names) {
31
- if (!name.endsWith(".oids"))
32
- continue;
33
- try {
34
- const content = await readFile(join(packDir, name), "utf-8");
35
- for (const line of content.split("\n")) {
36
- if (line.length === 40)
37
- knownOids.add(line);
38
- }
39
- }
40
- catch {
41
- }
42
- }
43
- }
44
25
  const indexOf = (commitOid) => {
45
26
  let index = indexByCommit.get(commitOid);
46
27
  if (!index) {
47
28
  index = {
48
29
  oidByPath: new Map(),
49
- entries: [],
50
- rootDirs: new Set(),
30
+ rootDirOids: new Map(),
51
31
  rootHierarchyWalked: false,
52
32
  walkedDirs: new Set(),
53
33
  fullyWalked: false,
@@ -57,37 +37,62 @@ export const createObjectStore = async (options = {}) => {
57
37
  return index;
58
38
  };
59
39
  const addBlob = (index, path, oid) => {
60
- if (index.oidByPath.has(path))
61
- return;
62
- index.oidByPath.set(path, oid);
63
- index.entries.push({ path, oid });
40
+ if (!index.oidByPath.has(path))
41
+ index.oidByPath.set(path, oid);
42
+ };
43
+ const entriesOf = (index) => [...index.oidByPath].map(([path, oid]) => ({ path, oid }));
44
+ const readObjectOrThrow = async (oid, context) => {
45
+ const obj = await packStore.readObject(oid);
46
+ if (obj === undefined)
47
+ throw createGitObjectMissingError(context, oid);
48
+ return obj;
49
+ };
50
+ const walkTree = async (index, treeOid, prefix, depth, budget) => {
51
+ if (depth > maxTreeDepth) {
52
+ throw createGitPackCorruptError(`tree depth exceeds limit (${depth})`);
53
+ }
54
+ if (--budget.visits < 0) {
55
+ throw createGitPackCorruptError("tree walk exceeds visit limit");
56
+ }
57
+ const { data } = await readObjectOrThrow(treeOid, prefix || "<root>");
58
+ for (const entry of parseTree(data)) {
59
+ if (isGitlinkMode(entry.mode))
60
+ continue;
61
+ const path = prefix === "" ? entry.name : `${prefix}/${entry.name}`;
62
+ if (isTreeMode(entry.mode)) {
63
+ await walkTree(index, entry.oid, path, depth + 1, budget);
64
+ }
65
+ else {
66
+ addBlob(index, path, entry.oid);
67
+ }
68
+ }
69
+ };
70
+ const rootTreeOidOf = async (commitOid) => {
71
+ const commit = await readObjectOrThrow(commitOid, "<commit>");
72
+ return commitTreeOid(commit.data);
64
73
  };
65
74
  const ensureRootHierarchy = async (commitOid) => {
66
75
  const index = indexOf(commitOid);
67
76
  if (index.rootHierarchyWalked)
68
77
  return index;
69
- await git.walk({
70
- fs,
71
- dir,
72
- cache,
73
- trees: [git.TREE({ ref: commitOid })],
74
- map: async (filepath, [entry]) => {
75
- if (!entry || filepath === ".")
76
- return undefined;
77
- const type = await entry.type();
78
- if (type === "blob") {
79
- addBlob(index, filepath, await entry.oid());
80
- return undefined;
81
- }
82
- if (type !== "tree")
83
- return null;
84
- if (filepath.indexOf("/") === -1) {
85
- index.rootDirs.add(filepath);
86
- return undefined;
78
+ const rootTree = await readObjectOrThrow(await rootTreeOidOf(commitOid), "<root>");
79
+ for (const entry of parseTree(rootTree.data)) {
80
+ if (isGitlinkMode(entry.mode))
81
+ continue;
82
+ if (isTreeMode(entry.mode)) {
83
+ index.rootDirOids.set(entry.name, entry.oid);
84
+ const sub = await readObjectOrThrow(entry.oid, entry.name);
85
+ for (const subEntry of parseTree(sub.data)) {
86
+ if (isGitlinkMode(subEntry.mode) || isTreeMode(subEntry.mode)) {
87
+ continue;
88
+ }
89
+ addBlob(index, `${entry.name}/${subEntry.name}`, subEntry.oid);
87
90
  }
88
- return null;
89
- },
90
- });
91
+ }
92
+ else {
93
+ addBlob(index, entry.name, entry.oid);
94
+ }
95
+ }
91
96
  index.rootHierarchyWalked = true;
92
97
  return index;
93
98
  };
@@ -97,47 +102,35 @@ export const createObjectStore = async (options = {}) => {
97
102
  for (const name of dirNames) {
98
103
  if (index.fullyWalked || index.walkedDirs.has(name))
99
104
  continue;
100
- if (index.rootDirs.has(name))
105
+ if (index.rootDirOids.has(name))
101
106
  pending.add(name);
107
+ else
108
+ index.walkedDirs.add(name);
109
+ }
110
+ const budget = { visits: maxTreeVisits };
111
+ for (const name of pending) {
112
+ await walkTree(index, index.rootDirOids.get(name), name, 1, budget);
102
113
  index.walkedDirs.add(name);
103
114
  }
104
- if (pending.size === 0)
105
- return index;
106
- await git.walk({
107
- fs,
108
- dir,
109
- cache,
110
- trees: [git.TREE({ ref: commitOid })],
111
- map: async (filepath, [entry]) => {
112
- if (!entry || filepath === ".")
113
- return undefined;
114
- if (!pending.has(topSegmentOf(filepath)))
115
- return null;
116
- if ((await entry.type()) === "blob") {
117
- addBlob(index, filepath, await entry.oid());
118
- }
119
- return undefined;
120
- },
121
- });
122
115
  return index;
123
116
  };
124
117
  const normalizeDirName = (name) => name.replace(/\/+$/, "");
125
118
  const listRootBlobEntries = async (commitOid) => {
126
119
  const index = await ensureRootHierarchy(commitOid);
127
- return index.entries.filter((e) => e.path.split("/").length <= 2);
120
+ return entriesOf(index).filter((e) => e.path.split("/").length <= 2);
128
121
  };
129
122
  const listBlobEntries = async (commitOid, underDirs) => {
130
123
  let index = await ensureRootHierarchy(commitOid);
131
124
  if (underDirs === undefined) {
132
125
  if (!index.fullyWalked) {
133
- index = await ensureDirsWalked(commitOid, index.rootDirs);
126
+ index = await ensureDirsWalked(commitOid, index.rootDirOids.keys());
134
127
  index.fullyWalked = true;
135
128
  }
136
129
  }
137
130
  else {
138
131
  index = await ensureDirsWalked(commitOid, underDirs.map(normalizeDirName));
139
132
  }
140
- return index.entries;
133
+ return entriesOf(index);
141
134
  };
142
135
  const getBlobOid = async (commitOid, filepath) => {
143
136
  const index = await ensureRootHierarchy(commitOid);
@@ -154,23 +147,9 @@ export const createObjectStore = async (options = {}) => {
154
147
  return {
155
148
  dir,
156
149
  writePack: async (pack, label) => {
157
- const name = `pack-${label}-${storeUid}-${packSeq++}`;
158
- const stagingRel = join(".git", "objects", "accel-tmp", name);
159
- const stagingDir = join(dir, stagingRel);
160
- await mkdir(stagingDir, { recursive: true });
161
- await writeFile(join(stagingDir, `${name}.pack`), pack);
162
- const { oids } = await git.indexPack({
163
- fs,
164
- dir,
165
- filepath: join(stagingRel, `${name}.pack`),
166
- });
167
- await writeFile(join(stagingDir, `${name}.oids`), oids.join("\n") + "\n", "utf-8");
168
- for (const ext of [".pack", ".idx", ".oids"]) {
169
- await rename(join(stagingDir, `${name}${ext}`), join(packDir, `${name}${ext}`));
170
- }
171
- await rm(stagingDir, { recursive: true, force: true }).catch(() => { });
172
- for (const oid of oids)
173
- knownOids.add(oid);
150
+ const name = `pack-${sanitizeLabel(label)}-${storeUid}-${packSeq++}`;
151
+ const { objects } = await parsePack(pack);
152
+ await packStore.writeObjects(name, objects);
174
153
  },
175
154
  listRootBlobEntries,
176
155
  listBlobEntries,
@@ -180,19 +159,15 @@ export const createObjectStore = async (options = {}) => {
180
159
  if (blobOid === undefined) {
181
160
  throw new Error(`File not found in commit ${commitOid}: ${filepath}`);
182
161
  }
183
- try {
184
- const { blob } = await git.readBlob({ fs, dir, cache, oid: blobOid });
185
- return Buffer.from(blob).toString("utf-8");
186
- }
187
- catch (err) {
188
- if (err instanceof Errors.NotFoundError) {
189
- throw createGitObjectMissingError(filepath, blobOid);
190
- }
191
- throw err;
162
+ const obj = await packStore.readObject(blobOid);
163
+ if (obj === undefined) {
164
+ throw createGitObjectMissingError(filepath, blobOid);
192
165
  }
166
+ return obj.data.toString("utf-8");
193
167
  },
194
- hasObject: (oid) => knownOids.has(oid),
168
+ hasObject: (oid) => packStore.hasObject(oid),
195
169
  cleanup: async () => {
170
+ packStore.clearCache();
196
171
  if (!persistent) {
197
172
  await rm(dir, { recursive: true, force: true }).catch(() => { });
198
173
  }
@@ -0,0 +1,19 @@
1
+ export declare const OBJ_COMMIT = 1;
2
+ export declare const OBJ_TREE = 2;
3
+ export declare const OBJ_BLOB = 3;
4
+ export declare const OBJ_TAG = 4;
5
+ export type PackedObject = {
6
+ oid: string;
7
+ type: number;
8
+ data: Buffer;
9
+ };
10
+ export type ParsedPack = {
11
+ objects: PackedObject[];
12
+ deltaCounts: {
13
+ ofs: number;
14
+ ref: number;
15
+ };
16
+ };
17
+ export declare const oidOfObject: (type: number, data: Buffer) => string;
18
+ export declare const applyDelta: (base: Buffer, delta: Buffer) => Buffer;
19
+ export declare const parsePack: (pack: Buffer) => Promise<ParsedPack>;