isomorphic-git 1.26.0 → 1.26.2

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.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import AsyncLock from 'async-lock';
2
2
  import Hash from 'sha.js/sha1.js';
3
- import { join } from 'path';
4
3
  import crc32 from 'crc-32';
5
4
  import pako from 'pako';
6
5
  import pify from 'pify';
@@ -1476,6 +1475,40 @@ function compareRefNames(a, b) {
1476
1475
  return tmp
1477
1476
  }
1478
1477
 
1478
+ const memo = new Map();
1479
+ function normalizePath(path) {
1480
+ let normalizedPath = memo.get(path);
1481
+ if (!normalizedPath) {
1482
+ normalizedPath = normalizePathInternal(path);
1483
+ memo.set(path, normalizedPath);
1484
+ }
1485
+ return normalizedPath
1486
+ }
1487
+
1488
+ function normalizePathInternal(path) {
1489
+ path = path
1490
+ .split('/./')
1491
+ .join('/') // Replace '/./' with '/'
1492
+ .replace(/\/{2,}/g, '/'); // Replace consecutive '/'
1493
+
1494
+ if (path === '/.') return '/' // if path === '/.' return '/'
1495
+ if (path === './') return '.' // if path === './' return '.'
1496
+
1497
+ if (path.startsWith('./')) path = path.slice(2); // Remove leading './'
1498
+ if (path.endsWith('/.')) path = path.slice(0, -2); // Remove trailing '/.'
1499
+ if (path.length > 1 && path.endsWith('/')) path = path.slice(0, -1); // Remove trailing '/'
1500
+
1501
+ if (path === '') return '.' // if path === '' return '.'
1502
+
1503
+ return path
1504
+ }
1505
+
1506
+ // For some reason path.posix.join is undefined in webpack
1507
+
1508
+ function join(...parts) {
1509
+ return normalizePath(parts.map(normalizePath).join('/'))
1510
+ }
1511
+
1479
1512
  // This is straight from parse_unit_factor in config.c of canonical git
1480
1513
  const num = val => {
1481
1514
  val = val.toLowerCase();
@@ -1590,7 +1623,7 @@ const getPath = (section, subsection, name) => {
1590
1623
  .join('.')
1591
1624
  };
1592
1625
 
1593
- const normalizePath = path => {
1626
+ const normalizePath$1 = path => {
1594
1627
  const pathSegments = path.split('.');
1595
1628
  const section = pathSegments.shift();
1596
1629
  const name = pathSegments.pop();
@@ -1646,7 +1679,7 @@ class GitConfig {
1646
1679
  }
1647
1680
 
1648
1681
  async get(path, getall = false) {
1649
- const normalizedPath = normalizePath(path).path;
1682
+ const normalizedPath = normalizePath$1(path).path;
1650
1683
  const allValues = this.parsedConfig
1651
1684
  .filter(config => config.path === normalizedPath)
1652
1685
  .map(({ section, name, value }) => {
@@ -1684,7 +1717,7 @@ class GitConfig {
1684
1717
  name,
1685
1718
  path: normalizedPath,
1686
1719
  sectionPath,
1687
- } = normalizePath(path);
1720
+ } = normalizePath$1(path);
1688
1721
  const configIndex = findLastIndex(
1689
1722
  this.parsedConfig,
1690
1723
  config => config.path === normalizedPath
@@ -3131,43 +3164,46 @@ async function _readObject({
3131
3164
  oid,
3132
3165
  getExternalRefDelta,
3133
3166
  });
3134
- }
3135
- // Finally
3136
- if (!result) {
3137
- throw new NotFoundError(oid)
3167
+
3168
+ if (!result) {
3169
+ throw new NotFoundError(oid)
3170
+ }
3171
+
3172
+ // Directly return packed result, as specified: packed objects always return the 'content' format.
3173
+ return result
3138
3174
  }
3139
3175
 
3176
+ // Loose objects are always deflated, return early
3140
3177
  if (format === 'deflated') {
3141
3178
  return result
3142
3179
  }
3143
3180
 
3181
+ // All loose objects are deflated but the hard-coded empty tree is `wrapped` so we have to check if we need to inflate the object.
3144
3182
  if (result.format === 'deflated') {
3145
3183
  result.object = Buffer.from(await inflate(result.object));
3146
3184
  result.format = 'wrapped';
3147
3185
  }
3148
3186
 
3149
- if (result.format === 'wrapped') {
3150
- if (format === 'wrapped' && result.format === 'wrapped') {
3151
- return result
3152
- }
3153
- const sha = await shasum(result.object);
3154
- if (sha !== oid) {
3155
- throw new InternalError(
3156
- `SHA check failed! Expected ${oid}, computed ${sha}`
3157
- )
3158
- }
3159
- const { object, type } = GitObject.unwrap(result.object);
3160
- result.type = type;
3161
- result.object = object;
3162
- result.format = 'content';
3187
+ if (format === 'wrapped') {
3188
+ return result
3163
3189
  }
3164
3190
 
3165
- if (result.format === 'content') {
3166
- if (format === 'content') return result
3167
- return
3191
+ const sha = await shasum(result.object);
3192
+ if (sha !== oid) {
3193
+ throw new InternalError(
3194
+ `SHA check failed! Expected ${oid}, computed ${sha}`
3195
+ )
3196
+ }
3197
+ const { object, type } = GitObject.unwrap(result.object);
3198
+ result.type = type;
3199
+ result.object = object;
3200
+ result.format = 'content';
3201
+
3202
+ if (format === 'content') {
3203
+ return result
3168
3204
  }
3169
3205
 
3170
- throw new InternalError(`invalid format "${result.format}"`)
3206
+ throw new InternalError(`invalid requested format "${format}"`)
3171
3207
  }
3172
3208
 
3173
3209
  class AlreadyExistsError extends BaseError {
@@ -7409,8 +7445,8 @@ function filterCapabilities(server, client) {
7409
7445
 
7410
7446
  const pkg = {
7411
7447
  name: 'isomorphic-git',
7412
- version: '1.26.0',
7413
- agent: 'git/isomorphic-git@1.26.0',
7448
+ version: '1.26.2',
7449
+ agent: 'git/isomorphic-git@1.26.2',
7414
7450
  };
7415
7451
 
7416
7452
  class FIFO {