type-git 0.3.0-alpha.2 → 0.3.0-alpha.3

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.
@@ -1,4 +1,4 @@
1
- import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, i as EnvInheritance, A as AuditConfig, R as RuntimeAdapters, j as ExecutionContext, k as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-sSzx9O1u.cjs';
1
+ import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, i as EnvInheritance, A as AuditConfig, R as RuntimeAdapters, j as ExecutionContext, k as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-CZ8wj9Kr.cjs';
2
2
 
3
3
  /**
4
4
  * stdout parsing utilities for Git output
@@ -1781,8 +1781,10 @@ type LfsPushOpts = {
1781
1781
  ref?: string;
1782
1782
  /** Dry run - show what would be pushed without actually pushing */
1783
1783
  dryRun?: boolean;
1784
- /** Push specified object IDs (OID hashes) instead of all objects */
1784
+ /** Push specified object IDs (OID hashes) instead of all objects. Empty arrays require stdin: true. */
1785
1785
  objectId?: string | string[];
1786
+ /** Send objectId values (or ref) as newline-delimited standard input. Requires objectId or ref. */
1787
+ stdin?: boolean;
1786
1788
  };
1787
1789
  /**
1788
1790
  * Options for LFS status
@@ -2141,8 +2143,34 @@ type LfsEnvInfo = {
2141
2143
  type LfsPreUploadOpts = {
2142
2144
  /** Object IDs to upload (if omitted, auto-detect pending objects) */
2143
2145
  oids?: string[];
2144
- /** Batch size for upload (default: 50, considers Windows 8KB limit) */
2146
+ /**
2147
+ * Number of OIDs per `git lfs push --object-id` invocation (default: 200).
2148
+ *
2149
+ * Each batch is one spawned process, so the batch size is bounded by the
2150
+ * OS command-line length limit. Git is spawned without a shell, so the
2151
+ * binding limit is the Windows CreateProcess limit (32,767 characters);
2152
+ * the default stays around 40% of it.
2153
+ */
2145
2154
  batchSize?: number;
2155
+ /**
2156
+ * Maximum number of batches uploaded concurrently (default: 4).
2157
+ *
2158
+ * Each `git lfs push` invocation pays a fixed cost (process spawn,
2159
+ * credential lookup, LFS batch API round-trip) before any bytes are
2160
+ * transferred; concurrent batches overlap that cost with other batches'
2161
+ * transfers. The first batch always runs alone and the remaining batches
2162
+ * start only after it succeeds, so a failure common to all batches (e.g.
2163
+ * an unreachable remote) costs a single round-trip. Once a batch fails, no
2164
+ * new batch is started; in-flight batches are awaited and the remaining
2165
+ * objects are reported in `skippedCount`. Set to 1 for strictly serial
2166
+ * uploads.
2167
+ *
2168
+ * Note: each `git lfs push` process transfers multiple objects in parallel
2169
+ * on its own (`lfs.concurrenttransfers`, default 8), so the peak transfer
2170
+ * parallelism is `concurrency` times that value. With `concurrency` > 1,
2171
+ * progress callbacks from different batches may interleave.
2172
+ */
2173
+ concurrency?: number;
2146
2174
  /** Remote name (default: 'origin') */
2147
2175
  remote?: string;
2148
2176
  };
@@ -2154,7 +2182,11 @@ type LfsPreUploadResult = {
2154
2182
  uploadedCount: number;
2155
2183
  /** Total bytes uploaded */
2156
2184
  uploadedBytes: number;
2157
- /** Number of objects skipped (already on remote) */
2185
+ /**
2186
+ * Number of objects not uploaded: the objects of the batch that failed or
2187
+ * was aborted, plus those of the batches never started after that failure.
2188
+ * `uploadedCount + skippedCount` always equals the number of objects.
2189
+ */
2158
2190
  skippedCount: number;
2159
2191
  };
2160
2192
  /**
@@ -3969,6 +4001,8 @@ type CliRunnerOptions = {
3969
4001
  * runner's own `run` / `runOrThrow` entry points.
3970
4002
  */
