git-fs-s3 0.3.6 → 0.3.8

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/dist/ops.d.ts CHANGED
@@ -14,6 +14,18 @@ interface Branch {
14
14
  * actually called, not just at an API boundary far above.
15
15
  */
16
16
  declare function assertSafeBranchName(name: string): void;
17
+ /**
18
+ * Resolve a fully-qualified ref's oid with one read instead of isomorphic-
19
+ * git's own `resolveRef`, which does a stat *then* a read for a loose ref
20
+ * (two round trips against object storage) — wasteful specifically here,
21
+ * where the caller already knows the ref exists (it came from a directory
22
+ * listing moments earlier). Reads the loose file directly and falls back to
23
+ * `git.resolveRef` only when that doesn't pan out (packed-refs, or anything
24
+ * else the plain-loose-file assumption doesn't cover), so correctness for
25
+ * those cases is unchanged — this only removes the redundant round trip on
26
+ * the common path.
27
+ */
28
+ declare function resolveLooseRefFast(repo: Repo, ref: string): Promise<string>;
17
29
  /** All branches with their tip commits; [] for an empty repository. */
18
30
  declare function listBranches(repo: Repo): Promise<Branch[]>;
19
31
  /** Create `name` pointing at the tip of `startPoint` (no checkout). */
@@ -287,4 +299,4 @@ declare function fastForwardMerge(repo: Repo, sourceBranch: string, targetBranch
287
299
  commitSha: string;
288
300
  } | null>;
289
301
 
290
- export { BANNER_WALK_DEPTH, type Branch, type CommitAuthor, type CommitInfo, type CommitLogOptions, type DiffFile, type DiffResult, type FileHistoryEntry, type FileHistoryResult, HISTORY_WALK_DEPTH, type LastCommitInfo, type MergeAnalysis, OpsHooks, Repo, type TreeEntry, analyzeMerge, assertBranchExists, assertSafeBranchName, authorNow, commitFilesToBare, createBranchFrom, deleteBranchByName, deleteFileFromBare, deleteFromTree, fastForwardMerge, findTreeEntry, getBlob, getCommit, getCommitDiff, getCommitHistory, getCommitLog, getDiffBetweenRefs, getFileContent, getFileFromRef, getFileHistory, getLastCommitsForTree, getTreeFromRef, listBranches, listTreeEntries, resolveCommit, upsertTree, writeCommitToBare };
302
+ export { BANNER_WALK_DEPTH, type Branch, type CommitAuthor, type CommitInfo, type CommitLogOptions, type DiffFile, type DiffResult, type FileHistoryEntry, type FileHistoryResult, HISTORY_WALK_DEPTH, type LastCommitInfo, type MergeAnalysis, OpsHooks, Repo, type TreeEntry, analyzeMerge, assertBranchExists, assertSafeBranchName, authorNow, commitFilesToBare, createBranchFrom, deleteBranchByName, deleteFileFromBare, deleteFromTree, fastForwardMerge, findTreeEntry, getBlob, getCommit, getCommitDiff, getCommitHistory, getCommitLog, getDiffBetweenRefs, getFileContent, getFileFromRef, getFileHistory, getLastCommitsForTree, getTreeFromRef, listBranches, listTreeEntries, resolveCommit, resolveLooseRefFast, upsertTree, writeCommitToBare };
package/dist/ops.js CHANGED
@@ -1,68 +1,29 @@
1
1
  import {
2
- GitInvalidRequestError,
3
- GitObjectNotFoundError,
4
- GitPathNotFoundError
5
- } from "./chunk-T5NHPY7U.js";
2
+ assertBranchExists,
3
+ assertSafeBranchName,
4
+ createBranchFrom,
5
+ deleteBranchByName,
6
+ listBranches,
7
+ resolveLooseRefFast
8
+ } from "./chunk-H7IGQRIA.js";
6
9
  import {
10
+ GitObjectNotFoundError,
11
+ GitPathNotFoundError,
7
12
  decodeUtf8,
8
13
  hasNullByte,
9
- isSafeBranchName,
10
14
  qualifyBranchRef,
11
15
  readBlobContent,
12
16
  toBase64
13
- } from "./chunk-RUE2NR43.js";
14
-
15
- // src/ops/branch.ts
16
- import git from "isomorphic-git";
17
- function assertSafeBranchName(name) {
18
- if (!isSafeBranchName(name)) {
19
- throw new GitInvalidRequestError(`Invalid branch name: ${name}`);
20
- }
21
- }
22
- async function listBranches(repo) {
23
- try {
24
- const [branches, currentBranch] = await Promise.all([
25
- git.listBranches(repo),
26
- git.currentBranch({ ...repo, fullname: false }).catch(() => null)
27
- ]);
28
- return Promise.all(
29
- branches.map(async (branch) => ({
30
- name: branch,
31
- commit: await git.resolveRef({ ...repo, ref: `refs/heads/${branch}` }),
32
- isDefault: branch === currentBranch
33
- }))
34
- );
35
- } catch (err) {
36
- if (err.code === "NotFoundError") return [];
37
- throw err;
38
- }
39
- }
40
- async function createBranchFrom(repo, name, startPoint = "main") {
41
- assertSafeBranchName(name);
42
- assertSafeBranchName(startPoint);
43
- const object = await git.resolveRef({
44
- ...repo,
45
- ref: `refs/heads/${startPoint}`
46
- });
47
- await git.branch({ ...repo, ref: name, checkout: false, object });
48
- }
49
- async function deleteBranchByName(repo, name) {
50
- assertSafeBranchName(name);
51
- await git.deleteBranch({ ...repo, ref: name });
52
- }
53
- async function assertBranchExists(repo, name) {
54
- assertSafeBranchName(name);
55
- await git.resolveRef({ ...repo, ref: `refs/heads/${name}` });
56
- }
17
+ } from "./chunk-YQFNY6PG.js";
57
18
 
