isomorphic-git 1.44.7 → 1.44.9

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/index.cjs CHANGED
@@ -622,7 +622,8 @@ function SecondsNanoseconds(
622
622
  milliseconds = date.valueOf();
623
623
  }
624
624
  const seconds = Math.floor(milliseconds / 1000);
625
- const nanoseconds = (milliseconds - seconds * 1000) * 1000000;
625
+ // Match the integer precision used when these timestamps are written to the index.
626
+ const nanoseconds = Math.floor((milliseconds - seconds * 1000) * 1000000);
626
627
  return [seconds, nanoseconds]
627
628
  }
628
629
 
@@ -1043,7 +1044,9 @@ function compareStats(entry, stats, filemode = true, trustino = true) {
1043
1044
  const staleness =
1044
1045
  (filemode && e.mode !== s.mode) ||
1045
1046
  e.mtimeSeconds !== s.mtimeSeconds ||
1047
+ e.mtimeNanoseconds !== s.mtimeNanoseconds ||
1046
1048
  e.ctimeSeconds !== s.ctimeSeconds ||
1049
+ e.ctimeNanoseconds !== s.ctimeNanoseconds ||
1047
1050
  e.uid !== s.uid ||
1048
1051
  e.gid !== s.gid ||
1049
1052
  (trustino && e.ino !== s.ino) ||
@@ -4615,12 +4618,16 @@ ${obj.gpgsig ? obj.gpgsig : ''}`
4615
4618
  }
4616
4619
  }
4617
4620
  const obj = {};
4621
+ const seen = new Set();
4618
4622
  for (const h of hs) {
4619
4623
  const key = h.slice(0, h.indexOf(' '));
4620
4624
  const value = h.slice(h.indexOf(' ') + 1);
4621
- if (Array.isArray(obj[key])) {
4622
- obj[key].push(value);
4623
- } else {
4625
+ // A tag header may appear only once, so the first occurrence wins, the
4626
+ // way canonical git reads them. Keeping the last one instead would make a
4627
+ // tag with a duplicate `object` header point at a different target here
4628
+ // than in git, under the same oid.
4629
+ if (!seen.has(key)) {
4630
+ seen.add(key);
4624
4631
  obj[key] = value;
4625
4632
  }
4626
4633
  }
@@ -4751,12 +4758,18 @@ class GitCommit {
4751
4758
  const obj = {
4752
4759
  parent: [],
4753
4760
  };
4761
+ const seen = new Set();
4754
4762
  for (const h of hs) {
4755
4763
  const key = h.slice(0, h.indexOf(' '));
4756
4764
  const value = h.slice(h.indexOf(' ') + 1);
4757
4765
  if (Array.isArray(obj[key])) {
4758
4766
  obj[key].push(value);
4759
- } else {
4767
+ } else if (!seen.has(key)) {
4768
+ // Only `parent` may appear more than once. For every other header the
4769
+ // first occurrence wins, the way canonical git reads them. Keeping the
4770
+ // last one instead would make a commit with a duplicate `tree` header
4771
+ // resolve to a different tree here than in git, under the same oid.
4772
+ seen.add(key);
4760
4773
  obj[key] = value;
4761
4774
  }
4762
4775
  }
@@ -9757,13 +9770,25 @@ class GitPktLine {
9757
9770
  const reader = new StreamReader(stream);
9758
9771
  return async function read() {
9759
9772
  try {
9760
- let length = await reader.read(4);
9761
- if (length == null) return true
9762
- length = parseInt(length.toString('utf8'), 16);
9773
+ const header = await reader.read(4);
9774
+ if (header == null || header.length === 0) return true
9775
+ const hex = header.toString('utf8');
9776
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
9777
+ throw new ParseError('four hexadecimal digits', hex)
9778
+ }
9779
+ const length = parseInt(hex, 16);
9763
9780
  if (length === 0) return null
9764
9781
  if (length === 1) return null // delim packets
9782
+ if (length < 4) {
9783
+ throw new ParseError('pkt-line length of 0, 1, or at least 4', hex)
9784
+ }
9765
9785
  const buffer = await reader.read(length - 4);
9766
- if (buffer == null) return true
9786
+ if (buffer == null || buffer.length !== length - 4) {
9787
+ throw new ParseError(
9788
+ `${length - 4} bytes of pkt-line data`,
9789
+ `${buffer == null ? 0 : buffer.length} bytes`
9790
+ )
9791
+ }
9767
9792
  return buffer
9768
9793
  } catch (err) {
9769
9794
  stream.error = err;
@@ -10255,8 +10280,8 @@ function filterCapabilities(server, client) {
10255
10280
 
10256
10281
  const pkg = {
10257
10282
  name: 'isomorphic-git',
10258
- version: '1.44.7',
10259
- agent: 'git/isomorphic-git@1.44.7',
10283
+ version: '1.44.9',
10284
+ agent: 'git/isomorphic-git@1.44.9',
10260
10285
  };
10261
10286
 
10262
10287
  class FIFO {
package/index.js CHANGED
@@ -615,7 +615,8 @@ function SecondsNanoseconds(
615
615
  milliseconds = date.valueOf();
616
616
  }
617
617
  const seconds = Math.floor(milliseconds / 1000);
618
- const nanoseconds = (milliseconds - seconds * 1000) * 1000000;
618
+ // Match the integer precision used when these timestamps are written to the index.
619
+ const nanoseconds = Math.floor((milliseconds - seconds * 1000) * 1000000);
619
620
  return [seconds, nanoseconds]
620
621
  }
621
622
 
@@ -1036,7 +1037,9 @@ function compareStats(entry, stats, filemode = true, trustino = true) {
1036
1037
  const staleness =
1037
1038
  (filemode && e.mode !== s.mode) ||
1038
1039
  e.mtimeSeconds !== s.mtimeSeconds ||
1040
+ e.mtimeNanoseconds !== s.mtimeNanoseconds ||
1039
1041
  e.ctimeSeconds !== s.ctimeSeconds ||
1042
+ e.ctimeNanoseconds !== s.ctimeNanoseconds ||
1040
1043
  e.uid !== s.uid ||
1041
1044
  e.gid !== s.gid ||
1042
1045
  (trustino && e.ino !== s.ino) ||
@@ -4602,12 +4605,16 @@ ${obj.gpgsig ? obj.gpgsig : ''}`
4602
4605
  }