3971
4003
  type RunOptions = ExecOpts & {
4004
+ /** UTF-8 text to write to standard input, then close it. */
4005
+ stdin?: string;
3972
4006
  /**
3973
4007
  * Extra environment variables merged on top of the resolved environment for
3974
4008
  * this single command. Values here take precedence over the configured
@@ -1,4 +1,4 @@
1
- import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, i as EnvInheritance, A as AuditConfig, R as RuntimeAdapters, j as ExecutionContext, k as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-sSzx9O1u.js';
1
+ import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, i as EnvInheritance, A as AuditConfig, R as RuntimeAdapters, j as ExecutionContext, k as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-CZ8wj9Kr.js';
2
2
 
3
3
  /**
4
4
  * stdout parsing utilities for Git output
@@ -1781,8 +1781,10 @@ type LfsPushOpts = {
1781
1781
  ref?: string;
1782
1782
  /** Dry run - show what would be pushed without actually pushing */
1783
1783
  dryRun?: boolean;
1784
- /** Push specified object IDs (OID hashes) instead of all objects */
1784
+ /** Push specified object IDs (OID hashes) instead of all objects. Empty arrays require stdin: true. */
1785
1785
  objectId?: string | string[];
1786
+ /** Send objectId values (or ref) as newline-delimited standard input. Requires objectId or ref. */
1787
+ stdin?: boolean;
1786
1788
  };
1787
1789
  /**
1788
1790
  * Options for LFS status
@@ -2141,8 +2143,34 @@ type LfsEnvInfo = {
2141
2143
  type LfsPreUploadOpts = {
2142
2144
  /** Object IDs to upload (if omitted, auto-detect pending objects) */
2143
2145
  oids?: string[];
2144
- /** Batch size for upload (default: 50, considers Windows 8KB limit) */
2146
+ /**
2147
+ * Number of OIDs per `git lfs push --object-id` invocation (default: 200).
2148
+ *
2149
+ * Each batch is one spawned process, so the batch size is bounded by the
2150
+ * OS command-line length limit. Git is spawned without a shell, so the
2151
+ * binding limit is the Windows CreateProcess limit (32,767 characters);
2152
+ * the default stays around 40% of it.
2153
+ */
2145
2154
  batchSize?: number;
2155
+ /**
2156
+ * Maximum number of batches uploaded concurrently (default: 4).
2157
+ *
2158
+ * Each `git lfs push` invocation pays a fixed cost (process spawn,
2159
+ * credential lookup, LFS batch API round-trip) before any bytes are
2160
+ * transferred; concurrent batches overlap that cost with other batches'
2161
+ * transfers. The first batch always runs alone and the remaining batches
2162
+ * start only after it succeeds, so a failure common to all batches (e.g.
2163
+ * an unreachable remote) costs a single round-trip. Once a batch fails, no
2164
+ * new batch is started; in-flight batches are awaited and the remaining
2165
+ * objects are reported in `skippedCount`. Set to 1 for strictly serial
2166
+ * uploads.
2167
+ *
2168
+ * Note: each `git lfs push` process transfers multiple objects in parallel
2169
+ * on its own (`lfs.concurrenttransfers`, default 8), so the peak transfer
2170
+ * parallelism is `concurrency` times that value. With `concurrency` > 1,
2171
+ * progress callbacks from different batches may interleave.
2172
+ */
2173
+ concurrency?: number;
2146
2174
  /** Remote name (default: 'origin') */
2147
2175
  remote?: string;
2148
2176
  };
@@ -2154,7 +2182,11 @@ type LfsPreUploadResult = {
2154
2182
  uploadedCount: number;
2155
2183
  /** Total bytes uploaded */
2156
2184
  uploadedBytes: number;
2157
- /** Number of objects skipped (already on remote) */
2185
+ /**
2186
+ * Number of objects not uploaded: the objects of the batch that failed or
2187
+ * was aborted, plus those of the batches never started after that failure.
2188
+ * `uploadedCount + skippedCount` always equals the number of objects.
2189
+ */
2158
2190
  skippedCount: number;
2159
2191
  };
2160
2192
  /**
@@ -3969,6 +4001,8 @@ type CliRunnerOptions = {
3969
4001
  * runner's own `run` / `runOrThrow` entry points.
3970
4002
  */
