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.
package/README.md CHANGED
@@ -456,6 +456,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
456
456
  <td align="center"><a href="http://toxik.us/"><img src="https://avatars.githubusercontent.com/u/235319?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Alexandru Georoceanu</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=toxik" title="Code">💻</a></td>
457
457
  <td align="center"><a href="https://github.com/arisgk"><img src="https://avatars.githubusercontent.com/u/4354335?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Aris Goudouras</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=arisgk" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=arisgk" title="Documentation">📖</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=arisgk" title="Tests">⚠️</a> <a href="https://github.com/isomorphic-git/isomorphic-git/issues?q=author%3Aarisgk" title="Bug reports">🐛</a></td>
458
458
  <td align="center"><a href="https://github.com/TonyWu2333"><img src="https://avatars.githubusercontent.com/u/75903587?v=4?s=60" width="60px;" alt=""/><br /><sub><b>TonyWu</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=TonyWu2333" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=TonyWu2333" title="Tests">⚠️</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=TonyWu2333" title="Documentation">📖</a></td>
459
+ <td align="center"><a href="https://github.com/MadalinTurluianu"><img src="https://avatars.githubusercontent.com/u/81984912?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Madalin Turluianu</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=MadalinTurluianu" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=MadalinTurluianu" title="Tests">⚠️</a></td>
459
460
  </tr>
460
461
  </table>
461
462
 
package/index.cjs CHANGED
@@ -1094,7 +1094,16 @@ async function isIndexStale(fs, filepath, cache) {
1094
1094
 
1095
1095
  const currStats = await fs.lstat(filepath);
1096
1096
  if (currStats === null) return false
1097
- return compareStats(savedStats, currStats)
1097
+ if (compareStats(savedStats, currStats)) return true
1098
+ // compareStats only looks at whole seconds, but the index is often rewritten
1099
+ // in the same second with the same size (an entry got a new oid). Both stats
1100
+ // come from the same fs, so compare the full timestamps too.
1101
+ const saved = normalizeStats(savedStats);
1102
+ const curr = normalizeStats(currStats);
1103
+ return (
1104
+ saved.mtimeNanoseconds !== curr.mtimeNanoseconds ||
1105
+ saved.ctimeNanoseconds !== curr.ctimeNanoseconds
1106
+ )
1098
1107
  }
1099
1108
 
