isomorphic-git 1.42.6 → 1.43.0

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 {
@@ -5763,6 +5772,10 @@ class GitWalkerFs {
5763
5772
  this.dir = dir;
5764
5773
  this.gitdir = gitdir;
5765
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;
5766
5779
 
5767
5780
  this.config = null;
5768
5781
  const walker = this;
@@ -5907,11 +5920,20 @@ class GitWalkerFs {
5907
5920
  (!filemode || stats.mode === stage.mode) &&
5908
5921
  compareStats(stats, stage, filemode, trustino)
5909
5922
  ) {
5910
- index.insert({
5911
- filepath: entry._fullpath,
5912
- stats,
5913
- oid,
5914
- });
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
+ }
5915
5937
  }
5916
5938
  }
5917
5939
  } else {
@@ -5925,6 +5947,26 @@ class GitWalkerFs {
5925
5947
  return entry._oid
5926
5948
  }
5927
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
+
5928
5970
  async _getGitConfig(fs, gitdir) {
5929
5971
  if (this.config) {
5930
5972
  return this.config
@@ -6120,7 +6162,13 @@ async function _walk({
6120
6162
  return reduce(parent, walkedChildren)
6121
6163
  }
6122
6164
  };
6123
- 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
6124
6172
  }
6125
6173
 
6126
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 {
@@ -5750,6 +5759,10 @@ class GitWalkerFs {
5750
5759
  this.dir = dir;
5751
5760
  this.gitdir = gitdir;
5752
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;
5753
5766
 
5754
5767
  this.config = null;
5755
5768
  const walker = this;
@@ -5894,11 +5907,20 @@ class GitWalkerFs {
5894
5907
  (!filemode || stats.mode === stage.mode) &&
5895
5908
  compareStats(stats, stage, filemode, trustino)
5896
5909
  ) {
5897
- index.insert({
5898
- filepath: entry._fullpath,
5899
- stats,
5900
- oid,
5901
- });
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
+ }
5902
5924
  }
5903
5925
  }
5904
5926
  } else {
@@ -5912,6 +5934,26 @@ class GitWalkerFs {
5912
5934
  return entry._oid
5913
5935
  }
5914
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
+
5915
5957
  async _getGitConfig(fs, gitdir) {
5916
5958
  if (this.config) {
5917
5959
  return this.config
@@ -6107,7 +6149,13 @@ async function _walk({
6107
6149
  return reduce(parent, walkedChildren)
6108
6150
  }
6109
6151
  };
6110
- 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
6111
6159
  }
6112
6160
 
6113
6161
  // @ts-check