3971
4003
  type RunOptions = ExecOpts & {
4004
+ /** UTF-8 text to write to standard input, then close it. */
4005
+ stdin?: string;
3972
4006
  /**
3973
4007
  * Extra environment variables merged on top of the resolved environment for
3974
4008
  * this single command. Values here take precedence over the configured
@@ -748,6 +748,7 @@ var CliRunner = class _CliRunner {
748
748
  result = await this.exec.spawn(
749
749
  {
750
750
  argv,
751
+ stdin: opts?.stdin,
751
752
  env,
752
753
  // The env above is already fully resolved (including any inherited variables),
753
754
  // so the adapter must not merge the parent environment on top of it.
@@ -1603,7 +1604,53 @@ var BareRepoImpl = class {
1603
1604
  }
1604
1605
  };
1605
1606
 
1607
+ // src/internal/concurrency.ts
1608
+ async function runWithConcurrency(items, run, options) {
1609
+ const { concurrency, warmupCount = 0 } = options;
1610
+ if (!Number.isInteger(concurrency) || concurrency < 1) {
1611
+ throw new RangeError(`concurrency must be a positive integer, got: ${concurrency}`);
1612
+ }
1613
+ if (!Number.isInteger(warmupCount) || warmupCount < 0) {
1614
+ throw new RangeError(`warmupCount must be a non-negative integer, got: ${warmupCount}`);
1615
+ }
1616
+ const results = new Array(items.length);
1617
+ let nextIndex = 0;
1618
+ let failed = false;
1619
+ let firstError;
1620
+ const runOne = async (index) => {
1621
+ try {
1622
+ const item = items[index];
1623
+ results[index] = await run(item, index);
1624
+ } catch (error) {
1625
+ if (!failed) {
1626
+ failed = true;
1627
+ firstError = error;
1628
+ }
1629
+ }
1630
+ };
1631
+ const warmupEnd = Math.min(warmupCount, items.length);
1632
+ while (nextIndex < warmupEnd && !failed) {
1633
+ await runOne(nextIndex++);
1634
+ }
1635
+ if (!failed && nextIndex < items.length) {
1636
+ const worker = async () => {
1637
+ while (!failed && nextIndex < items.length) {
1638
+ await runOne(nextIndex++);
1639
+ }
1640
+ };
1641
+ const workerCount = Math.min(concurrency, items.length - nextIndex);
1642
+ await Promise.all(Array.from({ length: workerCount }, () => worker()));
1643
+ }
1644
+ if (failed) {
1645
+ throw firstError;
1646
+ }
1647
+ return results;
1648
+ }
1649
+
1606
1650
  // src/impl/worktree-repo-impl.ts
1651
+ var PRE_UPLOAD_DEFAULT_BATCH_SIZE = 200;
1652
+ var PRE_UPLOAD_DEFAULT_CONCURRENCY = 4;
1653
+ var PRE_UPLOAD_WARMUP_BATCH_COUNT = 1;
1607
1654
  var WorktreeRepoImpl = class _WorktreeRepoImpl {
1608
1655
  workdir;
1609
1656
  runner;
@@ -2352,27 +2399,30 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2352
2399
  if (this._lfsMode === "disabled") {
2353
2400
  return;
2354
2401
  }
2402
+ if (opts?.stdin && opts.objectId === void 0 && !opts.ref) {
2403
+ throw new TypeError("lfs.push with stdin requires objectId or ref");
2404
+ }
2355
2405
  const args = ["lfs", "push"];
2356
2406
  if (opts?.dryRun) {
2357
2407
  args.push("--dry-run");
2358
2408
  }
2359
- if (opts?.objectId) {
2360
- const oids = Array.isArray(opts.objectId) ? opts.objectId : [opts.objectId];
2361
- for (const oid of oids) {
2362
- args.push("--object-id", oid);
2363
- }
2364
- } else {
2365
- args.push("--all");
2409
+ const oids = opts?.objectId !== void 0 ? Array.isArray(opts.objectId) ? opts.objectId : [opts.objectId] : void 0;
2410
+ if (oids?.length === 0 && !opts?.stdin) {
2411
+ throw new TypeError(
2412
+ "lfs.push with objectId requires at least one OID unless stdin is enabled"
2413
+ );
2366
2414
  }
2367
- if (opts?.remote) {
2368
- args.push(opts.remote);
2415
+ args.push(oids ? "--object-id" : "--all");
2416
+ args.push(opts?.remote ?? "origin");
2417
+ const values = oids ?? (opts?.ref ? [opts.ref] : []);
2418
+ if (opts?.stdin) {
2419
+ args.push("--stdin");
2369
2420
  } else {
2370
- args.push("origin");
2371
- }
2372
- if (opts?.ref) {
2373
- args.push(opts.ref);
2421
+ args.push(...values);
2374
2422
  }
2375
2423
  await this.runner.runOrThrow(this.context, args, {
2424
+ stdin: opts?.stdin ? values.length > 0 ? `${values.join("\n")}
2425
+ ` : "" : void 0,
2376
2426
  signal: opts?.signal,
2377
2427
  onProgress: opts?.onProgress,
2378
2428
  onLfsProgress: opts?.onLfsProgress
@@ -2411,12 +2461,19 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2411
2461
  * Pre-upload LFS objects before commit/push (2-phase commit pattern)
2412
2462
  *
2413
2463
  * This allows uploading LFS objects to the remote before creating a commit,
2414
- * ensuring reliable large file handling. Objects are batched to handle
2415
- * Windows command line length limits (8KB).
2464
+ * ensuring reliable large file handling. Objects are batched to stay within
2465
+ * command-line length limits, and batches run with bounded concurrency to
2466
+ * overlap per-invocation fixed costs with other batches' transfers.
2467
+ *
2468
+ * Failure handling: once a batch fails, no new batch is started (in-flight
2469
+ * batches are awaited), and the objects of failed and unstarted batches are
2470
+ * reported in `skippedCount`. The first batch always runs alone before the
2471
+ * remaining batches widen to the concurrency limit, so a failure common to
2472
+ * all batches costs a single round-trip.
2416
2473
  *
2417
2474
  * Usage pattern:
2418
2475
  * 1. Stage changes: git add
2419
- * 2. Pre-upload LFS: await repo.lfs.preUpload()
2476
+ * 2. Pre-upload LFS: await repo.lfsExtra.preUpload()
2420
2477
  * 3. Commit: git commit
2421
2478
  * 4. Push refs: git push (only refs, objects already uploaded)
2422
2479
  */
@@ -2425,7 +2482,14 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2425
2482
  return { uploadedCount: 0, uploadedBytes: 0, skippedCount: 0 };
2426
2483
  }
