isomorphic-git 1.44.8 → 1.44.10

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.
@@ -1196,7 +1196,8 @@ function SecondsNanoseconds(
1196
1196
  milliseconds = date.valueOf();
1197
1197
  }
1198
1198
  const seconds = Math.floor(milliseconds / 1000);
1199
- const nanoseconds = (milliseconds - seconds * 1000) * 1000000;
1199
+ // Match the integer precision used when these timestamps are written to the index.
1200
+ const nanoseconds = Math.floor((milliseconds - seconds * 1000) * 1000000);
1200
1201
  return [seconds, nanoseconds]
1201
1202
  }
1202
1203
 
@@ -1617,7 +1618,9 @@ function compareStats(entry, stats, filemode = true, trustino = true) {
1617
1618
  const staleness =
1618
1619
  (filemode && e.mode !== s.mode) ||
1619
1620
  e.mtimeSeconds !== s.mtimeSeconds ||
1621
+ e.mtimeNanoseconds !== s.mtimeNanoseconds ||
1620
1622
  e.ctimeSeconds !== s.ctimeSeconds ||
1623
+ e.ctimeNanoseconds !== s.ctimeNanoseconds ||
1621
1624
  e.uid !== s.uid ||
1622
1625
  e.gid !== s.gid ||
1623
1626
  (trustino && e.ino !== s.ino) ||
@@ -3668,12 +3671,16 @@ ${obj.gpgsig ? obj.gpgsig : ''}`
3668
3671
  }
3669
3672
  }
3670
3673
  const obj = {};
3674
+ const seen = new Set();
3671
3675
  for (const h of hs) {
3672
3676
  const key = h.slice(0, h.indexOf(' '));
3673
3677
  const value = h.slice(h.indexOf(' ') + 1);
3674
- if (Array.isArray(obj[key])) {
3675
- obj[key].push(value);
3676
- } else {
3678
+ // A tag header may appear only once, so the first occurrence wins, the
3679
+ // way canonical git reads them. Keeping the last one instead would make a
3680
+ // tag with a duplicate `object` header point at a different target here
3681
+ // than in git, under the same oid.
3682
+ if (!seen.has(key)) {
3683
+ seen.add(key);
3677
3684
  obj[key] = value;
3678
3685
  }
3679
3686
  }
@@ -3804,14 +3811,34 @@ class GitCommit {
3804
3811
  const obj = {
3805
3812
  parent: [],
3806
3813
  };
3807
- for (const h of hs) {
3808
- const key = h.slice(0, h.indexOf(' '));
3809
- const value = h.slice(h.indexOf(' ') + 1);
3810
- if (Array.isArray(obj[key])) {
3811
- obj[key].push(value);
3812
- } else {
3813
- obj[key] = value;
3814
- }
3814
+ const keyOf = h => h.slice(0, h.indexOf(' '));
3815
+ const valueOf = h => h.slice(h.indexOf(' ') + 1);
3816
+ // Git reads the start of a commit by position: one `tree`, then the
3817
+ // `parent` lines that follow it directly. Anything after that run is an
3818
+ // extra header that git keeps but never interprets, so a `tree` or
3819
+ // `parent` further down must not count here either. Reading them would
3820
+ // give the same oid a different tree, or a different ancestry, than git
3821
+ // and every other implementation reports.
3822
+ if (hs.length === 0 || keyOf(hs[0]) !== 'tree') {
3823
+ throw new ParseError(
3824
+ 'tree as the first commit header',
3825
+ keyOf(hs[0] || '')
3826
+ )
3827
+ }
3828
+ obj.tree = valueOf(hs[0]);
3829
+ let index = 1;
3830
+ while (index < hs.length && keyOf(hs[index]) === 'parent') {
3831
+ obj.parent.push(valueOf(hs[index]));
3832
+ index++;
3833
+ }
3834
+ const seen = new Set(['tree', 'parent']);
3835
+ for (; index < hs.length; index++) {
3836
+ const key = keyOf(hs[index]);
3837
+ // The first occurrence of a single-valued header wins, the way canonical
3838
+ // git reads them.
3839
+ if (seen.has(key)) continue
3840
+ seen.add(key);
3841
+ obj[key] = valueOf(hs[index]);
3815
3842
  }
3816
3843
  if (obj.author) {
3817
3844
  obj.author = parseAuthor(obj.author);
package/managers/index.js CHANGED
@@ -1189,7 +1189,8 @@ function SecondsNanoseconds(
1189
1189
  milliseconds = date.valueOf();
1190
1190
  }
1191
1191
  const seconds = Math.floor(milliseconds / 1000);
1192
- const nanoseconds = (milliseconds - seconds * 1000) * 1000000;
1192
+ // Match the integer precision used when these timestamps are written to the index.
1193
+ const nanoseconds = Math.floor((milliseconds - seconds * 1000) * 1000000);
1193
1194
  return [seconds, nanoseconds]
1194
1195
  }
1195
1196
 
@@ -1610,7 +1611,9 @@ function compareStats(entry, stats, filemode = true, trustino = true) {
1610
1611
  const staleness =
1611
1612
  (filemode && e.mode !== s.mode) ||
1612
1613
  e.mtimeSeconds !== s.mtimeSeconds ||
1614
+ e.mtimeNanoseconds !== s.mtimeNanoseconds ||
1613
1615
  e.ctimeSeconds !== s.ctimeSeconds ||
1616
+ e.ctimeNanoseconds !== s.ctimeNanoseconds ||
1614
1617
  e.uid !== s.uid ||
1615
1618
  e.gid !== s.gid ||
1616
1619
  (trustino && e.ino !== s.ino) ||
@@ -3661,12 +3664,16 @@ ${obj.gpgsig ? obj.gpgsig : ''}`
3661
3664
  }
