isomorphic-git 1.44.6 → 1.44.8
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 +1 -0
- package/index.cjs +79 -16
- package/index.js +79 -16
- package/index.umd.min.js +1 -1
- package/index.umd.min.js.map +1 -1
- package/managers/index.cjs +65 -11
- package/managers/index.js +65 -11
- package/managers/index.umd.min.js +1 -1
- package/managers/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/managers/index.cjs
CHANGED
|
@@ -1281,13 +1281,25 @@ function parseCacheEntryFlags(bits) {
|
|
|
1281
1281
|
extended: Boolean(bits & 0b0100000000000000),
|
|
1282
1282
|
stage: (bits & 0b0011000000000000) >> 12,
|
|
1283
1283
|
nameLength: bits & 0b0000111111111111,
|
|
1284
|
+
skipWorktree: false,
|
|
1285
|
+
intentToAdd: false,
|
|
1284
1286
|
}
|
|
1285
1287
|
}
|
|
1286
1288
|
|
|
1289
|
+
// Bits of the version 3 extended flags field that git understands:
|
|
1290
|
+
// 1-bit reserved, 1-bit skip-worktree, 1-bit intent-to-add, 13 unused bits
|
|
1291
|
+
const SKIP_WORKTREE = 0b0100000000000000;
|
|
1292
|
+
const INTENT_TO_ADD = 0b0010000000000000;
|
|
1293
|
+
|
|
1294
|
+
function hasExtendedFlags(entry) {
|
|
1295
|
+
return Boolean(entry.flags.skipWorktree || entry.flags.intentToAdd)
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1287
1298
|
function renderCacheEntryFlags(entry) {
|
|
1288
1299
|
const flags = entry.flags;
|
|
1289
|
-
// 1-bit extended flag
|
|
1290
|
-
flags
|
|
1300
|
+
// 1-bit extended flag, set only when the entry needs the extended
|
|
1301
|
+
// flags field that version 3 adds
|
|
1302
|
+
flags.extended = hasExtendedFlags(entry);
|
|
1291
1303
|
// 12-bit name length if the length is less than 0xFFF; otherwise 0xFFF
|
|
1292
1304
|
// is stored in this field.
|
|
1293
1305
|
flags.nameLength = Math.min(Buffer.from(entry.path).length, 0xfff);
|
|
@@ -1299,6 +1311,13 @@ function renderCacheEntryFlags(entry) {
|
|
|
1299
1311
|
)
|
|
1300
1312
|
}
|
|
1301
1313
|
|
|
1314
|
+
function renderCacheEntryExtendedFlags(entry) {
|
|
1315
|
+
return (
|
|
1316
|
+
(entry.flags.skipWorktree ? SKIP_WORKTREE : 0) +
|
|
1317
|
+
(entry.flags.intentToAdd ? INTENT_TO_ADD : 0)
|
|
1318
|
+
)
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1302
1321
|
class GitIndex {
|
|
1303
1322
|
/*::
|
|
1304
1323
|
_entries: Map<string, CacheEntry>
|
|
@@ -1358,7 +1377,7 @@ class GitIndex {
|
|
|
1358
1377
|
}
|
|
1359
1378
|
|
|
1360
1379
|
const version = reader.readUInt32BE();
|
|
1361
|
-
if (version !== 2) {
|
|
1380
|
+
if (version !== 2 && version !== 3) {
|
|
1362
1381
|
throw new InternalError(`Unsupported dircache version: ${version}`)
|
|
1363
1382
|
}
|
|
1364
1383
|
const numEntries = reader.readUInt32BE();
|
|
@@ -1378,7 +1397,16 @@ class GitIndex {
|
|
|
1378
1397
|
entry.oid = reader.slice(20).toString('hex');
|
|
1379
1398
|
const flags = reader.readUInt16BE();
|
|
1380
1399
|
entry.flags = parseCacheEntryFlags(flags);
|
|
1381
|
-
|
|
1400
|
+
if (entry.flags.extended) {
|
|
1401
|
+
const extendedFlags = reader.readUInt16BE();
|
|
1402
|
+
if (extendedFlags & ~(SKIP_WORKTREE | INTENT_TO_ADD)) {
|
|
1403
|
+
throw new InternalError(
|
|
1404
|
+
`Unknown index entry format: 0x${extendedFlags.toString(16)}`
|
|
1405
|
+
)
|
|
1406
|
+
}
|
|
1407
|
+
entry.flags.skipWorktree = Boolean(extendedFlags & SKIP_WORKTREE);
|
|
1408
|
+
entry.flags.intentToAdd = Boolean(extendedFlags & INTENT_TO_ADD);
|
|
1409
|
+
}
|
|
1382
1410
|
const pathlength = buffer.indexOf(0, reader.tell() + 1) - reader.tell();
|
|
1383
1411
|
if (pathlength < 1) {
|
|
1384
1412
|
throw new InternalError(`Got a path length of: ${pathlength}`)
|
|
@@ -1457,6 +1485,9 @@ class GitIndex {
|
|
|
1457
1485
|
}
|
|
1458
1486
|
stats = normalizeStats(stats);
|
|
1459
1487
|
const bfilepath = Buffer.from(filepath);
|
|
1488
|
+
// Keep the skip-worktree bit of a path outside the sparse checkout.
|
|
1489
|
+
// Intent-to-add is cleared, since the path is now staged.
|
|
1490
|
+
const existing = stage === 0 ? this._entries.get(filepath) : undefined;
|
|
1460
1491
|
const entry = {
|
|
1461
1492
|
ctimeSeconds: stats.ctimeSeconds,
|
|
1462
1493
|
ctimeNanoseconds: stats.ctimeNanoseconds,
|
|
@@ -1478,6 +1509,8 @@ class GitIndex {
|
|
|
1478
1509
|
extended: false,
|
|
1479
1510
|
stage,
|
|
1480
1511
|
nameLength: bfilepath.length < 0xfff ? bfilepath.length : 0xfff,
|
|
1512
|
+
skipWorktree: Boolean(existing?.flags.skipWorktree),
|
|
1513
|
+
intentToAdd: false,
|
|
1481
1514
|
},
|
|
1482
1515
|
stages: [],
|
|
1483
1516
|
};
|
|
@@ -1521,8 +1554,11 @@ class GitIndex {
|
|
|
1521
1554
|
|
|
1522
1555
|
static async _entryToBuffer(entry) {
|
|
1523
1556
|
const bpath = Buffer.from(entry.path);
|
|
1524
|
-
|
|
1525
|
-
|
|
1557
|
+
const extended = hasExtendedFlags(entry);
|
|
1558
|
+
// the fixed length + the extended flags (if any) + the filename + at
|
|
1559
|
+
// least one null char => align by 8
|
|
1560
|
+
const length =
|
|
1561
|
+
Math.ceil((62 + (extended ? 2 : 0) + bpath.length + 1) / 8) * 8;
|
|
1526
1562
|
const written = Buffer.alloc(length);
|
|
1527
1563
|
const writer = new BufferCursor(written);
|
|
1528
1564
|
const stat = normalizeStats(entry);
|
|
@@ -1538,6 +1574,9 @@ class GitIndex {
|
|
|
1538
1574
|
writer.writeUInt32BE(stat.size);
|
|
1539
1575
|
writer.write(entry.oid, 20, 'hex');
|
|
1540
1576
|
writer.writeUInt16BE(renderCacheEntryFlags(entry));
|
|
1577
|
+
if (extended) {
|
|
1578
|
+
writer.writeUInt16BE(renderCacheEntryExtendedFlags(entry));
|
|
1579
|
+
}
|
|
1541
1580
|
writer.write(entry.path, bpath.length, 'utf8');
|
|
1542
1581
|
return written
|
|
1543
1582
|
}
|
|
@@ -1546,7 +1585,8 @@ class GitIndex {
|
|
|
1546
1585
|
const header = Buffer.alloc(12);
|
|
1547
1586
|
const writer = new BufferCursor(header);
|
|
1548
1587
|
writer.write('DIRC', 4, 'utf8');
|
|
1549
|
-
|
|
1588
|
+
// Like canonical git, only use version 3 when an entry needs it
|
|
1589
|
+
writer.writeUInt32BE(this.entriesFlat.some(hasExtendedFlags) ? 3 : 2);
|
|
1550
1590
|
writer.writeUInt32BE(this.entriesFlat.length);
|
|
1551
1591
|
|
|
1552
1592
|
let entryBuffers = [];
|
|
@@ -2961,13 +3001,25 @@ class GitPktLine {
|
|
|
2961
3001
|
const reader = new StreamReader(stream);
|
|
2962
3002
|
return async function read() {
|
|
2963
3003
|
try {
|
|
2964
|
-
|
|
2965
|
-
if (
|
|
2966
|
-
|
|
3004
|
+
const header = await reader.read(4);
|
|
3005
|
+
if (header == null || header.length === 0) return true
|
|
3006
|
+
const hex = header.toString('utf8');
|
|
3007
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
|
|
3008
|
+
throw new ParseError('four hexadecimal digits', hex)
|
|
3009
|
+
}
|
|
3010
|
+
const length = parseInt(hex, 16);
|
|
2967
3011
|
if (length === 0) return null
|
|
2968
3012
|
if (length === 1) return null // delim packets
|
|
3013
|
+
if (length < 4) {
|
|
3014
|
+
throw new ParseError('pkt-line length of 0, 1, or at least 4', hex)
|
|
3015
|
+
}
|
|
2969
3016
|
const buffer = await reader.read(length - 4);
|
|
2970
|
-
if (buffer == null)
|
|
3017
|
+
if (buffer == null || buffer.length !== length - 4) {
|
|
3018
|
+
throw new ParseError(
|
|
3019
|
+
`${length - 4} bytes of pkt-line data`,
|
|
3020
|
+
`${buffer == null ? 0 : buffer.length} bytes`
|
|
3021
|
+
)
|
|
3022
|
+
}
|
|
2971
3023
|
return buffer
|
|
2972
3024
|
} catch (err) {
|
|
2973
3025
|
stream.error = err;
|
|
@@ -6051,9 +6103,11 @@ class GitWalkerFs {
|
|
|
6051
6103
|
// 1) if we can (because the oid and mode are the same)
|
|
6052
6104
|
// 2) and only if we need to (because other stats differ)
|
|
6053
6105
|
// 3) and only if the caller opted in to refreshing the index
|
|
6106
|
+
// 4) and not for an intent-to-add entry, which inserting would stage
|
|
6054
6107
|
if (
|
|
6055
6108
|
self.refresh &&
|
|
6056
6109
|
stage &&
|
|
6110
|
+
!stage.flags.intentToAdd &&
|
|
6057
6111
|
oid === stage.oid &&
|
|
6058
6112
|
(!filemode || stats.mode === stage.mode) &&
|
|
6059
6113
|
compareStats(stats, stage, filemode, trustino)
|
package/managers/index.js
CHANGED
|
@@ -1274,13 +1274,25 @@ function parseCacheEntryFlags(bits) {
|
|
|
1274
1274
|
extended: Boolean(bits & 0b0100000000000000),
|
|
1275
1275
|
stage: (bits & 0b0011000000000000) >> 12,
|
|
1276
1276
|
nameLength: bits & 0b0000111111111111,
|
|
1277
|
+
skipWorktree: false,
|
|
1278
|
+
intentToAdd: false,
|
|
1277
1279
|
}
|
|
1278
1280
|
}
|
|
1279
1281
|
|
|
1282
|
+
// Bits of the version 3 extended flags field that git understands:
|
|
1283
|
+
// 1-bit reserved, 1-bit skip-worktree, 1-bit intent-to-add, 13 unused bits
|
|
1284
|
+
const SKIP_WORKTREE = 0b0100000000000000;
|
|
1285
|
+
const INTENT_TO_ADD = 0b0010000000000000;
|
|
1286
|
+
|
|
1287
|
+
function hasExtendedFlags(entry) {
|
|
1288
|
+
return Boolean(entry.flags.skipWorktree || entry.flags.intentToAdd)
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1280
1291
|
function renderCacheEntryFlags(entry) {
|
|
1281
1292
|
const flags = entry.flags;
|
|
1282
|
-
// 1-bit extended flag
|
|
1283
|
-
flags
|
|
1293
|
+
// 1-bit extended flag, set only when the entry needs the extended
|
|
1294
|
+
// flags field that version 3 adds
|
|
1295
|
+
flags.extended = hasExtendedFlags(entry);
|
|
1284
1296
|
// 12-bit name length if the length is less than 0xFFF; otherwise 0xFFF
|
|
1285
1297
|
// is stored in this field.
|
|
1286
1298
|
flags.nameLength = Math.min(Buffer.from(entry.path).length, 0xfff);
|
|
@@ -1292,6 +1304,13 @@ function renderCacheEntryFlags(entry) {
|
|
|
1292
1304
|
)
|
|
1293
1305
|
}
|
|
1294
1306
|
|
|
1307
|
+
function renderCacheEntryExtendedFlags(entry) {
|
|
1308
|
+
return (
|
|
1309
|
+
(entry.flags.skipWorktree ? SKIP_WORKTREE : 0) +
|
|
1310
|
+
(entry.flags.intentToAdd ? INTENT_TO_ADD : 0)
|
|
1311
|
+
)
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1295
1314
|
class GitIndex {
|
|
1296
1315
|
/*::
|
|
1297
1316
|
_entries: Map<string, CacheEntry>
|
|
@@ -1351,7 +1370,7 @@ class GitIndex {
|
|
|
1351
1370
|
}
|
|
1352
1371
|
|
|
1353
1372
|
const version = reader.readUInt32BE();
|
|
1354
|
-
if (version !== 2) {
|
|
1373
|
+
if (version !== 2 && version !== 3) {
|
|
1355
1374
|
throw new InternalError(`Unsupported dircache version: ${version}`)
|
|
1356
1375
|
}
|
|
1357
1376
|
const numEntries = reader.readUInt32BE();
|
|
@@ -1371,7 +1390,16 @@ class GitIndex {
|
|
|
1371
1390
|
entry.oid = reader.slice(20).toString('hex');
|
|
1372
1391
|
const flags = reader.readUInt16BE();
|
|
1373
1392
|
entry.flags = parseCacheEntryFlags(flags);
|
|
1374
|
-
|
|
1393
|
+
if (entry.flags.extended) {
|
|
1394
|
+
const extendedFlags = reader.readUInt16BE();
|
|
1395
|
+
if (extendedFlags & ~(SKIP_WORKTREE | INTENT_TO_ADD)) {
|
|
1396
|
+
throw new InternalError(
|
|
1397
|
+
`Unknown index entry format: 0x${extendedFlags.toString(16)}`
|
|
1398
|
+
)
|
|
1399
|
+
}
|
|
1400
|
+
entry.flags.skipWorktree = Boolean(extendedFlags & SKIP_WORKTREE);
|
|
1401
|
+
entry.flags.intentToAdd = Boolean(extendedFlags & INTENT_TO_ADD);
|
|
1402
|
+
}
|
|
1375
1403
|
const pathlength = buffer.indexOf(0, reader.tell() + 1) - reader.tell();
|
|
1376
1404
|
if (pathlength < 1) {
|
|
1377
1405
|
throw new InternalError(`Got a path length of: ${pathlength}`)
|
|
@@ -1450,6 +1478,9 @@ class GitIndex {
|
|
|
1450
1478
|
}
|
|
1451
1479
|
stats = normalizeStats(stats);
|
|
1452
1480
|
const bfilepath = Buffer.from(filepath);
|
|
1481
|
+
// Keep the skip-worktree bit of a path outside the sparse checkout.
|
|
1482
|
+
// Intent-to-add is cleared, since the path is now staged.
|
|
1483
|
+
const existing = stage === 0 ? this._entries.get(filepath) : undefined;
|
|
1453
1484
|
const entry = {
|
|
1454
1485
|
ctimeSeconds: stats.ctimeSeconds,
|
|
1455
1486
|
ctimeNanoseconds: stats.ctimeNanoseconds,
|
|
@@ -1471,6 +1502,8 @@ class GitIndex {
|
|
|
1471
1502
|
extended: false,
|
|
1472
1503
|
stage,
|
|
1473
1504
|
nameLength: bfilepath.length < 0xfff ? bfilepath.length : 0xfff,
|
|
1505
|
+
skipWorktree: Boolean(existing?.flags.skipWorktree),
|
|
1506
|
+
intentToAdd: false,
|
|
1474
1507
|
},
|
|
1475
1508
|
stages: [],
|
|
1476
1509
|
};
|
|
@@ -1514,8 +1547,11 @@ class GitIndex {
|
|
|
1514
1547
|
|
|
1515
1548
|
static async _entryToBuffer(entry) {
|
|
1516
1549
|
const bpath = Buffer.from(entry.path);
|
|
1517
|
-
|
|
1518
|
-
|
|
1550
|
+
const extended = hasExtendedFlags(entry);
|
|
1551
|
+
// the fixed length + the extended flags (if any) + the filename + at
|
|
1552
|
+
// least one null char => align by 8
|
|
1553
|
+
const length =
|
|
1554
|
+
Math.ceil((62 + (extended ? 2 : 0) + bpath.length + 1) / 8) * 8;
|
|
1519
1555
|
const written = Buffer.alloc(length);
|
|
1520
1556
|
const writer = new BufferCursor(written);
|
|
1521
1557
|
const stat = normalizeStats(entry);
|
|
@@ -1531,6 +1567,9 @@ class GitIndex {
|
|
|
1531
1567
|
writer.writeUInt32BE(stat.size);
|
|
1532
1568
|
writer.write(entry.oid, 20, 'hex');
|
|
1533
1569
|
writer.writeUInt16BE(renderCacheEntryFlags(entry));
|
|
1570
|
+
if (extended) {
|
|
1571
|
+
writer.writeUInt16BE(renderCacheEntryExtendedFlags(entry));
|
|
1572
|
+
}
|
|
1534
1573
|
writer.write(entry.path, bpath.length, 'utf8');
|
|
1535
1574
|
return written
|
|
1536
1575
|
}
|
|
@@ -1539,7 +1578,8 @@ class GitIndex {
|
|
|
1539
1578
|
const header = Buffer.alloc(12);
|
|
1540
1579
|
const writer = new BufferCursor(header);
|
|
1541
1580
|
writer.write('DIRC', 4, 'utf8');
|
|
1542
|
-
|
|
1581
|
+
// Like canonical git, only use version 3 when an entry needs it
|
|
1582
|
+
writer.writeUInt32BE(this.entriesFlat.some(hasExtendedFlags) ? 3 : 2);
|
|
1543
1583
|
writer.writeUInt32BE(this.entriesFlat.length);
|
|
1544
1584
|
|
|
1545
1585
|
let entryBuffers = [];
|
|
@@ -2954,13 +2994,25 @@ class GitPktLine {
|
|
|
2954
2994
|
const reader = new StreamReader(stream);
|
|
2955
2995
|
return async function read() {
|
|
2956
2996
|
try {
|
|
2957
|
-
|
|
2958
|
-
if (
|
|
2959
|
-
|
|
2997
|
+
const header = await reader.read(4);
|
|
2998
|
+
if (header == null || header.length === 0) return true
|
|
2999
|
+
const hex = header.toString('utf8');
|
|
3000
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
|
|
3001
|
+
throw new ParseError('four hexadecimal digits', hex)
|
|
3002
|
+
}
|
|
3003
|
+
const length = parseInt(hex, 16);
|
|
2960
3004
|
if (length === 0) return null
|
|
2961
3005
|
if (length === 1) return null // delim packets
|
|
3006
|
+
if (length < 4) {
|
|
3007
|
+
throw new ParseError('pkt-line length of 0, 1, or at least 4', hex)
|
|
3008
|
+
}
|
|
2962
3009
|
const buffer = await reader.read(length - 4);
|
|
2963
|
-
if (buffer == null)
|
|
3010
|
+
if (buffer == null || buffer.length !== length - 4) {
|
|
3011
|
+
throw new ParseError(
|
|
3012
|
+
`${length - 4} bytes of pkt-line data`,
|
|
3013
|
+
`${buffer == null ? 0 : buffer.length} bytes`
|
|
3014
|
+
)
|
|
3015
|
+
}
|
|
2964
3016
|
return buffer
|
|
2965
3017
|
} catch (err) {
|
|
2966
3018
|
stream.error = err;
|
|
@@ -6038,9 +6090,11 @@ class GitWalkerFs {
|
|
|
6038
6090
|
// 1) if we can (because the oid and mode are the same)
|
|
6039
6091
|
// 2) and only if we need to (because other stats differ)
|
|
6040
6092
|
// 3) and only if the caller opted in to refreshing the index
|
|
6093
|
+
// 4) and not for an intent-to-add entry, which inserting would stage
|
|
6041
6094
|
if (
|
|
6042
6095
|
self.refresh &&
|
|
6043
6096
|
stage &&
|
|
6097
|
+
!stage.flags.intentToAdd &&
|
|
6044
6098
|
oid === stage.oid &&
|
|
6045
6099
|
(!filemode || stats.mode === stage.mode) &&
|
|
6046
6100
|
compareStats(stats, stage, filemode, trustino)
|