2427
2484
  const remote = opts?.remote ?? "origin";
2428
- const batchSize = opts?.batchSize ?? 50;
2485
+ const batchSize = opts?.batchSize ?? PRE_UPLOAD_DEFAULT_BATCH_SIZE;
2486
+ const concurrency = opts?.concurrency ?? PRE_UPLOAD_DEFAULT_CONCURRENCY;
2487
+ if (!Number.isInteger(batchSize) || batchSize < 1) {
2488
+ throw new RangeError(`batchSize must be a positive integer, got: ${batchSize}`);
2489
+ }
2490
+ if (!Number.isInteger(concurrency) || concurrency < 1) {
2491
+ throw new RangeError(`concurrency must be a positive integer, got: ${concurrency}`);
2492
+ }
2429
2493
  let oids;
2430
2494
  if (opts?.oids && opts.oids.length > 0) {
2431
2495
  oids = opts.oids;
@@ -2450,18 +2514,24 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2450
2514
  if (oids.length === 0) {
2451
2515
  return { uploadedCount: 0, uploadedBytes: 0, skippedCount: 0 };
2452
2516
  }
2517
+ const batches = [];
2518
+ for (let i = 0; i < oids.length; i += batchSize) {
2519
+ batches.push(oids.slice(i, i + batchSize));
2520
+ }
2453
2521
  let uploadedCount = 0;
2454
2522
  let uploadedBytes = 0;
2455
2523
  let skippedCount = 0;
2456
- for (let i = 0; i < oids.length; i += batchSize) {
2457
- const batch = oids.slice(i, i + batchSize);
2524
+ let attemptedCount = 0;
2525
+ const batchFailedStop = new Error("lfs pre-upload batch failed");
2526
+ const pushBatch = async (batch) => {
2458
2527
  const args = ["lfs", "push", remote, "--object-id", ...batch];
2459
2528
  const result = await this.runner.run(this.context, args, {
2460
2529
  signal: opts?.signal,
2461
2530
  onProgress: opts?.onProgress,
2462
2531
  onLfsProgress: opts?.onLfsProgress
2463
2532
  });
2464
- if (result.exitCode === 0) {
2533
+ attemptedCount += batch.length;
2534
+ if (result.exitCode === 0 && !result.aborted) {
2465
2535
  uploadedCount += batch.length;
2466
2536
  const bytesMatch = result.stderr.match(
2467
2537
  /Uploading LFS objects:.*?\((\d+(?:\.\d+)?)\s*([KMG]?B)/i
@@ -2481,7 +2551,19 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2481
2551
  }
2482
2552
  } else {
2483
2553
  skippedCount += batch.length;
2554
+ throw batchFailedStop;
2484
2555
  }
2556
+ };
2557
+ try {
2558
+ await runWithConcurrency(batches, pushBatch, {
2559
+ concurrency,
2560
+ warmupCount: PRE_UPLOAD_WARMUP_BATCH_COUNT
2561
+ });
2562
+ } catch (error) {
2563
+ if (error !== batchFailedStop) {
2564
+ throw error;
2565
+ }
2566
+ skippedCount += oids.length - attemptedCount;
2485
2567
  }
2486
2568
  return { uploadedCount, uploadedBytes, skippedCount };
2487
2569
  }
@@ -2493,7 +2575,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2493
2575
  *
2494
2576
  * Usage pattern:
2495
2577
  * 1. Fetch refs: git fetch
2496
- * 2. Pre-download LFS: await repo.lfs.preDownload({ ref: 'origin/feature' })
2578
+ * 2. Pre-download LFS: await repo.lfsExtra.preDownload({ ref: 'origin/feature' })
2497
2579
  * 3. Checkout: git checkout feature
2498
2580
  */
2499
2581
  async lfsPreDownload(opts) {
@@ -2502,6 +2584,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
2502
2584
  }
2503
2585
  const remote = opts?.remote ?? "origin";
2504
2586
  const batchSize = opts?.batchSize ?? 50;
2587
+ if (!Number.isInteger(batchSize) || batchSize < 1) {
2588
+ throw new RangeError(`batchSize must be a positive integer, got: ${batchSize}`);
2589
+ }
2505
2590
  let oids;
2506
2591
  if (opts?.oids && opts.oids.length > 0) {
2507
2592
  oids = opts.oids;
@@ -6048,7 +6133,7 @@ var NodeExecAdapter = class {
6048
6133
  const child = spawn(command, args, {
6049
6134
  cwd,
6050
6135
  env: resolveChildEnv(env, inheritEnv),
6051
- stdio: ["ignore", "pipe", "pipe"]
6136
+ stdio: [options.stdin === void 0 ? "ignore" : "pipe", "pipe", "pipe"]
6052
6137
  });
6053
6138
  let stdout = "";
6054
6139
  let stderr = "";
@@ -6076,6 +6161,12 @@ var NodeExecAdapter = class {
6076
6161
  stderr += text;
6077
6162
  handlers?.onStderr?.(text);
6078
6163
  });
6164
+ child.stdin?.on("error", (error) => {
6165
+ if (error.code !== "EPIPE" && error.code !== "EOF") {
6166
+ reject(error);
6167
+ }
6168
+ });
6169
+ child.stdin?.end(options.stdin);
6079
6170
  child.on("error", (error) => {
6080
6171
  signal?.removeEventListener("abort", abortHandler);
6081
6172
  reject(error);
@@ -6104,7 +6195,7 @@ var NodeExecAdapter = class {
6104
6195
  const child = spawn(command, args, {
6105
6196
  cwd,
6106
6197
  env: resolveChildEnv(env, inheritEnv),
6107
- stdio: ["ignore", "pipe", "pipe"]
6198
+ stdio: [options.stdin === void 0 ? "ignore" : "pipe", "pipe", "pipe"]
6108
6199
  });
6109
6200
  let aborted = false;
6110
6201
  let exitSignal;
@@ -6129,6 +6220,12 @@ var NodeExecAdapter = class {
6129
6220
  child.stderr?.on("data", (chunk) => {
6130
6221
  stderr += chunk.toString("utf8");
6131
6222
  });
6223
+ child.stdin?.on("error", (error) => {
6224
+ if (error.code !== "EPIPE" && error.code !== "EOF") {
6225
+ reject(error);
6226
+ }
6227
+ });
6228
+ child.stdin?.end(options.stdin);
6132
6229
  child.on("error", (error) => {
6133
6230
  signal?.removeEventListener("abort", abortHandler);
6134
6231
  reject(error);