3662
3665
  }
3663
3666
  const obj = {};
3667
+ const seen = new Set();
3664
3668
  for (const h of hs) {
3665
3669
  const key = h.slice(0, h.indexOf(' '));
3666
3670
  const value = h.slice(h.indexOf(' ') + 1);
3667
- if (Array.isArray(obj[key])) {
3668
- obj[key].push(value);
3669
- } else {
3671
+ // A tag header may appear only once, so the first occurrence wins, the
3672
+ // way canonical git reads them. Keeping the last one instead would make a
3673
+ // tag with a duplicate `object` header point at a different target here
3674
+ // than in git, under the same oid.
3675
+ if (!seen.has(key)) {
3676
+ seen.add(key);
3670
3677
  obj[key] = value;
3671
3678
  }
3672
3679
  }
@@ -3797,14 +3804,34 @@ class GitCommit {
3797
3804
  const obj = {
3798
3805
  parent: [],
3799
3806
  };
3800
- for (const h of hs) {
3801
- const key = h.slice(0, h.indexOf(' '));
3802
- const value = h.slice(h.indexOf(' ') + 1);
3803
- if (Array.isArray(obj[key])) {
3804
- obj[key].push(value);
3805
- } else {
3806
- obj[key] = value;
3807
- }
3807
+ const keyOf = h => h.slice(0, h.indexOf(' '));
3808
+ const valueOf = h => h.slice(h.indexOf(' ') + 1);
3809
+ // Git reads the start of a commit by position: one `tree`, then the
3810
+ // `parent` lines that follow it directly. Anything after that run is an
3811
+ // extra header that git keeps but never interprets, so a `tree` or
3812
+ // `parent` further down must not count here either. Reading them would
3813
+ // give the same oid a different tree, or a different ancestry, than git
3814
+ // and every other implementation reports.
3815
+ if (hs.length === 0 || keyOf(hs[0]) !== 'tree') {
3816
+ throw new ParseError(
3817
+ 'tree as the first commit header',
3818
+ keyOf(hs[0] || '')
3819
+ )
3820
+ }
3821
+ obj.tree = valueOf(hs[0]);
3822
+ let index = 1;
3823
+ while (index < hs.length && keyOf(hs[index]) === 'parent') {
3824
+ obj.parent.push(valueOf(hs[index]));
3825
+ index++;
3826
+ }
3827
+ const seen = new Set(['tree', 'parent']);
3828
+ for (; index < hs.length; index++) {
3829
+ const key = keyOf(hs[index]);
3830
+ // The first occurrence of a single-valued header wins, the way canonical
3831
+ // git reads them.
3832
+ if (seen.has(key)) continue
3833
+ seen.add(key);
3834
+ obj[key] = valueOf(hs[index]);
3808
3835
  }
3809
3836
  if (obj.author) {
3810
3837
  obj.author = parseAuthor(obj.author);