4603
4606
  }
4604
4607
  const obj = {};
4608
+ const seen = new Set();
4605
4609
  for (const h of hs) {
4606
4610
  const key = h.slice(0, h.indexOf(' '));
4607
4611
  const value = h.slice(h.indexOf(' ') + 1);
4608
- if (Array.isArray(obj[key])) {
4609
- obj[key].push(value);
4610
- } else {
4612
+ // A tag header may appear only once, so the first occurrence wins, the
4613
+ // way canonical git reads them. Keeping the last one instead would make a
4614
+ // tag with a duplicate `object` header point at a different target here
4615
+ // than in git, under the same oid.
4616
+ if (!seen.has(key)) {
4617
+ seen.add(key);
4611
4618
  obj[key] = value;
4612
4619
  }
4613
4620
  }
@@ -4738,12 +4745,18 @@ class GitCommit {
4738
4745
  const obj = {
4739
4746
  parent: [],
4740
4747
  };
4748
+ const seen = new Set();
4741
4749
  for (const h of hs) {
4742
4750
  const key = h.slice(0, h.indexOf(' '));
4743
4751
  const value = h.slice(h.indexOf(' ') + 1);
4744
4752
  if (Array.isArray(obj[key])) {
4745
4753
  obj[key].push(value);
4746
- } else {
4754
+ } else if (!seen.has(key)) {
4755
+ // Only `parent` may appear more than once. For every other header the
4756
+ // first occurrence wins, the way canonical git reads them. Keeping the
4757
+ // last one instead would make a commit with a duplicate `tree` header
4758
+ // resolve to a different tree here than in git, under the same oid.
4759
+ seen.add(key);
4747
4760
  obj[key] = value;
4748
4761
  }
4749
4762
  }
@@ -9744,13 +9757,25 @@ class GitPktLine {
9744
9757
  const reader = new StreamReader(stream);
9745
9758
  return async function read() {
9746
9759
  try {
9747
- let length = await reader.read(4);
9748
- if (length == null) return true
9749
- length = parseInt(length.toString('utf8'), 16);
9760
+ const header = await reader.read(4);
9761
+ if (header == null || header.length === 0) return true
9762
+ const hex = header.toString('utf8');
9763
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
9764
+ throw new ParseError('four hexadecimal digits', hex)
9765
+ }
9766
+ const length = parseInt(hex, 16);
9750
9767
  if (length === 0) return null
9751
9768
  if (length === 1) return null // delim packets
9769
+ if (length < 4) {
9770
+ throw new ParseError('pkt-line length of 0, 1, or at least 4', hex)
9771
+ }
9752
9772
  const buffer = await reader.read(length - 4);
9753
- if (buffer == null) return true
9773
+ if (buffer == null || buffer.length !== length - 4) {
9774
+ throw new ParseError(
9775
+ `${length - 4} bytes of pkt-line data`,
9776
+ `${buffer == null ? 0 : buffer.length} bytes`
9777
+ )
9778
+ }
9754
9779
  return buffer
9755
9780
  } catch (err) {
9756
9781
  stream.error = err;
@@ -10242,8 +10267,8 @@ function filterCapabilities(server, client) {
10242
10267
 
10243
10268
  const pkg = {
10244
10269
  name: 'isomorphic-git',
10245
- version: '1.44.7',
10246
- agent: 'git/isomorphic-git@1.44.7',
10270
+ version: '1.44.9',
10271
+ agent: 'git/isomorphic-git@1.44.9',
10247
10272
  };
10248
10273
 
10249
10274
  class FIFO {