isomorphic-git 1.44.4 → 1.44.6

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
@@ -464,6 +464,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
464
464
  <td align="center"><a href="https://github.com/macabeus"><img src="https://avatars.githubusercontent.com/u/9501115?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Bruno Macabeus</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=macabeus" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=macabeus" title="Tests">⚠️</a></td>
465
465
  <td align="center"><a href="https://github.com/snowyukitty"><img src="https://avatars.githubusercontent.com/u/270071858?v=4?s=60" width="60px;" alt=""/><br /><sub><b>snowyukitty</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=snowyukitty" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=snowyukitty" title="Tests">⚠️</a></td>
466
466
  <td align="center"><a href="https://github.com/ShahabAhmed01"><img src="https://avatars.githubusercontent.com/u/192491541?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Shahab Ahmed</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=ShahabAhmed01" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=ShahabAhmed01" title="Tests">⚠️</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=ShahabAhmed01" title="Documentation">📖</a></td>
467
+ <td align="center"><a href="https://github.com/wleeaf"><img src="https://avatars.githubusercontent.com/u/179125857?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Wleeaf</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=wleeaf" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=wleeaf" title="Tests">⚠️</a></td>
467
468
  </tr>
468
469
  </table>
469
470
 
package/index.cjs CHANGED
@@ -1823,9 +1823,11 @@ const schema = {
1823
1823
  // section is alphanumeric (ASCII) with - and .
1824
1824
  // section is case insensitive
1825
1825
  // subsection is optional
1826
- // subsection is specified after section and one or more spaces
1827
- // subsection is specified between double quotes
1828
- const SECTION_LINE_REGEX = /^\[([A-Za-z0-9-.]+)(?: "(.*)")?\]$/;
1826
+ // subsection is specified after section and one or more spaces or tabs
1827
+ // subsection is specified between double quotes, where \ escapes the next character
1828
+ // a comment can follow the section header
1829
+ const SECTION_LINE_REGEX =
1830
+ /^\[([A-Za-z0-9-.]+)(?:[ \t]+"((?:[^"\\]|\\.)*)")?\][ \t]*(?:[#;].*)?$/;
1829
1831
  const SECTION_REGEX = /^[A-Za-z0-9-.]+$/;
1830
1832
 
1831
1833
  // variable lines contain a name, and equal sign and then a value
@@ -1841,7 +1843,8 @@ const extractSectionLine = line => {
1841
1843
  const matches = SECTION_LINE_REGEX.exec(line);
1842
1844
  if (matches != null) {
1843
1845
  const [section, subsection] = matches.slice(1);
1844
- return [section, subsection]
1846
+ // Like canonical git, drop the backslash of an escaped character
1847
+ return [section, subsection && subsection.replace(/\\(.)/g, '$1')]
1845
1848
  }
1846
1849
  return null
1847
1850
  };
@@ -3371,6 +3374,69 @@ function otherVarIntDecode(reader, startWith) {
3371
3374
  return result
3372
3375
  }
3373
3376
 
