isomorphic-git 1.42.5 → 1.42.7

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.
@@ -1658,7 +1658,16 @@ async function isIndexStale(fs, filepath, cache) {
1658
1658
 
1659
1659
  const currStats = await fs.lstat(filepath);
1660
1660
  if (currStats === null) return false
1661
- return compareStats(savedStats, currStats)
1661
+ if (compareStats(savedStats, currStats)) return true
1662
+ // compareStats only looks at whole seconds, but the index is often rewritten
1663
+ // in the same second with the same size (an entry got a new oid). Both stats
1664
+ // come from the same fs, so compare the full timestamps too.
1665
+ const saved = normalizeStats(savedStats);
1666
+ const curr = normalizeStats(currStats);
1667
+ return (
1668
+ saved.mtimeNanoseconds !== curr.mtimeNanoseconds ||
1669
+ saved.ctimeNanoseconds !== curr.ctimeNanoseconds
1670
+ )
1662
1671
  }
1663
1672
 
1664
1673
  class GitIndexManager {
@@ -5328,6 +5337,23 @@ class CheckoutConflictError extends BaseError {
5328
5337
  /** @type {'CheckoutConflictError'} */
5329
5338
  CheckoutConflictError.code = 'CheckoutConflictError';
5330
5339
 
5340
+ class CherryPickLocalChangesError extends BaseError {
5341
+ /**
5342
+ * @param {string[]} filepaths
5343
+ */
5344
+ constructor(filepaths) {
5345
+ super(
5346
+ `Your local changes to the following files would be overwritten by cherry-pick: ${filepaths.join(
5347
+ ', '
5348
+ )}`
5349
+ );
5350
+ this.code = this.name = CherryPickLocalChangesError.code;
5351
+ this.data = { filepaths };
5352
+ }
5353
+ }
5354
+ /** @type {'CherryPickLocalChangesError'} */
5355
+ CherryPickLocalChangesError.code = 'CherryPickLocalChangesError';
5356
+
5331
5357
  class CherryPickMergeCommitError extends BaseError {
5332
5358
  /**
5333
5359
  * @param {string} oid
@@ -5746,6 +5772,10 @@ class GitWalkerFs {
5746
5772
  this.dir = dir;
5747
5773
  this.gitdir = gitdir;
5748
5774
  this.refresh = refresh;
5775
+ // Index entries whose stat info needs a refresh. `flush` writes them to
5776
+ // the index together when the walk is finished.
5777
+ this.refreshQueue = [];
5778
+ this.flushed = false;
5749
5779
 
5750
5780
  this.config = null;
5751
5781
  const walker = this;
@@ -5890,11 +5920,20 @@ class GitWalkerFs {
5890
5920
  (!filemode || stats.mode === stage.mode) &&
5891
5921
  compareStats(stats, stage, filemode, trustino)
5892
5922
  ) {
5893
- index.insert({
5894
- filepath: entry._fullpath,
5895
- stats,
5896
- oid,
5897
- });
5923
+ if (self.flushed) {
5924
+ // The walk is finished and `flush` already ran, so write
5925
+ // it right away.
5926
+ index.insert({ filepath: entry._fullpath, stats, oid });
5927
+ } else {
5928
+ // Queue the refresh so `flush` can write all of them to the
5929
+ // index in one go when the walk is finished.
5930
+ self.refreshQueue.push({
5931
+ filepath: entry._fullpath,
5932
+ stage,
5933
+ stats,
5934
+ oid,
5935
+ });
5936
+ }
5898
5937
  }
5899
5938
  }
5900
5939
  } else {
@@ -5908,6 +5947,26 @@ class GitWalkerFs {
5908
5947
  return entry._oid
5909
5948
  }
5910
5949
 
5950
+ /**
5951
+ * Write the queued stat refreshes to the index in a single pass.
5952
+ * `_walk` calls this once the walk is finished. The entries it returned
5953
+ * can still be asked for their oid afterwards, so from then on `oid`
5954
+ * writes a refresh right away instead of queueing it.
5955
+ */
5956
+ async flush() {
5957
+ const { fs, gitdir, cache, refreshQueue } = this;
5958
+ this.refreshQueue = [];
5959
+ this.flushed = true;
5960
+ if (refreshQueue.length === 0) return
5961
+ await GitIndexManager.acquire({ fs, gitdir, cache }, async index => {
5962
+ for (const { filepath, stage, stats, oid } of refreshQueue) {
5963
+ // Only refresh entries that are still the ones we looked at.
5964
+ if (index.entriesMap.get(filepath) !== stage) continue
5965
+ index.insert({ filepath, stats, oid });
5966
+ }
5967
+ });
5968
+ }
5969
+
5911
5970
  async _getGitConfig(fs, gitdir) {
5912
5971
  if (this.config) {
5913
5972
  return this.config
@@ -6103,7 +6162,13 @@ async function _walk({
6103
6162
  return reduce(parent, walkedChildren)
6104
6163
  }
6105
6164
  };
6106
- return walk(root)
6165
+ const result = await walk(root);
6166
+ // Let walkers write out what they queued during the walk. WORKDIR queues
6167
+ // its index stat refreshes so the index is written once at the end.
6168
+ for (const walker of walkers) {
6169
+ if (walker.flush) await walker.flush();
6170
+ }
6171
+ return result
6107
6172
  }
6108
6173
 
6109
6174
  // @ts-check
package/managers/index.js CHANGED
@@ -1651,7 +1651,16 @@ async function isIndexStale(fs, filepath, cache) {
1651
1651
 
1652
1652
  const currStats = await fs.lstat(filepath);
1653
1653
  if (currStats === null) return false
1654
- return compareStats(savedStats, currStats)
1654
+ if (compareStats(savedStats, currStats)) return true
1655
+ // compareStats only looks at whole seconds, but the index is often rewritten
1656
+ // in the same second with the same size (an entry got a new oid). Both stats
1657
+ // come from the same fs, so compare the full timestamps too.
1658
+ const saved = normalizeStats(savedStats);
1659
+ const curr = normalizeStats(currStats);
1660
+ return (
1661
+ saved.mtimeNanoseconds !== curr.mtimeNanoseconds ||
1662
+ saved.ctimeNanoseconds !== curr.ctimeNanoseconds
1663
+ )
1655
1664
  }
1656
1665
 
1657
1666
  class GitIndexManager {
@@ -5315,6 +5324,23 @@ class CheckoutConflictError extends BaseError {
5315
5324
  /** @type {'CheckoutConflictError'} */
5316
5325
  CheckoutConflictError.code = 'CheckoutConflictError';
5317
5326
 
5327
+ class CherryPickLocalChangesError extends BaseError {
5328
+ /**
5329
+ * @param {string[]} filepaths
5330
+ */
5331
+ constructor(filepaths) {
5332
+ super(
5333
+ `Your local changes to the following files would be overwritten by cherry-pick: ${filepaths.join(
5334
+ ', '
5335
+ )}`
5336
+ );
5337
+ this.code = this.name = CherryPickLocalChangesError.code;
5338
+ this.data = { filepaths };
5339
+ }
5340
+ }
5341
+ /** @type {'CherryPickLocalChangesError'} */
5342
+ CherryPickLocalChangesError.code = 'CherryPickLocalChangesError';
5343
+
5318
5344
  class CherryPickMergeCommitError extends BaseError {
5319
5345
  /**
5320
5346
  * @param {string} oid
@@ -5733,6 +5759,10 @@ class GitWalkerFs {
5733
5759
  this.dir = dir;
5734
5760
  this.gitdir = gitdir;
5735
5761
  this.refresh = refresh;
5762
+ // Index entries whose stat info needs a refresh. `flush` writes them to
5763
+ // the index together when the walk is finished.
5764
+ this.refreshQueue = [];
5765
+ this.flushed = false;
5736
5766
 
5737
5767
  this.config = null;
5738
5768
  const walker = this;
@@ -5877,11 +5907,20 @@ class GitWalkerFs {
5877
5907
  (!filemode || stats.mode === stage.mode) &&
5878
5908
  compareStats(stats, stage, filemode, trustino)
5879
5909
  ) {
5880
- index.insert({
5881
- filepath: entry._fullpath,
5882
- stats,
5883
- oid,
5884
- });
5910
+ if (self.flushed) {
5911
+ // The walk is finished and `flush` already ran, so write
5912
+ // it right away.
5913
+ index.insert({ filepath: entry._fullpath, stats, oid });
5914
+ } else {
5915
+ // Queue the refresh so `flush` can write all of them to the
5916
+ // index in one go when the walk is finished.
5917
+ self.refreshQueue.push({
5918
+ filepath: entry._fullpath,
5919
+ stage,
5920
+ stats,
5921
+ oid,
5922
+ });
5923
+ }
5885
5924
  }
5886
5925
  }
5887
5926
  } else {
@@ -5895,6 +5934,26 @@ class GitWalkerFs {
5895
5934
  return entry._oid
5896
5935
  }
5897
5936
 
5937
+ /**
5938
+ * Write the queued stat refreshes to the index in a single pass.
5939
+ * `_walk` calls this once the walk is finished. The entries it returned
5940
+ * can still be asked for their oid afterwards, so from then on `oid`
5941
+ * writes a refresh right away instead of queueing it.
5942
+ */
5943
+ async flush() {
5944
+ const { fs, gitdir, cache, refreshQueue } = this;
5945
+ this.refreshQueue = [];
5946
+ this.flushed = true;
5947
+ if (refreshQueue.length === 0) return
5948
+ await GitIndexManager.acquire({ fs, gitdir, cache }, async index => {
5949
+ for (const { filepath, stage, stats, oid } of refreshQueue) {
5950
+ // Only refresh entries that are still the ones we looked at.
5951
+ if (index.entriesMap.get(filepath) !== stage) continue
5952
+ index.insert({ filepath, stats, oid });
5953
+ }
5954
+ });
5955
+ }
5956
+
5898
5957
  async _getGitConfig(fs, gitdir) {
5899
5958
  if (this.config) {
5900
5959
  return this.config
@@ -6090,7 +6149,13 @@ async function _walk({
6090
6149
  return reduce(parent, walkedChildren)
6091
6150
  }
6092
6151
  };
6093
- return walk(root)
6152
+ const result = await walk(root);
6153
+ // Let walkers write out what they queued during the walk. WORKDIR queues
6154
+ // its index stat refreshes so the index is written once at the end.
6155
+ for (const walker of walkers) {
6156
+ if (walker.flush) await walker.flush();
6157
+ }
6158
+ return result
6094
6159
  }
6095
6160
 
6096
6161
  // @ts-check