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.
@@ -3811,20 +3811,34 @@ class GitCommit {
3811
3811
  const obj = {
3812
3812
  parent: [],
3813
3813
  };
3814
- const seen = new Set();
3815
- for (const h of hs) {
3816
- const key = h.slice(0, h.indexOf(' '));
3817
- const value = h.slice(h.indexOf(' ') + 1);
3818
- if (Array.isArray(obj[key])) {
3819
- obj[key].push(value);
3820
- } else if (!seen.has(key)) {
3821
- // Only `parent` may appear more than once. For every other header the
3822
- // first occurrence wins, the way canonical git reads them. Keeping the
3823
- // last one instead would make a commit with a duplicate `tree` header
3824
- // resolve to a different tree here than in git, under the same oid.
3825
- seen.add(key);
3826
- obj[key] = value;
3827
- }
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]);
3828
3842
  }
3829
3843
  if (obj.author) {
3830
3844
  obj.author = parseAuthor(obj.author);
package/managers/index.js CHANGED
@@ -3804,20 +3804,34 @@ class GitCommit {
3804
3804
  const obj = {
3805
3805
  parent: [],
3806
3806
  };
3807
- const seen = new Set();
3808
- for (const h of hs) {
3809
- const key = h.slice(0, h.indexOf(' '));
3810
- const value = h.slice(h.indexOf(' ') + 1);
3811
- if (Array.isArray(obj[key])) {
3812
- obj[key].push(value);
3813
- } else if (!seen.has(key)) {
3814
- // Only `parent` may appear more than once. For every other header the
3815
- // first occurrence wins, the way canonical git reads them. Keeping the
3816
- // last one instead would make a commit with a duplicate `tree` header
3817
- // resolve to a different tree here than in git, under the same oid.
3818
- seen.add(key);
3819
- obj[key] = value;
3820
- }
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]);
3821
3835
  }
3822
3836
  if (obj.author) {
3823
3837
  obj.author = parseAuthor(obj.author);