58
19
  // src/ops/commit.ts
59
- import git3 from "isomorphic-git";
20
+ import git2 from "isomorphic-git";
60
21
 
61
22
  // src/ops/tree.ts
62
- import git2 from "isomorphic-git";
23
+ import git from "isomorphic-git";
63
24
  var joinPath = (prefix, name) => prefix ? `${prefix.replace(/\/+$/, "")}/${name}` : name;
64
25
  async function upsertTree(repo, treeOid, entries) {
65
- const existing = treeOid ? (await git2.readTree({ ...repo, oid: treeOid })).tree : [];
26
+ const existing = treeOid ? (await git.readTree({ ...repo, oid: treeOid })).tree : [];
66
27
  const byName = new Map(existing.map((e) => [e.path, e]));
67
28
  const direct = /* @__PURE__ */ new Map();
68
29
  const nested = /* @__PURE__ */ new Map();
@@ -96,10 +57,10 @@ async function upsertTree(repo, treeOid, entries) {
96
57
  for (const [dir, newOid] of nestedResults) {
97
58
  byName.set(dir, { mode: "040000", path: dir, oid: newOid, type: "tree" });
98
59
  }
99
- return git2.writeTree({ ...repo, tree: Array.from(byName.values()) });
60
+ return git.writeTree({ ...repo, tree: Array.from(byName.values()) });
100
61
  }
101
62
  async function deleteFromTree(repo, treeOid, filePath) {
102
- const existing = (await git2.readTree({ ...repo, oid: treeOid })).tree;
63
+ const existing = (await git.readTree({ ...repo, oid: treeOid })).tree;
103
64
  const byName = new Map(existing.map((e) => [e.path, e]));
104
65
  const slash = filePath.indexOf("/");
105
66
  if (slash === -1) {
@@ -113,7 +74,7 @@ async function deleteFromTree(repo, treeOid, filePath) {
113
74
  byName.set(dir, { ...entry, oid: newOid });
114
75
  }
115
76
  }
116
- return git2.writeTree({ ...repo, tree: Array.from(byName.values()) });
77
+ return git.writeTree({ ...repo, tree: Array.from(byName.values()) });
117
78
  }
118
79
  async function findTreeEntry(repo, rootTreeOid, treePath) {
119
80
  if (!treePath) {
@@ -123,7 +84,7 @@ async function findTreeEntry(repo, rootTreeOid, treePath) {
123
84
  let currentTreeOid = rootTreeOid;
124
85
  let currentPath = "";
125
86
  for (const [index, part] of parts.entries()) {
126
- const tree = await git2.readTree({ ...repo, oid: currentTreeOid });
87
+ const tree = await git.readTree({ ...repo, oid: currentTreeOid });
127
88
  const entry = tree.tree.find((candidate) => candidate.path === part);
128
89
  if (!entry) return null;
129
90
  currentPath = currentPath ? joinPath(currentPath, entry.path) : entry.path;
@@ -141,7 +102,7 @@ async function findTreeEntry(repo, rootTreeOid, treePath) {
141
102
  return null;
142
103
  }
143
104
  async function listTreeEntries(repo, treeOid, prefix = "") {
144
- const tree = await git2.readTree({ ...repo, oid: treeOid });
105
+ const tree = await git.readTree({ ...repo, oid: treeOid });
145
106
  return tree.tree.map((entry) => ({
146
107
  path: prefix ? joinPath(prefix, entry.path) : entry.path,
147
108
  mode: entry.mode,
@@ -164,11 +125,11 @@ async function writeCommitToBare(repo, options) {
164
125
  let parentOid;
165
126
  let parentTreeOid;
166
127
  try {
167
- parentOid = await git3.resolveRef({
128
+ parentOid = await git2.resolveRef({
168
129
  ...repo,
169
130
  ref: `refs/heads/${options.branch}`
170
131
  });
171
- const { commit } = await git3.readCommit({ ...repo, oid: parentOid });
132
+ const { commit } = await git2.readCommit({ ...repo, oid: parentOid });
172
133
  parentTreeOid = commit.tree;
173
134
  } catch (err) {
174
135
  if (err?.code !== "NotFoundError") {
@@ -176,7 +137,7 @@ async function writeCommitToBare(repo, options) {
176
137
  }
177
138
  }
178
139
  const treeOid = await options.buildTree(parentTreeOid);
179
- const commitOid = await git3.writeCommit({
140
+ const commitOid = await git2.writeCommit({
180
141
  ...repo,
181
142
  commit: {
182
143
  message: options.message,
@@ -186,7 +147,7 @@ async function writeCommitToBare(repo, options) {
186
147
  committer: options.author
187
148
  }
188
149
  });
189
- await git3.writeRef({
150
+ await git2.writeRef({
190
151
  ...repo,
191
152
  ref: `refs/heads/${options.branch}`,
192
153
  value: commitOid,
@@ -204,7 +165,7 @@ function commitFilesToBare(repo, options) {
204
165
  await Promise.all(
205
166
  options.files.map(async (file) => {
206
167
  const content = typeof file.content === "string" ? new TextEncoder().encode(file.content) : file.content;
207
- const oid = await git3.writeBlob({ ...repo, blob: content });
168
+ const oid = await git2.writeBlob({ ...repo, blob: content });
208
169
  blobs.set(file.path, oid);
209
170
  })
210
171
  );
@@ -228,10 +189,10 @@ function deleteFileFromBare(repo, options) {
228
189
 
229
190
  // src/ops/diff.ts
230
191
  import { createTwoFilesPatch } from "diff";
231
- import git5 from "isomorphic-git";
192
+ import git4 from "isomorphic-git";
232
193
 
233
194
  // src/ops/history.ts
234
- import git4 from "isomorphic-git";
195
+ import git3 from "isomorphic-git";
235
196
 
236
197
  // src/ops/types.ts
237
198
  var runStep = (hooks, label, fn) => hooks?.step ? hooks.step(label, fn) : fn();
@@ -258,16 +219,16 @@ function wrapMissingObject(promise, context) {
258
219
  }
259
220
  var isNotFound = (err) => err?.code === "NotFoundError";
260
221
  async function resolveCommit(repo, ref) {
261
- const oid = await git4.resolveRef({ ...repo, ref: qualifyBranchRef(ref) });
222
+ const oid = await git3.resolveRef({ ...repo, ref: qualifyBranchRef(ref) });
262
223
  const result = await wrapMissingObject(
263
- git4.readCommit({ ...repo, oid }),
224
+ git3.readCommit({ ...repo, oid }),
264
225
  `${repo.gitdir} commit ${oid}`
265
226
  );
266
227
  return { oid, commit: result.commit };
267
228
  }
268
229
  async function getBlob(repo, sha) {
269
230
  const { blob } = await wrapMissingObject(
270
- git4.readBlob({ ...repo, oid: sha }),
231
+ git3.readBlob({ ...repo, oid: sha }),
271
232
  `${repo.gitdir} blob ${sha}`
272
233
  );
273
234
  return blob;
@@ -283,14 +244,14 @@ async function getFileContent(repo, filePath, ref = "main") {
283
244
  throw new GitPathNotFoundError(`File not found: ${filePath}`);
284
245
  }
285
246
  const { blob } = await wrapMissingObject(
286
- git4.readBlob({ ...repo, oid: entry.oid }),
247
+ git3.readBlob({ ...repo, oid: entry.oid }),
287
248
  context
288
249
  );
289
250
  return blob;
290
251
  }
291
252
  async function getCommit(repo, sha) {
292
253
  const result = await wrapMissingObject(
293
- git4.readCommit({ ...repo, oid: sha }),
254
+ git3.readCommit({ ...repo, oid: sha }),
294
255
  `${repo.gitdir} commit ${sha}`
295
256
  );
296
257
  return { oid: result.oid, commit: result.commit, payload: result.payload };
@@ -307,7 +268,7 @@ async function getCommitLog(repo, options = {}, hooks) {
307
268
  headSha = options.knownHeadSha;
308
269
  } else {
309
270
  try {
310
- headSha = await git4.resolveRef({ ...repo, ref: qualifyBranchRef(ref) });
271
+ headSha = await git3.resolveRef({ ...repo, ref: qualifyBranchRef(ref) });
311
272
  } catch (err) {
312
273
  if (isNotFound(err)) return [];
313
274
  throw err;
@@ -331,7 +292,7 @@ async function getCommitLog(repo, options = {}, hooks) {
331
292
  runStep(
332
293
  hooks,
333
294
  `git.log ${ref} depth=${depth}`,
334
- () => git4.log({ ...repo, ref: headSha, depth })
295
+ () => git3.log({ ...repo, ref: headSha, depth })
335
296
  ),
336
297
  `${repo.gitdir}@${ref} history`
337
298
  );
@@ -417,7 +378,7 @@ async function getTreeFromRef(repo, options = {}, hooks) {
417
378
  async function getCommitHistory(repo, options, hooks) {
418
379
  const limit = options.limit ?? 50;
419
380
  const skip = options.skip ?? 0;
420
- const headSha = await git4.resolveRef({ ...repo, ref: qualifyBranchRef(options.ref) }).catch(() => null);
381
+ const headSha = await git3.resolveRef({ ...repo, ref: qualifyBranchRef(options.ref) }).catch(() => null);
421
382
  const cacheKey = headSha ? `commits:${repo.gitdir}:${headSha}:${limit}:${skip}` : null;
422
383
  if (cacheKey) {
423
384
  const cached = hooks?.resultCache?.get(cacheKey);
@@ -474,15 +435,15 @@ function summarizeDiff(files) {
474
435
  };
475
436
  }
476
437
  async function walkTreeDiff(repo, oldOid, newOid) {
477
- const changes = await git5.walk({
438
+ const changes = await git4.walk({
478
439
  ...repo,
479
- trees: [git5.TREE({ ref: oldOid }), git5.TREE({ ref: newOid })],
440
+ trees: [git4.TREE({ ref: oldOid }), git4.TREE({ ref: newOid })],
480
441
  map: async (filepath, [A, B]) => {
481
442
  const [typeA, typeB] = await Promise.all([A?.type(), B?.type()]);
482
443
  if (typeA === "tree" || typeB === "tree") return;
483
444
  if (typeA && !typeB) {
484
445
  const oidA2 = A ? await A.oid() : "";
485
- const { blob } = await git5.readBlob({ ...repo, oid: oidA2 });
446
+ const { blob } = await git4.readBlob({ ...repo, oid: oidA2 });
486
447
  const before = detectBlobContent(blob);
487
448
  return {
488
449
  path: filepath,
@@ -502,7 +463,7 @@ async function walkTreeDiff(repo, oldOid, newOid) {
502
463
  }
503
464
  if (!typeA && typeB) {
504
465
  const oidB2 = B ? await B.oid() : "";
505
- const { blob } = await git5.readBlob({ ...repo, oid: oidB2 });
466
+ const { blob } = await git4.readBlob({ ...repo, oid: oidB2 });
506
467
  const after = detectBlobContent(blob);
507
468
  return {
508
469
  path: filepath,
@@ -526,8 +487,8 @@ async function walkTreeDiff(repo, oldOid, newOid) {
526
487
  ]);
527
488
  if (oidA !== oidB) {
528
489
  const [{ blob: blobA }, { blob: blobB }] = await Promise.all([
529
- git5.readBlob({ ...repo, oid: oidA }),
530
- git5.readBlob({ ...repo, oid: oidB })
490
+ git4.readBlob({ ...repo, oid: oidA }),
491
+ git4.readBlob({ ...repo, oid: oidB })
531
492
  ]);
532
493
  const before = detectBlobContent(blobA);
533
494
  const after = detectBlobContent(blobB);
@@ -567,7 +528,7 @@ async function getCommitDiff(repo, commitSha) {
567
528
  ];
568
529
  while (stack.length) {
569
530
  const { treeOid, prefix } = stack.pop();
570
- const { tree } = await git5.readTree({ ...repo, oid: treeOid });
531
+ const { tree } = await git4.readTree({ ...repo, oid: treeOid });
571
532
  for (const entry of tree) {
572
533
  const full = prefix ? `${prefix}/${entry.path}` : entry.path;
573
534
  if (entry.type === "tree") {
@@ -579,7 +540,7 @@ async function getCommitDiff(repo, commitSha) {
579
540
  }
580
541
  const files2 = await Promise.all(
581
542
  entries.map(async ({ path, oid }) => {
582
- const { blob } = await git5.readBlob({ ...repo, oid });
543
+ const { blob } = await git4.readBlob({ ...repo, oid });
583
544
  const after = detectBlobContent(blob);
584
545
  return {
585
546
  path,
@@ -608,8 +569,8 @@ async function getCommitDiff(repo, commitSha) {
608
569
  }
609
570
  async function getDiffBetweenRefs(repo, baseRef, compareRef) {
610
571
  const [baseOid, compareOid] = await Promise.all([
611
- git5.resolveRef({ ...repo, ref: qualifyBranchRef(baseRef) }),
612
- git5.resolveRef({ ...repo, ref: qualifyBranchRef(compareRef) })
572
+ git4.resolveRef({ ...repo, ref: qualifyBranchRef(baseRef) }),
573
+ git4.resolveRef({ ...repo, ref: qualifyBranchRef(compareRef) })
613
574
  ]);
614
575
  const files = await walkTreeDiff(repo, baseOid, compareOid);
615
576
  return summarizeDiff(files);
@@ -801,16 +762,16 @@ async function getLastCommitsForTree(repo, options, hooks) {
801
762
  }
802
763
 
803
764
  // src/ops/merge.ts
804
- import git6 from "isomorphic-git";
765
+ import git5 from "isomorphic-git";
805
766
  async function analyzeMerge(repo, sourceBranch, targetBranch) {
806
767
  assertSafeBranchName(sourceBranch);
807
768
  assertSafeBranchName(targetBranch);
808
769
  try {
809
770
  const [sourceOid, targetOid] = await Promise.all([
810
- git6.resolveRef({ ...repo, ref: qualifyBranchRef(sourceBranch) }),
811
- git6.resolveRef({ ...repo, ref: qualifyBranchRef(targetBranch) })
771
+ git5.resolveRef({ ...repo, ref: qualifyBranchRef(sourceBranch) }),
772
+ git5.resolveRef({ ...repo, ref: qualifyBranchRef(targetBranch) })
812
773
  ]);
813
- const isDescendant = await git6.isDescendent({
774
+ const isDescendant = await git5.isDescendent({
814
775
  ...repo,
815
776
  oid: sourceOid,
816
777
  ancestor: targetOid
@@ -837,16 +798,16 @@ async function fastForwardMerge(repo, sourceBranch, targetBranch) {
837
798
  assertSafeBranchName(sourceBranch);
838
799
  assertSafeBranchName(targetBranch);
839
800
  const [sourceOid, targetOid] = await Promise.all([
840
- git6.resolveRef({ ...repo, ref: `refs/heads/${sourceBranch}` }),
841
- git6.resolveRef({ ...repo, ref: `refs/heads/${targetBranch}` })
801
+ git5.resolveRef({ ...repo, ref: `refs/heads/${sourceBranch}` }),
802
+ git5.resolveRef({ ...repo, ref: `refs/heads/${targetBranch}` })
842
803
  ]);
843
- const isFF = await git6.isDescendent({
804
+ const isFF = await git5.isDescendent({
844
805
  ...repo,
845
806
  oid: sourceOid,
846
807
  ancestor: targetOid
847
808
  });
848
809
  if (!isFF) return null;
849
- await git6.writeRef({
810
+ await git5.writeRef({
850
811
  ...repo,
851
812
  ref: `refs/heads/${targetBranch}`,
852
813
  value: sourceOid,
@@ -882,6 +843,7 @@ export {
882
843
  listBranches,
883
844
  listTreeEntries,
884
845
  resolveCommit,
846
+ resolveLooseRefFast,
885
847
  resultKeyPrefixes,
886
848
  upsertTree,
887
849
  writeCommitToBare