isomorphic-git 1.44.9 → 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.
package/index.cjs CHANGED
@@ -4758,20 +4758,34 @@ class GitCommit {
4758
4758
  const obj = {
4759
4759
  parent: [],
4760
4760
  };
4761
- const seen = new Set();
4762
- for (const h of hs) {
4763
- const key = h.slice(0, h.indexOf(' '));
4764
- const value = h.slice(h.indexOf(' ') + 1);
4765
- if (Array.isArray(obj[key])) {
4766
- obj[key].push(value);
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);
4773
- obj[key] = value;
4774
- }
4761
+ const keyOf = h => h.slice(0, h.indexOf(' '));
4762
+ const valueOf = h => h.slice(h.indexOf(' ') + 1);
4763
+ // Git reads the start of a commit by position: one `tree`, then the
4764
+ // `parent` lines that follow it directly. Anything after that run is an
4765
+ // extra header that git keeps but never interprets, so a `tree` or
4766
+ // `parent` further down must not count here either. Reading them would
4767
+ // give the same oid a different tree, or a different ancestry, than git
4768
+ // and every other implementation reports.
4769
+ if (hs.length === 0 || keyOf(hs[0]) !== 'tree') {
4770
+ throw new ParseError(
4771
+ 'tree as the first commit header',
4772
+ keyOf(hs[0] || '')
4773
+ )
4774
+ }
4775
+ obj.tree = valueOf(hs[0]);
4776
+ let index = 1;
4777
+ while (index < hs.length && keyOf(hs[index]) === 'parent') {
4778
+ obj.parent.push(valueOf(hs[index]));
4779
+ index++;
4780
+ }
4781
+ const seen = new Set(['tree', 'parent']);
4782
+ for (; index < hs.length; index++) {
4783
+ const key = keyOf(hs[index]);
4784
+ // The first occurrence of a single-valued header wins, the way canonical
4785
+ // git reads them.
4786
+ if (seen.has(key)) continue
4787
+ seen.add(key);
4788
+ obj[key] = valueOf(hs[index]);
4775
4789
  }
4776
4790
  if (obj.author) {
4777
4791
  obj.author = parseAuthor(obj.author);
@@ -10280,8 +10294,8 @@ function filterCapabilities(server, client) {
10280
10294
 
10281
10295
  const pkg = {
10282
10296
  name: 'isomorphic-git',
10283
- version: '1.44.9',
10284
- agent: 'git/isomorphic-git@1.44.9',
10297
+ version: '1.44.10',
10298
+ agent: 'git/isomorphic-git@1.44.10',
10285
10299
  };
10286
10300
 
10287
10301
  class FIFO {
package/index.js CHANGED
@@ -4745,20 +4745,34 @@ class GitCommit {
4745
4745
  const obj = {
4746
4746
  parent: [],
4747
4747
  };
4748
- const seen = new Set();
4749
- for (const h of hs) {
4750
- const key = h.slice(0, h.indexOf(' '));
4751
- const value = h.slice(h.indexOf(' ') + 1);
4752
- if (Array.isArray(obj[key])) {
4753
- obj[key].push(value);
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);
4760
- obj[key] = value;
4761
- }
4748
+ const keyOf = h => h.slice(0, h.indexOf(' '));
4749
+ const valueOf = h => h.slice(h.indexOf(' ') + 1);
4750
+ // Git reads the start of a commit by position: one `tree`, then the
4751
+ // `parent` lines that follow it directly. Anything after that run is an
4752
+ // extra header that git keeps but never interprets, so a `tree` or
4753
+ // `parent` further down must not count here either. Reading them would
4754
+ // give the same oid a different tree, or a different ancestry, than git
4755
+ // and every other implementation reports.
4756
+ if (hs.length === 0 || keyOf(hs[0]) !== 'tree') {
4757
+ throw new ParseError(
4758
+ 'tree as the first commit header',
4759
+ keyOf(hs[0] || '')
4760
+ )
4761
+ }
4762
+ obj.tree = valueOf(hs[0]);
4763
+ let index = 1;
4764
+ while (index < hs.length && keyOf(hs[index]) === 'parent') {
4765
+ obj.parent.push(valueOf(hs[index]));
4766
+ index++;
4767
+ }
4768
+ const seen = new Set(['tree', 'parent']);
4769
+ for (; index < hs.length; index++) {
4770
+ const key = keyOf(hs[index]);
4771
+ // The first occurrence of a single-valued header wins, the way canonical
4772
+ // git reads them.
4773
+ if (seen.has(key)) continue
4774
+ seen.add(key);
4775
+ obj[key] = valueOf(hs[index]);
4762
4776
  }
4763
4777
  if (obj.author) {
4764
4778
  obj.author = parseAuthor(obj.author);
@@ -10267,8 +10281,8 @@ function filterCapabilities(server, client) {
10267
10281
 
10268
10282
  const pkg = {
10269
10283
  name: 'isomorphic-git',
10270
- version: '1.44.9',
10271
- agent: 'git/isomorphic-git@1.44.9',
10284
+ version: '1.44.10',
10285
+ agent: 'git/isomorphic-git@1.44.10',
10272
10286
  };
10273
10287
 
10274
10288
  class FIFO {