1100
1109
  class GitIndexManager {
@@ -4824,6 +4833,10 @@ class GitWalkerFs {
4824
4833
  this.dir = dir;
4825
4834
  this.gitdir = gitdir;
4826
4835
  this.refresh = refresh;
4836
+ // Index entries whose stat info needs a refresh. `flush` writes them to
4837
+ // the index together when the walk is finished.
4838
+ this.refreshQueue = [];
4839
+ this.flushed = false;
4827
4840
 
4828
4841
  this.config = null;
4829
4842
  const walker = this;
@@ -4968,11 +4981,20 @@ class GitWalkerFs {
4968
4981
  (!filemode || stats.mode === stage.mode) &&
4969
4982
  compareStats(stats, stage, filemode, trustino)
4970
4983
  ) {
4971
- index.insert({
4972
- filepath: entry._fullpath,
4973
- stats,
4974
- oid,
4975
- });
4984
+ if (self.flushed) {
4985
+ // The walk is finished and `flush` already ran, so write
4986
+ // it right away.
4987
+ index.insert({ filepath: entry._fullpath, stats, oid });
4988
+ } else {
4989
+ // Queue the refresh so `flush` can write all of them to the
4990
+ // index in one go when the walk is finished.
4991
+ self.refreshQueue.push({
4992
+ filepath: entry._fullpath,
4993
+ stage,
4994
+ stats,
4995
+ oid,
4996
+ });
4997
+ }
4976
4998
  }
4977
4999
  }
4978
5000
  } else {
@@ -4986,6 +5008,26 @@ class GitWalkerFs {
4986
5008
  return entry._oid
4987
5009
  }
4988
5010
 
5011
+ /**
5012
+ * Write the queued stat refreshes to the index in a single pass.
5013
+ * `_walk` calls this once the walk is finished. The entries it returned
5014
+ * can still be asked for their oid afterwards, so from then on `oid`
5015
+ * writes a refresh right away instead of queueing it.
5016
+ */
5017
+ async flush() {
5018
+ const { fs, gitdir, cache, refreshQueue } = this;
5019
+ this.refreshQueue = [];
5020
+ this.flushed = true;
5021
+ if (refreshQueue.length === 0) return
5022
+ await GitIndexManager.acquire({ fs, gitdir, cache }, async index => {
5023
+ for (const { filepath, stage, stats, oid } of refreshQueue) {
5024
+ // Only refresh entries that are still the ones we looked at.
5025
+ if (index.entriesMap.get(filepath) !== stage) continue
5026
+ index.insert({ filepath, stats, oid });
5027
+ }
5028
+ });
5029
+ }
5030
+
4989
5031
  async _getGitConfig(fs, gitdir) {
4990
5032
  if (this.config) {
4991
5033
  return this.config
@@ -5183,7 +5225,13 @@ async function _walk({
5183
5225
  return reduce(parent, walkedChildren)
5184
5226
  }
5185
5227
  };
5186
- return walk(root)
5228
+ const result = await walk(root);
5229
+ // Let walkers write out what they queued during the walk. WORKDIR queues
5230
+ // its index stat refreshes so the index is written once at the end.
5231
+ for (const walker of walkers) {
5232
+ if (walker.flush) await walker.flush();
5233
+ }
5234
+ return result
5187
5235
  }
5188
5236
 
5189
5237
  /**
@@ -9975,8 +10023,8 @@ function filterCapabilities(server, client) {
9975
10023
 
9976
10024
  const pkg = {
9977
10025
  name: 'isomorphic-git',
9978
- version: '1.42.6',
9979
- agent: 'git/isomorphic-git@1.42.6',
10026
+ version: '1.43.0',
10027
+ agent: 'git/isomorphic-git@1.43.0',
9980
10028
  };
9981
10029
 
9982
10030
  class FIFO {
@@ -15604,7 +15652,7 @@ async function readTree({
15604
15652
  * @param {FsClient} args.fs - a file system client
15605
15653
  * @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
15606
15654
  * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
15607
- * @param {string} args.filepath - The path to the file to remove from the index
15655
+ * @param {string|string[]} args.filepath - The path to the file to remove from the index, or an array of paths
15608
15656
  * @param {object} [args.cache] - a [cache](cache.md) object
15609
15657
  *
15610
15658
  * @returns {Promise<void>} Resolves successfully once the git index has been updated
@@ -15613,6 +15661,11 @@ async function readTree({
15613
15661
  * await git.remove({ fs, dir: '/tutorial', filepath: 'README.md' })
15614
15662
  * console.log('done')
15615
15663
  *
15664
+ * @example
15665
+ * // remove several files from the index with a single write of the index
15666
+ * await git.remove({ fs, dir: '/tutorial', filepath: ['README.md', 'docs/old.md'] })
15667
+ * console.log('done')
15668
+ *
15616
15669
  */
15617
15670
  async function remove({
15618
15671
  fs: _fs,
@@ -15631,7 +15684,10 @@ async function remove({
15631
15684
  await GitIndexManager.acquire(
15632
15685
  { fs: fsp, gitdir: updatedGitdir, cache },
15633
15686
  async function (index) {
15634
- index.delete({ filepath });
15687
+ const filepaths = Array.isArray(filepath) ? filepath : [filepath];
15688
+ for (const currentFilepath of filepaths) {
15689
+ index.delete({ filepath: currentFilepath });
15690
+ }
15635
15691
  }
15636
15692
  );
15637
15693
  } catch (err) {
package/index.d.cts CHANGED
@@ -2903,7 +2903,7 @@ export function readTree({ fs, dir, gitdir, oid, filepath, cache, }: {
2903
2903
  * @param {FsClient} args.fs - a file system client
2904
2904
  * @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
2905
2905
  * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
2906
- * @param {string} args.filepath - The path to the file to remove from the index
2906
+ * @param {string|string[]} args.filepath - The path to the file to remove from the index, or an array of paths
2907
2907
  * @param {object} [args.cache] - a [cache](cache.md) object
2908
2908
  *
2909
2909
  * @returns {Promise<void>} Resolves successfully once the git index has been updated
@@ -2912,12 +2912,17 @@ export function readTree({ fs, dir, gitdir, oid, filepath, cache, }: {
2912
2912
  * await git.remove({ fs, dir: '/tutorial', filepath: 'README.md' })
2913
2913
  * console.log('done')
2914
2914
  *
2915
+ * @example
2916
+ * // remove several files from the index with a single write of the index
2917
+ * await git.remove({ fs, dir: '/tutorial', filepath: ['README.md', 'docs/old.md'] })
2918
+ * console.log('done')
2919
+ *
2915
2920
  */
2916
2921
  export function remove({ fs: _fs, dir, gitdir, filepath, cache, }: {
2917
2922
  fs: FsClient;
2918
2923
  dir?: string | undefined;
2919
2924
  gitdir?: string | undefined;
2920
- filepath: string;
2925
+ filepath: string | string[];
2921
2926
  cache?: object;
2922
2927
  }): Promise<void>;
2923
2928
  /**
package/index.d.ts CHANGED
@@ -2902,7 +2902,7 @@ export function readTree({ fs, dir, gitdir, oid, filepath, cache, }: {
2902
2902
  * @param {FsClient} args.fs - a file system client
2903
2903
  * @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
2904
2904
  * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
2905
- * @param {string} args.filepath - The path to the file to remove from the index
2905
+ * @param {string|string[]} args.filepath - The path to the file to remove from the index, or an array of paths
2906
2906
  * @param {object} [args.cache] - a [cache](cache.md) object
2907
2907
  *
2908
2908
  * @returns {Promise<void>} Resolves successfully once the git index has been updated
@@ -2911,12 +2911,17 @@ export function readTree({ fs, dir, gitdir, oid, filepath, cache, }: {
2911
2911
  * await git.remove({ fs, dir: '/tutorial', filepath: 'README.md' })
2912
2912
  * console.log('done')
2913
2913
  *
2914
+ * @example
2915
+ * // remove several files from the index with a single write of the index
2916
+ * await git.remove({ fs, dir: '/tutorial', filepath: ['README.md', 'docs/old.md'] })
2917
+ * console.log('done')
2918
+ *
2914
2919
  */
2915
2920
  export function remove({ fs: _fs, dir, gitdir, filepath, cache, }: {
2916
2921
  fs: FsClient;
2917
2922
  dir?: string | undefined;
2918
2923
  gitdir?: string | undefined;
2919
- filepath: string;
2924
+ filepath: string | string[];
2920
2925
  cache?: object;
2921
2926
  }): Promise<void>;
2922
2927
  /**
package/index.js CHANGED
@@ -1087,7 +1087,16 @@ async function isIndexStale(fs, filepath, cache) {
1087
1087
 
1088
1088
  const currStats = await fs.lstat(filepath);
1089
1089
  if (currStats === null) return false
1090
- return compareStats(savedStats, currStats)
1090
+ if (compareStats(savedStats, currStats)) return true
1091
+ // compareStats only looks at whole seconds, but the index is often rewritten
1092
+ // in the same second with the same size (an entry got a new oid). Both stats
1093
+ // come from the same fs, so compare the full timestamps too.
1094
+ const saved = normalizeStats(savedStats);
1095
+ const curr = normalizeStats(currStats);
1096
+ return (
1097
+ saved.mtimeNanoseconds !== curr.mtimeNanoseconds ||
1098
+ saved.ctimeNanoseconds !== curr.ctimeNanoseconds
1099
+ )
1091
1100
  }
1092
1101
 
1093
1102
  class GitIndexManager {
@@ -4811,6 +4820,10 @@ class GitWalkerFs {
4811
4820
  this.dir = dir;
4812
4821
  this.gitdir = gitdir;
4813
4822
  this.refresh = refresh;
4823
+ // Index entries whose stat info needs a refresh. `flush` writes them to
4824
+ // the index together when the walk is finished.
4825
+ this.refreshQueue = [];
4826
+ this.flushed = false;
4814
4827
 
4815
4828
  this.config = null;
4816
4829
  const walker = this;
@@ -4955,11 +4968,20 @@ class GitWalkerFs {
4955
4968
  (!filemode || stats.mode === stage.mode) &&
4956
4969
  compareStats(stats, stage, filemode, trustino)
4957
4970
  ) {
4958
- index.insert({
4959
- filepath: entry._fullpath,
4960
- stats,
4961
- oid,
4962
- });
4971
+ if (self.flushed) {
4972
+ // The walk is finished and `flush` already ran, so write
4973
+ // it right away.
4974
+ index.insert({ filepath: entry._fullpath, stats, oid });
4975
+ } else {
4976
+ // Queue the refresh so `flush` can write all of them to the
4977
+ // index in one go when the walk is finished.
4978
+ self.refreshQueue.push({
4979
+ filepath: entry._fullpath,
4980
+ stage,
4981
+ stats,
4982
+ oid,
4983
+ });
4984
+ }
4963
4985
  }
4964
4986
  }
4965
4987
  } else {
@@ -4973,6 +4995,26 @@ class GitWalkerFs {
4973
4995
  return entry._oid
4974
4996
  }
4975
4997
 
4998
+ /**
4999
+ * Write the queued stat refreshes to the index in a single pass.
5000
+ * `_walk` calls this once the walk is finished. The entries it returned
5001
+ * can still be asked for their oid afterwards, so from then on `oid`
5002
+ * writes a refresh right away instead of queueing it.
5003
+ */
5004
+ async flush() {
5005
+ const { fs, gitdir, cache, refreshQueue } = this;
5006
+ this.refreshQueue = [];
5007
+ this.flushed = true;
5008
+ if (refreshQueue.length === 0) return
5009
+ await GitIndexManager.acquire({ fs, gitdir, cache }, async index => {
5010
+ for (const { filepath, stage, stats, oid } of refreshQueue) {
5011
+ // Only refresh entries that are still the ones we looked at.
5012
+ if (index.entriesMap.get(filepath) !== stage) continue
5013
+ index.insert({ filepath, stats, oid });
5014
+ }
5015
+ });
5016
+ }
5017
+
4976
5018
  async _getGitConfig(fs, gitdir) {
4977
5019
  if (this.config) {
4978
5020
  return this.config
@@ -5170,7 +5212,13 @@ async function _walk({
5170
5212
  return reduce(parent, walkedChildren)
5171
5213
  }
5172
5214
  };
5173
- return walk(root)
5215
+ const result = await walk(root);
5216
+ // Let walkers write out what they queued during the walk. WORKDIR queues
5217
+ // its index stat refreshes so the index is written once at the end.
5218
+ for (const walker of walkers) {
5219
+ if (walker.flush) await walker.flush();
5220
+ }
5221
+ return result
5174
5222
  }
5175
5223
 
5176
5224
  /**
@@ -9962,8 +10010,8 @@ function filterCapabilities(server, client) {
9962
10010
 
9963
10011
  const pkg = {
9964
10012
  name: 'isomorphic-git',
9965
- version: '1.42.6',
9966
- agent: 'git/isomorphic-git@1.42.6',
10013
+ version: '1.43.0',
10014
+ agent: 'git/isomorphic-git@1.43.0',
9967
10015
  };
9968
10016
 
9969
10017
  class FIFO {
@@ -15591,7 +15639,7 @@ async function readTree({
15591
15639
  * @param {FsClient} args.fs - a file system client
15592
15640
  * @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
15593
15641
  * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
15594
- * @param {string} args.filepath - The path to the file to remove from the index
15642
+ * @param {string|string[]} args.filepath - The path to the file to remove from the index, or an array of paths
15595
15643
  * @param {object} [args.cache] - a [cache](cache.md) object
15596
15644
  *
15597
15645
  * @returns {Promise<void>} Resolves successfully once the git index has been updated
@@ -15600,6 +15648,11 @@ async function readTree({
15600
15648
  * await git.remove({ fs, dir: '/tutorial', filepath: 'README.md' })
15601
15649
  * console.log('done')
15602
15650
  *
15651
+ * @example
15652
+ * // remove several files from the index with a single write of the index
15653
+ * await git.remove({ fs, dir: '/tutorial', filepath: ['README.md', 'docs/old.md'] })
15654
+ * console.log('done')
15655
+ *
15603
15656
  */
15604
15657
  async function remove({
15605
15658
  fs: _fs,
@@ -15618,7 +15671,10 @@ async function remove({
15618
15671
  await GitIndexManager.acquire(
15619
15672
  { fs: fsp, gitdir: updatedGitdir, cache },
15620
15673
  async function (index) {
15621
- index.delete({ filepath });
15674
+ const filepaths = Array.isArray(filepath) ? filepath : [filepath];
15675
+ for (const currentFilepath of filepaths) {
15676
+ index.delete({ filepath: currentFilepath });
15677
+ }
15622
15678
  }
15623
15679
  );
15624
15680
  } catch (err) {
@@ -2902,7 +2902,7 @@ export function readTree({ fs, dir, gitdir, oid, filepath, cache, }: {
2902
2902
  * @param {FsClient} args.fs - a file system client
2903
2903
  * @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
2904
2904
  * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
2905
- * @param {string} args.filepath - The path to the file to remove from the index
2905
+ * @param {string|string[]} args.filepath - The path to the file to remove from the index, or an array of paths
2906
2906
  * @param {object} [args.cache] - a [cache](cache.md) object
2907
2907
  *
2908
2908
  * @returns {Promise<void>} Resolves successfully once the git index has been updated
@@ -2911,12 +2911,17 @@ export function readTree({ fs, dir, gitdir, oid, filepath, cache, }: {
2911
2911
  * await git.remove({ fs, dir: '/tutorial', filepath: 'README.md' })
2912
2912
  * console.log('done')
2913
2913
  *
2914
+ * @example
2915
+ * // remove several files from the index with a single write of the index
2916
+ * await git.remove({ fs, dir: '/tutorial', filepath: ['README.md', 'docs/old.md'] })
2917
+ * console.log('done')
2918
+ *
2914
2919
  */
2915
2920
  export function remove({ fs: _fs, dir, gitdir, filepath, cache, }: {
2916
2921
  fs: FsClient;
2917
2922
  dir?: string | undefined;
2918
2923
  gitdir?: string | undefined;
2919
- filepath: string;
2924
+ filepath: string | string[];
2920
2925
  cache?: object;
2921
2926
  }): Promise<void>;
2922
2927
  /**