3377
+ // Memory that `fromPack` may use to keep resolved objects for delta bases.
3378
+ // An object larger than a quarter of this is not kept.
3379
+ const RESOLVE_CACHE_BYTES = 32 * 1024 * 1024;
3380
+
3381
+ // A cache that drops the least recently used object when it holds too many bytes.
3382
+ class ObjectCache {
3383
+ constructor(maxBytes) {
3384
+ this.maxBytes = maxBytes;
3385
+ this.bytes = 0;
3386
+ this.map = new Map();
3387
+ }
3388
+
3389
+ get(key) {
3390
+ const value = this.map.get(key);
3391
+ if (value !== undefined) {
3392
+ this.map.delete(key);
3393
+ this.map.set(key, value);
3394
+ }
3395
+ return value
3396
+ }
3397
+
3398
+ set(key, value) {
3399
+ const size = value.object.byteLength;
3400
+ if (size > this.maxBytes / 4) return
3401
+ this.map.set(key, value);
3402
+ this.bytes += size;
3403
+ for (const [oldKey, old] of this.map) {
3404
+ if (this.bytes <= this.maxBytes) break
3405
+ this.map.delete(oldKey);
3406
+ this.bytes -= old.object.byteLength;
3407
+ }
3408
+ }
3409
+ }
3410
+
3411
+ // Resolve an object from the data that `listpack` already inflated.
3412
+ // Return null when the object needs `readSlice`. This happens when the base of
3413
+ // a delta is not in the cache, or when the delta is corrupt.
3414
+ function resolveInflated(
3415
+ { type, data, reference, offset },
3416
+ cache,
3417
+ offsetByOid
3418
+ ) {
3419
+ // `applyDelta` and `shasum` need a Buffer. This is a view and copies nothing.
3420
+ const object = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
3421
+ if (type !== 'ofs-delta' && type !== 'ref-delta') return { type, object }
3422
+ const baseOffset =
3423
+ type === 'ofs-delta'
3424
+ ? offset - decodeVarInt(new BufferCursor(reference))
3425
+ : offsetByOid.get(reference.toString('hex'));
3426
+ const base = cache.get(baseOffset);
3427
+ if (!base) return null
3428
+ try {
3429
+ return {
3430
+ type: base.type,
3431
+ object: Buffer.from(applyDelta(object, base.object)),
3432
+ }
3433
+ } catch (err) {
3434
+ // A corrupt delta. `readSlice` reports it again. Any other error is a bug.
3435
+ if (err instanceof InternalError || err instanceof RangeError) return null
3436
+ throw err
3437
+ }
3438
+ }
3439
+
3374
3440
  class GitPackIndex {
3375
3441
  constructor(stuff) {
3376
3442
  Object.assign(this, stuff);
@@ -3442,6 +3508,9 @@ class GitPackIndex {
3442
3508
  const offsets = new Map();
3443
3509
  let totalObjectCount = null;
3444
3510
  let lastPercent = null;
3511
+ // Objects that `listpack` inflated, by pack offset. A delta finds its base here.
3512
+ const cache = new ObjectCache(RESOLVE_CACHE_BYTES);
3513
+ const offsetByOid = new Map();
3445
3514
 
3446
3515
  await listpack([pack], async ({ data, type, reference, offset, num }) => {
3447
3516
  if (totalObjectCount === null) totalObjectCount = num;
@@ -3477,6 +3546,20 @@ class GitPackIndex {
3477
3546
  offset,
3478
3547
  };
3479
3548
  }
3549
+
3550
+ // The object is already inflated, so get its oid now. Then the loop below
3551
+ // does not inflate it again. That loop reads all other objects.
3552
+ const o = offsetToObject[offset];
3553
+ if (!o) return
3554
+ const resolved = resolveInflated(
3555
+ { type, data, reference, offset },
3556
+ cache,
3557
+ offsetByOid
3558
+ );
3559
+ if (!resolved) return
3560
+ o.oid = await shasum(GitObject.wrap(resolved));
3561
+ offsetByOid.set(o.oid, offset);
3562
+ cache.set(offset, resolved);
3480
3563
  });
3481
3564
 
3482
3565
  // We need to know the lengths of the slices to compute the CRCs.
@@ -3520,20 +3603,21 @@ class GitPackIndex {
3520
3603
  lastPercent = percent;
3521
3604
 
3522
3605
  const o = offsetToObject[offset];
3523
- if (o.oid) continue
3524
- try {
3525
- p.readDepth = 0;
3526
- p.externalReadDepth = 0;
3527
- const { type, object } = await p.readSlice({ start: offset });
3528
- objectsByDepth[p.readDepth] += 1;
3529
- const oid = await shasum(GitObject.wrap({ type, object }));
3530
- o.oid = oid;
3531
- hashes.push(oid);
3532
- offsets.set(oid, offset);
3533
- crcs[oid] = o.crc;
3534
- } catch (err) {
3535
- continue
3606
+ if (!o.oid) {
3607
+ // The first pass did not resolve this object, so read it.
3608
+ try {
3609
+ p.readDepth = 0;
3610
+ p.externalReadDepth = 0;
3611
+ const { type, object } = await p.readSlice({ start: offset });
3612
+ objectsByDepth[p.readDepth] += 1;
3613
+ o.oid = await shasum(GitObject.wrap({ type, object }));
3614
+ } catch (err) {
3615
+ continue
3616
+ }
3536
3617
  }
3618
+ hashes.push(o.oid);
3619
+ offsets.set(o.oid, offset);
3620
+ crcs[o.oid] = o.crc;
3537
3621
  }
3538
3622
 
3539
3623
  hashes.sort();
@@ -10126,8 +10210,8 @@ function filterCapabilities(server, client) {
10126
10210
 
10127
10211
  const pkg = {
10128
10212
  name: 'isomorphic-git',
10129
- version: '1.44.4',
10130
- agent: 'git/isomorphic-git@1.44.4',
10213
+ version: '1.44.6',
10214
+ agent: 'git/isomorphic-git@1.44.6',
10131
10215
  };
10132
10216
 
10133
10217
  class FIFO {
package/index.js CHANGED
@@ -1816,9 +1816,11 @@ const schema = {
1816
1816
  // section is alphanumeric (ASCII) with - and .
1817
1817
  // section is case insensitive
1818
1818
  // subsection is optional
1819
- // subsection is specified after section and one or more spaces
1820
- // subsection is specified between double quotes
1821
- const SECTION_LINE_REGEX = /^\[([A-Za-z0-9-.]+)(?: "(.*)")?\]$/;
1819
+ // subsection is specified after section and one or more spaces or tabs
1820
+ // subsection is specified between double quotes, where \ escapes the next character
1821
+ // a comment can follow the section header
1822
+ const SECTION_LINE_REGEX =
1823
+ /^\[([A-Za-z0-9-.]+)(?:[ \t]+"((?:[^"\\]|\\.)*)")?\][ \t]*(?:[#;].*)?$/;
1822
1824
  const SECTION_REGEX = /^[A-Za-z0-9-.]+$/;
1823
1825
 
1824
1826
  // variable lines contain a name, and equal sign and then a value
@@ -1834,7 +1836,8 @@ const extractSectionLine = line => {
1834
1836
  const matches = SECTION_LINE_REGEX.exec(line);
1835
1837
  if (matches != null) {
1836
1838
  const [section, subsection] = matches.slice(1);
1837
- return [section, subsection]
1839
+ // Like canonical git, drop the backslash of an escaped character
1840
+ return [section, subsection && subsection.replace(/\\(.)/g, '$1')]
1838
1841
  }
1839
1842
  return null
1840
1843
  };
@@ -3364,6 +3367,69 @@ function otherVarIntDecode(reader, startWith) {
3364
3367
  return result
3365
3368
  }
3366
3369
 
3370
+ // Memory that `fromPack` may use to keep resolved objects for delta bases.
3371
+ // An object larger than a quarter of this is not kept.
3372
+ const RESOLVE_CACHE_BYTES = 32 * 1024 * 1024;
3373
+
3374
+ // A cache that drops the least recently used object when it holds too many bytes.
3375
+ class ObjectCache {
3376
+ constructor(maxBytes) {
3377
+ this.maxBytes = maxBytes;
3378
+ this.bytes = 0;
3379
+ this.map = new Map();
3380
+ }
3381
+
3382
+ get(key) {
3383
+ const value = this.map.get(key);
3384
+ if (value !== undefined) {
3385
+ this.map.delete(key);
3386
+ this.map.set(key, value);
3387
+ }
3388
+ return value
3389
+ }
3390
+
3391
+ set(key, value) {
3392
+ const size = value.object.byteLength;
3393
+ if (size > this.maxBytes / 4) return
3394
+ this.map.set(key, value);
3395
+ this.bytes += size;
3396
+ for (const [oldKey, old] of this.map) {
3397
+ if (this.bytes <= this.maxBytes) break
3398
+ this.map.delete(oldKey);
3399
+ this.bytes -= old.object.byteLength;
3400
+ }
3401
+ }
3402
+ }
3403
+
3404
+ // Resolve an object from the data that `listpack` already inflated.
3405
+ // Return null when the object needs `readSlice`. This happens when the base of
3406
+ // a delta is not in the cache, or when the delta is corrupt.
3407
+ function resolveInflated(
3408
+ { type, data, reference, offset },
3409
+ cache,
3410
+ offsetByOid
3411
+ ) {
3412
+ // `applyDelta` and `shasum` need a Buffer. This is a view and copies nothing.
3413
+ const object = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
3414
+ if (type !== 'ofs-delta' && type !== 'ref-delta') return { type, object }
3415
+ const baseOffset =
3416
+ type === 'ofs-delta'
3417
+ ? offset - decodeVarInt(new BufferCursor(reference))
3418
+ : offsetByOid.get(reference.toString('hex'));
3419
+ const base = cache.get(baseOffset);
3420
+ if (!base) return null
3421
+ try {
3422
+ return {
3423
+ type: base.type,
3424
+ object: Buffer.from(applyDelta(object, base.object)),
3425
+ }
3426
+ } catch (err) {
3427
+ // A corrupt delta. `readSlice` reports it again. Any other error is a bug.
3428
+ if (err instanceof InternalError || err instanceof RangeError) return null
3429
+ throw err
3430
+ }
3431
+ }
3432
+
3367
3433
  class GitPackIndex {
3368
3434
  constructor(stuff) {
3369
3435
  Object.assign(this, stuff);
@@ -3435,6 +3501,9 @@ class GitPackIndex {
3435
3501
  const offsets = new Map();
3436
3502
  let totalObjectCount = null;
3437
3503
  let lastPercent = null;
3504
+ // Objects that `listpack` inflated, by pack offset. A delta finds its base here.
3505
+ const cache = new ObjectCache(RESOLVE_CACHE_BYTES);
3506
+ const offsetByOid = new Map();
3438
3507
 
3439
3508
  await listpack([pack], async ({ data, type, reference, offset, num }) => {
3440
3509
  if (totalObjectCount === null) totalObjectCount = num;
@@ -3470,6 +3539,20 @@ class GitPackIndex {
3470
3539
  offset,
3471
3540
  };
3472
3541
  }
3542
+
3543
+ // The object is already inflated, so get its oid now. Then the loop below
3544
+ // does not inflate it again. That loop reads all other objects.
3545
+ const o = offsetToObject[offset];
3546
+ if (!o) return
3547
+ const resolved = resolveInflated(
3548
+ { type, data, reference, offset },
3549
+ cache,
3550
+ offsetByOid
3551
+ );
3552
+ if (!resolved) return
3553
+ o.oid = await shasum(GitObject.wrap(resolved));
3554
+ offsetByOid.set(o.oid, offset);
3555
+ cache.set(offset, resolved);
3473
3556
  });
3474
3557
 
3475
3558
  // We need to know the lengths of the slices to compute the CRCs.
@@ -3513,20 +3596,21 @@ class GitPackIndex {
3513
3596
  lastPercent = percent;
3514
3597
 
3515
3598
  const o = offsetToObject[offset];
3516
- if (o.oid) continue
3517
- try {
3518
- p.readDepth = 0;
3519
- p.externalReadDepth = 0;
3520
- const { type, object } = await p.readSlice({ start: offset });
3521
- objectsByDepth[p.readDepth] += 1;
3522
- const oid = await shasum(GitObject.wrap({ type, object }));
3523
- o.oid = oid;
3524
- hashes.push(oid);
3525
- offsets.set(oid, offset);
3526
- crcs[oid] = o.crc;
3527
- } catch (err) {
3528
- continue
3599
+ if (!o.oid) {
3600
+ // The first pass did not resolve this object, so read it.
3601
+ try {
3602
+ p.readDepth = 0;
3603
+ p.externalReadDepth = 0;
3604
+ const { type, object } = await p.readSlice({ start: offset });
3605
+ objectsByDepth[p.readDepth] += 1;
3606
+ o.oid = await shasum(GitObject.wrap({ type, object }));
3607
+ } catch (err) {
3608
+ continue
3609
+ }
3529
3610
  }
3611
+ hashes.push(o.oid);
3612
+ offsets.set(o.oid, offset);
3613
+ crcs[o.oid] = o.crc;
3530
3614
  }
3531
3615
 
3532
3616
  hashes.sort();
@@ -10113,8 +10197,8 @@ function filterCapabilities(server, client) {
10113
10197
 
10114
10198
  const pkg = {
10115
10199
  name: 'isomorphic-git',
10116
- version: '1.44.4',
10117
- agent: 'git/isomorphic-git@1.44.4',
10200
+ version: '1.44.6',
10201
+ agent: 'git/isomorphic-git@1.44.6',
10118
10202
  };
10119
10203
 
10120
10204
  class FIFO {