isomorphic-git 1.44.5 → 1.44.7
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 +157 -25
- package/index.js +157 -25
- package/index.umd.min.js +1 -1
- package/index.umd.min.js.map +1 -1
- package/managers/index.cjs +143 -20
- package/managers/index.js +143 -20
- package/managers/index.umd.min.js +1 -1
- package/managers/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -465,6 +465,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
|
|
|
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
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>
|
|
468
|
+
<td align="center"><a href="https://github.com/SergioSRcode"><img src="https://avatars.githubusercontent.com/u/104135678?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Sergio</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=SergioSRcode" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=SergioSRcode" title="Documentation">📖</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=SergioSRcode" title="Tests">⚠️</a></td>
|
|
468
469
|
</tr>
|
|
469
470
|
</table>
|
|
470
471
|
|
package/index.cjs
CHANGED
|
@@ -707,13 +707,25 @@ function parseCacheEntryFlags(bits) {
|
|
|
707
707
|
extended: Boolean(bits & 0b0100000000000000),
|
|
708
708
|
stage: (bits & 0b0011000000000000) >> 12,
|
|
709
709
|
nameLength: bits & 0b0000111111111111,
|
|
710
|
+
skipWorktree: false,
|
|
711
|
+
intentToAdd: false,
|
|
710
712
|
}
|
|
711
713
|
}
|
|
712
714
|
|
|
715
|
+
// Bits of the version 3 extended flags field that git understands:
|
|
716
|
+
// 1-bit reserved, 1-bit skip-worktree, 1-bit intent-to-add, 13 unused bits
|
|
717
|
+
const SKIP_WORKTREE = 0b0100000000000000;
|
|
718
|
+
const INTENT_TO_ADD = 0b0010000000000000;
|
|
719
|
+
|
|
720
|
+
function hasExtendedFlags(entry) {
|
|
721
|
+
return Boolean(entry.flags.skipWorktree || entry.flags.intentToAdd)
|
|
722
|
+
}
|
|
723
|
+
|
|
713
724
|
function renderCacheEntryFlags(entry) {
|
|
714
725
|
const flags = entry.flags;
|
|
715
|
-
// 1-bit extended flag
|
|
716
|
-
flags
|
|
726
|
+
// 1-bit extended flag, set only when the entry needs the extended
|
|
727
|
+
// flags field that version 3 adds
|
|
728
|
+
flags.extended = hasExtendedFlags(entry);
|
|
717
729
|
// 12-bit name length if the length is less than 0xFFF; otherwise 0xFFF
|
|
718
730
|
// is stored in this field.
|
|
719
731
|
flags.nameLength = Math.min(Buffer.from(entry.path).length, 0xfff);
|
|
@@ -725,6 +737,13 @@ function renderCacheEntryFlags(entry) {
|
|
|
725
737
|
)
|
|
726
738
|
}
|
|
727
739
|
|
|
740
|
+
function renderCacheEntryExtendedFlags(entry) {
|
|
741
|
+
return (
|
|
742
|
+
(entry.flags.skipWorktree ? SKIP_WORKTREE : 0) +
|
|
743
|
+
(entry.flags.intentToAdd ? INTENT_TO_ADD : 0)
|
|
744
|
+
)
|
|
745
|
+
}
|
|
746
|
+
|
|
728
747
|
class GitIndex {
|
|
729
748
|
/*::
|
|
730
749
|
_entries: Map<string, CacheEntry>
|
|
@@ -784,7 +803,7 @@ class GitIndex {
|
|
|
784
803
|
}
|
|
785
804
|
|
|
786
805
|
const version = reader.readUInt32BE();
|
|
787
|
-
if (version !== 2) {
|
|
806
|
+
if (version !== 2 && version !== 3) {
|
|
788
807
|
throw new InternalError(`Unsupported dircache version: ${version}`)
|
|
789
808
|
}
|
|
790
809
|
const numEntries = reader.readUInt32BE();
|
|
@@ -804,7 +823,16 @@ class GitIndex {
|
|
|
804
823
|
entry.oid = reader.slice(20).toString('hex');
|
|
805
824
|
const flags = reader.readUInt16BE();
|
|
806
825
|
entry.flags = parseCacheEntryFlags(flags);
|
|
807
|
-
|
|
826
|
+
if (entry.flags.extended) {
|
|
827
|
+
const extendedFlags = reader.readUInt16BE();
|
|
828
|
+
if (extendedFlags & ~(SKIP_WORKTREE | INTENT_TO_ADD)) {
|
|
829
|
+
throw new InternalError(
|
|
830
|
+
`Unknown index entry format: 0x${extendedFlags.toString(16)}`
|
|
831
|
+
)
|
|
832
|
+
}
|
|
833
|
+
entry.flags.skipWorktree = Boolean(extendedFlags & SKIP_WORKTREE);
|
|
834
|
+
entry.flags.intentToAdd = Boolean(extendedFlags & INTENT_TO_ADD);
|
|
835
|
+
}
|
|
808
836
|
const pathlength = buffer.indexOf(0, reader.tell() + 1) - reader.tell();
|
|
809
837
|
if (pathlength < 1) {
|
|
810
838
|
throw new InternalError(`Got a path length of: ${pathlength}`)
|
|
@@ -883,6 +911,9 @@ class GitIndex {
|
|
|
883
911
|
}
|
|
884
912
|
stats = normalizeStats(stats);
|
|
885
913
|
const bfilepath = Buffer.from(filepath);
|
|
914
|
+
// Keep the skip-worktree bit of a path outside the sparse checkout.
|
|
915
|
+
// Intent-to-add is cleared, since the path is now staged.
|
|
916
|
+
const existing = stage === 0 ? this._entries.get(filepath) : undefined;
|
|
886
917
|
const entry = {
|
|
887
918
|
ctimeSeconds: stats.ctimeSeconds,
|
|
888
919
|
ctimeNanoseconds: stats.ctimeNanoseconds,
|
|
@@ -904,6 +935,8 @@ class GitIndex {
|
|
|
904
935
|
extended: false,
|
|
905
936
|
stage,
|
|
906
937
|
nameLength: bfilepath.length < 0xfff ? bfilepath.length : 0xfff,
|
|
938
|
+
skipWorktree: Boolean(existing?.flags.skipWorktree),
|
|
939
|
+
intentToAdd: false,
|
|
907
940
|
},
|
|
908
941
|
stages: [],
|
|
909
942
|
};
|
|
@@ -947,8 +980,11 @@ class GitIndex {
|
|
|
947
980
|
|
|
948
981
|
static async _entryToBuffer(entry) {
|
|
949
982
|
const bpath = Buffer.from(entry.path);
|
|
950
|
-
|
|
951
|
-
|
|
983
|
+
const extended = hasExtendedFlags(entry);
|
|
984
|
+
// the fixed length + the extended flags (if any) + the filename + at
|
|
985
|
+
// least one null char => align by 8
|
|
986
|
+
const length =
|
|
987
|
+
Math.ceil((62 + (extended ? 2 : 0) + bpath.length + 1) / 8) * 8;
|
|
952
988
|
const written = Buffer.alloc(length);
|
|
953
989
|
const writer = new BufferCursor(written);
|
|
954
990
|
const stat = normalizeStats(entry);
|
|
@@ -964,6 +1000,9 @@ class GitIndex {
|
|
|
964
1000
|
writer.writeUInt32BE(stat.size);
|
|
965
1001
|
writer.write(entry.oid, 20, 'hex');
|
|
966
1002
|
writer.writeUInt16BE(renderCacheEntryFlags(entry));
|
|
1003
|
+
if (extended) {
|
|
1004
|
+
writer.writeUInt16BE(renderCacheEntryExtendedFlags(entry));
|
|
1005
|
+
}
|
|
967
1006
|
writer.write(entry.path, bpath.length, 'utf8');
|
|
968
1007
|
return written
|
|
969
1008
|
}
|
|
@@ -972,7 +1011,8 @@ class GitIndex {
|
|
|
972
1011
|
const header = Buffer.alloc(12);
|
|
973
1012
|
const writer = new BufferCursor(header);
|
|
974
1013
|
writer.write('DIRC', 4, 'utf8');
|
|
975
|
-
|
|
1014
|
+
// Like canonical git, only use version 3 when an entry needs it
|
|
1015
|
+
writer.writeUInt32BE(this.entriesFlat.some(hasExtendedFlags) ? 3 : 2);
|
|
976
1016
|
writer.writeUInt32BE(this.entriesFlat.length);
|
|
977
1017
|
|
|
978
1018
|
let entryBuffers = [];
|
|
@@ -3374,6 +3414,69 @@ function otherVarIntDecode(reader, startWith) {
|
|
|
3374
3414
|
return result
|
|
3375
3415
|
}
|
|
3376
3416
|
|
|
3417
|
+
// Memory that `fromPack` may use to keep resolved objects for delta bases.
|
|
3418
|
+
// An object larger than a quarter of this is not kept.
|
|
3419
|
+
const RESOLVE_CACHE_BYTES = 32 * 1024 * 1024;
|
|
3420
|
+
|
|
3421
|
+
// A cache that drops the least recently used object when it holds too many bytes.
|
|
3422
|
+
class ObjectCache {
|
|
3423
|
+
constructor(maxBytes) {
|
|
3424
|
+
this.maxBytes = maxBytes;
|
|
3425
|
+
this.bytes = 0;
|
|
3426
|
+
this.map = new Map();
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3429
|
+
get(key) {
|
|
3430
|
+
const value = this.map.get(key);
|
|
3431
|
+
if (value !== undefined) {
|
|
3432
|
+
this.map.delete(key);
|
|
3433
|
+
this.map.set(key, value);
|
|
3434
|
+
}
|
|
3435
|
+
return value
|
|
3436
|
+
}
|
|
3437
|
+
|
|
3438
|
+
set(key, value) {
|
|
3439
|
+
const size = value.object.byteLength;
|
|
3440
|
+
if (size > this.maxBytes / 4) return
|
|
3441
|
+
this.map.set(key, value);
|
|
3442
|
+
this.bytes += size;
|
|
3443
|
+
for (const [oldKey, old] of this.map) {
|
|
3444
|
+
if (this.bytes <= this.maxBytes) break
|
|
3445
|
+
this.map.delete(oldKey);
|
|
3446
|
+
this.bytes -= old.object.byteLength;
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3451
|
+
// Resolve an object from the data that `listpack` already inflated.
|
|
3452
|
+
// Return null when the object needs `readSlice`. This happens when the base of
|
|
3453
|
+
// a delta is not in the cache, or when the delta is corrupt.
|
|
3454
|
+
function resolveInflated(
|
|
3455
|
+
{ type, data, reference, offset },
|
|
3456
|
+
cache,
|
|
3457
|
+
offsetByOid
|
|
3458
|
+
) {
|
|
3459
|
+
// `applyDelta` and `shasum` need a Buffer. This is a view and copies nothing.
|
|
3460
|
+
const object = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
3461
|
+
if (type !== 'ofs-delta' && type !== 'ref-delta') return { type, object }
|
|
3462
|
+
const baseOffset =
|
|
3463
|
+
type === 'ofs-delta'
|
|
3464
|
+
? offset - decodeVarInt(new BufferCursor(reference))
|
|
3465
|
+
: offsetByOid.get(reference.toString('hex'));
|
|
3466
|
+
const base = cache.get(baseOffset);
|
|
3467
|
+
if (!base) return null
|
|
3468
|
+
try {
|
|
3469
|
+
return {
|
|
3470
|
+
type: base.type,
|
|
3471
|
+
object: Buffer.from(applyDelta(object, base.object)),
|
|
3472
|
+
}
|
|
3473
|
+
} catch (err) {
|
|
3474
|
+
// A corrupt delta. `readSlice` reports it again. Any other error is a bug.
|
|
3475
|
+
if (err instanceof InternalError || err instanceof RangeError) return null
|
|
3476
|
+
throw err
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3479
|
+
|
|
3377
3480
|
class GitPackIndex {
|
|
3378
3481
|
constructor(stuff) {
|
|
3379
3482
|
Object.assign(this, stuff);
|
|
@@ -3445,6 +3548,9 @@ class GitPackIndex {
|
|
|
3445
3548
|
const offsets = new Map();
|
|
3446
3549
|
let totalObjectCount = null;
|
|
3447
3550
|
let lastPercent = null;
|
|
3551
|
+
// Objects that `listpack` inflated, by pack offset. A delta finds its base here.
|
|
3552
|
+
const cache = new ObjectCache(RESOLVE_CACHE_BYTES);
|
|
3553
|
+
const offsetByOid = new Map();
|
|
3448
3554
|
|
|
3449
3555
|
await listpack([pack], async ({ data, type, reference, offset, num }) => {
|
|
3450
3556
|
if (totalObjectCount === null) totalObjectCount = num;
|
|
@@ -3480,6 +3586,20 @@ class GitPackIndex {
|
|
|
3480
3586
|
offset,
|
|
3481
3587
|
};
|
|
3482
3588
|
}
|
|
3589
|
+
|
|
3590
|
+
// The object is already inflated, so get its oid now. Then the loop below
|
|
3591
|
+
// does not inflate it again. That loop reads all other objects.
|
|
3592
|
+
const o = offsetToObject[offset];
|
|
3593
|
+
if (!o) return
|
|
3594
|
+
const resolved = resolveInflated(
|
|
3595
|
+
{ type, data, reference, offset },
|
|
3596
|
+
cache,
|
|
3597
|
+
offsetByOid
|
|
3598
|
+
);
|
|
3599
|
+
if (!resolved) return
|
|
3600
|
+
o.oid = await shasum(GitObject.wrap(resolved));
|
|
3601
|
+
offsetByOid.set(o.oid, offset);
|
|
3602
|
+
cache.set(offset, resolved);
|
|
3483
3603
|
});
|
|
3484
3604
|
|
|
3485
3605
|
// We need to know the lengths of the slices to compute the CRCs.
|
|
@@ -3523,20 +3643,21 @@ class GitPackIndex {
|
|
|
3523
3643
|
lastPercent = percent;
|
|
3524
3644
|
|
|
3525
3645
|
const o = offsetToObject[offset];
|
|
3526
|
-
if (o.oid)
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
} catch (err) {
|
|
3538
|
-
continue
|
|
3646
|
+
if (!o.oid) {
|
|
3647
|
+
// The first pass did not resolve this object, so read it.
|
|
3648
|
+
try {
|
|
3649
|
+
p.readDepth = 0;
|
|
3650
|
+
p.externalReadDepth = 0;
|
|
3651
|
+
const { type, object } = await p.readSlice({ start: offset });
|
|
3652
|
+
objectsByDepth[p.readDepth] += 1;
|
|
3653
|
+
o.oid = await shasum(GitObject.wrap({ type, object }));
|
|
3654
|
+
} catch (err) {
|
|
3655
|
+
continue
|
|
3656
|
+
}
|
|
3539
3657
|
}
|
|
3658
|
+
hashes.push(o.oid);
|
|
3659
|
+
offsets.set(o.oid, offset);
|
|
3660
|
+
crcs[o.oid] = o.crc;
|
|
3540
3661
|
}
|
|
3541
3662
|
|
|
3542
3663
|
hashes.sort();
|
|
@@ -5037,9 +5158,11 @@ class GitWalkerFs {
|
|
|
5037
5158
|
// 1) if we can (because the oid and mode are the same)
|
|
5038
5159
|
// 2) and only if we need to (because other stats differ)
|
|
5039
5160
|
// 3) and only if the caller opted in to refreshing the index
|
|
5161
|
+
// 4) and not for an intent-to-add entry, which inserting would stage
|
|
5040
5162
|
if (
|
|
5041
5163
|
self.refresh &&
|
|
5042
5164
|
stage &&
|
|
5165
|
+
!stage.flags.intentToAdd &&
|
|
5043
5166
|
oid === stage.oid &&
|
|
5044
5167
|
(!filemode || stats.mode === stage.mode) &&
|
|
5045
5168
|
compareStats(stats, stage, filemode, trustino)
|
|
@@ -6547,7 +6670,10 @@ async function _commit({
|
|
|
6547
6670
|
return GitIndexManager.acquire(
|
|
6548
6671
|
{ fs, gitdir, cache, allowUnmerged: false },
|
|
6549
6672
|
async function (index) {
|
|
6550
|
-
|
|
6673
|
+
// Entries added with `git add --intent-to-add` are not part of the tree
|
|
6674
|
+
const inodes = flatFileListToDirectoryStructure(
|
|
6675
|
+
index.entries.filter(entry => !entry.flags.intentToAdd)
|
|
6676
|
+
);
|
|
6551
6677
|
const inode = inodes.get('.');
|
|
6552
6678
|
if (!tree) {
|
|
6553
6679
|
tree = await constructTree({ fs, gitdir, inode, dryRun });
|
|
@@ -10129,8 +10255,8 @@ function filterCapabilities(server, client) {
|
|
|
10129
10255
|
|
|
10130
10256
|
const pkg = {
|
|
10131
10257
|
name: 'isomorphic-git',
|
|
10132
|
-
version: '1.44.
|
|
10133
|
-
agent: 'git/isomorphic-git@1.44.
|
|
10258
|
+
version: '1.44.7',
|
|
10259
|
+
agent: 'git/isomorphic-git@1.44.7',
|
|
10134
10260
|
};
|
|
10135
10261
|
|
|
10136
10262
|
class FIFO {
|
|
@@ -17074,8 +17200,14 @@ async function status({
|
|
|
17074
17200
|
type: 'blob',
|
|
17075
17201
|
object,
|
|
17076
17202
|
});
|
|
17077
|
-
// If the oid in the index === working dir oid but stats differed update cache
|
|
17078
|
-
|
|
17203
|
+
// If the oid in the index === working dir oid but stats differed update cache.
|
|
17204
|
+
// An intent-to-add entry is left alone: inserting it again would stage it.
|
|
17205
|
+
if (
|
|
17206
|
+
refresh &&
|
|
17207
|
+
I &&
|
|
17208
|
+
!indexEntry.flags.intentToAdd &&
|
|
17209
|
+
indexEntry.oid === workdirOid
|
|
17210
|
+
) {
|
|
17079
17211
|
// and as long as our fs.stats aren't bad.
|
|
17080
17212
|
// size of -1 happens over a BrowserFS HTTP Backend that doesn't serve Content-Length headers
|
|
17081
17213
|
// (like the Karma webserver) because BrowserFS HTTP Backend uses HTTP HEAD requests to do fs.stat
|
package/index.js
CHANGED
|
@@ -700,13 +700,25 @@ function parseCacheEntryFlags(bits) {
|
|
|
700
700
|
extended: Boolean(bits & 0b0100000000000000),
|
|
701
701
|
stage: (bits & 0b0011000000000000) >> 12,
|
|
702
702
|
nameLength: bits & 0b0000111111111111,
|
|
703
|
+
skipWorktree: false,
|
|
704
|
+
intentToAdd: false,
|
|
703
705
|
}
|
|
704
706
|
}
|
|
705
707
|
|
|
708
|
+
// Bits of the version 3 extended flags field that git understands:
|
|
709
|
+
// 1-bit reserved, 1-bit skip-worktree, 1-bit intent-to-add, 13 unused bits
|
|
710
|
+
const SKIP_WORKTREE = 0b0100000000000000;
|
|
711
|
+
const INTENT_TO_ADD = 0b0010000000000000;
|
|
712
|
+
|
|
713
|
+
function hasExtendedFlags(entry) {
|
|
714
|
+
return Boolean(entry.flags.skipWorktree || entry.flags.intentToAdd)
|
|
715
|
+
}
|
|
716
|
+
|
|
706
717
|
function renderCacheEntryFlags(entry) {
|
|
707
718
|
const flags = entry.flags;
|
|
708
|
-
// 1-bit extended flag
|
|
709
|
-
flags
|
|
719
|
+
// 1-bit extended flag, set only when the entry needs the extended
|
|
720
|
+
// flags field that version 3 adds
|
|
721
|
+
flags.extended = hasExtendedFlags(entry);
|
|
710
722
|
// 12-bit name length if the length is less than 0xFFF; otherwise 0xFFF
|
|
711
723
|
// is stored in this field.
|
|
712
724
|
flags.nameLength = Math.min(Buffer.from(entry.path).length, 0xfff);
|
|
@@ -718,6 +730,13 @@ function renderCacheEntryFlags(entry) {
|
|
|
718
730
|
)
|
|
719
731
|
}
|
|
720
732
|
|
|
733
|
+
function renderCacheEntryExtendedFlags(entry) {
|
|
734
|
+
return (
|
|
735
|
+
(entry.flags.skipWorktree ? SKIP_WORKTREE : 0) +
|
|
736
|
+
(entry.flags.intentToAdd ? INTENT_TO_ADD : 0)
|
|
737
|
+
)
|
|
738
|
+
}
|
|
739
|
+
|
|
721
740
|
class GitIndex {
|
|
722
741
|
/*::
|
|
723
742
|
_entries: Map<string, CacheEntry>
|
|
@@ -777,7 +796,7 @@ class GitIndex {
|
|
|
777
796
|
}
|
|
778
797
|
|
|
779
798
|
const version = reader.readUInt32BE();
|
|
780
|
-
if (version !== 2) {
|
|
799
|
+
if (version !== 2 && version !== 3) {
|
|
781
800
|
throw new InternalError(`Unsupported dircache version: ${version}`)
|
|
782
801
|
}
|
|
783
802
|
const numEntries = reader.readUInt32BE();
|
|
@@ -797,7 +816,16 @@ class GitIndex {
|
|
|
797
816
|
entry.oid = reader.slice(20).toString('hex');
|
|
798
817
|
const flags = reader.readUInt16BE();
|
|
799
818
|
entry.flags = parseCacheEntryFlags(flags);
|
|
800
|
-
|
|
819
|
+
if (entry.flags.extended) {
|
|
820
|
+
const extendedFlags = reader.readUInt16BE();
|
|
821
|
+
if (extendedFlags & ~(SKIP_WORKTREE | INTENT_TO_ADD)) {
|
|
822
|
+
throw new InternalError(
|
|
823
|
+
`Unknown index entry format: 0x${extendedFlags.toString(16)}`
|
|
824
|
+
)
|
|
825
|
+
}
|
|
826
|
+
entry.flags.skipWorktree = Boolean(extendedFlags & SKIP_WORKTREE);
|
|
827
|
+
entry.flags.intentToAdd = Boolean(extendedFlags & INTENT_TO_ADD);
|
|
828
|
+
}
|
|
801
829
|
const pathlength = buffer.indexOf(0, reader.tell() + 1) - reader.tell();
|
|
802
830
|
if (pathlength < 1) {
|
|
803
831
|
throw new InternalError(`Got a path length of: ${pathlength}`)
|
|
@@ -876,6 +904,9 @@ class GitIndex {
|
|
|
876
904
|
}
|
|
877
905
|
stats = normalizeStats(stats);
|
|
878
906
|
const bfilepath = Buffer.from(filepath);
|
|
907
|
+
// Keep the skip-worktree bit of a path outside the sparse checkout.
|
|
908
|
+
// Intent-to-add is cleared, since the path is now staged.
|
|
909
|
+
const existing = stage === 0 ? this._entries.get(filepath) : undefined;
|
|
879
910
|
const entry = {
|
|
880
911
|
ctimeSeconds: stats.ctimeSeconds,
|
|
881
912
|
ctimeNanoseconds: stats.ctimeNanoseconds,
|
|
@@ -897,6 +928,8 @@ class GitIndex {
|
|
|
897
928
|
extended: false,
|
|
898
929
|
stage,
|
|
899
930
|
nameLength: bfilepath.length < 0xfff ? bfilepath.length : 0xfff,
|
|
931
|
+
skipWorktree: Boolean(existing?.flags.skipWorktree),
|
|
932
|
+
intentToAdd: false,
|
|
900
933
|
},
|
|
901
934
|
stages: [],
|
|
902
935
|
};
|
|
@@ -940,8 +973,11 @@ class GitIndex {
|
|
|
940
973
|
|
|
941
974
|
static async _entryToBuffer(entry) {
|
|
942
975
|
const bpath = Buffer.from(entry.path);
|
|
943
|
-
|
|
944
|
-
|
|
976
|
+
const extended = hasExtendedFlags(entry);
|
|
977
|
+
// the fixed length + the extended flags (if any) + the filename + at
|
|
978
|
+
// least one null char => align by 8
|
|
979
|
+
const length =
|
|
980
|
+
Math.ceil((62 + (extended ? 2 : 0) + bpath.length + 1) / 8) * 8;
|
|
945
981
|
const written = Buffer.alloc(length);
|
|
946
982
|
const writer = new BufferCursor(written);
|
|
947
983
|
const stat = normalizeStats(entry);
|
|
@@ -957,6 +993,9 @@ class GitIndex {
|
|
|
957
993
|
writer.writeUInt32BE(stat.size);
|
|
958
994
|
writer.write(entry.oid, 20, 'hex');
|
|
959
995
|
writer.writeUInt16BE(renderCacheEntryFlags(entry));
|
|
996
|
+
if (extended) {
|
|
997
|
+
writer.writeUInt16BE(renderCacheEntryExtendedFlags(entry));
|
|
998
|
+
}
|
|
960
999
|
writer.write(entry.path, bpath.length, 'utf8');
|
|
961
1000
|
return written
|
|
962
1001
|
}
|
|
@@ -965,7 +1004,8 @@ class GitIndex {
|
|
|
965
1004
|
const header = Buffer.alloc(12);
|
|
966
1005
|
const writer = new BufferCursor(header);
|
|
967
1006
|
writer.write('DIRC', 4, 'utf8');
|
|
968
|
-
|
|
1007
|
+
// Like canonical git, only use version 3 when an entry needs it
|
|
1008
|
+
writer.writeUInt32BE(this.entriesFlat.some(hasExtendedFlags) ? 3 : 2);
|
|
969
1009
|
writer.writeUInt32BE(this.entriesFlat.length);
|
|
970
1010
|
|
|
971
1011
|
let entryBuffers = [];
|
|
@@ -3367,6 +3407,69 @@ function otherVarIntDecode(reader, startWith) {
|
|
|
3367
3407
|
return result
|
|
3368
3408
|
}
|
|
3369
3409
|
|
|
3410
|
+
// Memory that `fromPack` may use to keep resolved objects for delta bases.
|
|
3411
|
+
// An object larger than a quarter of this is not kept.
|
|
3412
|
+
const RESOLVE_CACHE_BYTES = 32 * 1024 * 1024;
|
|
3413
|
+
|
|
3414
|
+
// A cache that drops the least recently used object when it holds too many bytes.
|
|
3415
|
+
class ObjectCache {
|
|
3416
|
+
constructor(maxBytes) {
|
|
3417
|
+
this.maxBytes = maxBytes;
|
|
3418
|
+
this.bytes = 0;
|
|
3419
|
+
this.map = new Map();
|
|
3420
|
+
}
|
|
3421
|
+
|
|
3422
|
+
get(key) {
|
|
3423
|
+
const value = this.map.get(key);
|
|
3424
|
+
if (value !== undefined) {
|
|
3425
|
+
this.map.delete(key);
|
|
3426
|
+
this.map.set(key, value);
|
|
3427
|
+
}
|
|
3428
|
+
return value
|
|
3429
|
+
}
|
|
3430
|
+
|
|
3431
|
+
set(key, value) {
|
|
3432
|
+
const size = value.object.byteLength;
|
|
3433
|
+
if (size > this.maxBytes / 4) return
|
|
3434
|
+
this.map.set(key, value);
|
|
3435
|
+
this.bytes += size;
|
|
3436
|
+
for (const [oldKey, old] of this.map) {
|
|
3437
|
+
if (this.bytes <= this.maxBytes) break
|
|
3438
|
+
this.map.delete(oldKey);
|
|
3439
|
+
this.bytes -= old.object.byteLength;
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
|
|
3444
|
+
// Resolve an object from the data that `listpack` already inflated.
|
|
3445
|
+
// Return null when the object needs `readSlice`. This happens when the base of
|
|
3446
|
+
// a delta is not in the cache, or when the delta is corrupt.
|
|
3447
|
+
function resolveInflated(
|
|
3448
|
+
{ type, data, reference, offset },
|
|
3449
|
+
cache,
|
|
3450
|
+
offsetByOid
|
|
3451
|
+
) {
|
|
3452
|
+
// `applyDelta` and `shasum` need a Buffer. This is a view and copies nothing.
|
|
3453
|
+
const object = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
3454
|
+
if (type !== 'ofs-delta' && type !== 'ref-delta') return { type, object }
|
|
3455
|
+
const baseOffset =
|
|
3456
|
+
type === 'ofs-delta'
|
|
3457
|
+
? offset - decodeVarInt(new BufferCursor(reference))
|
|
3458
|
+
: offsetByOid.get(reference.toString('hex'));
|
|
3459
|
+
const base = cache.get(baseOffset);
|
|
3460
|
+
if (!base) return null
|
|
3461
|
+
try {
|
|
3462
|
+
return {
|
|
3463
|
+
type: base.type,
|
|
3464
|
+
object: Buffer.from(applyDelta(object, base.object)),
|
|
3465
|
+
}
|
|
3466
|
+
} catch (err) {
|
|
3467
|
+
// A corrupt delta. `readSlice` reports it again. Any other error is a bug.
|
|
3468
|
+
if (err instanceof InternalError || err instanceof RangeError) return null
|
|
3469
|
+
throw err
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
|
|
3370
3473
|
class GitPackIndex {
|
|
3371
3474
|
constructor(stuff) {
|
|
3372
3475
|
Object.assign(this, stuff);
|
|
@@ -3438,6 +3541,9 @@ class GitPackIndex {
|
|
|
3438
3541
|
const offsets = new Map();
|
|
3439
3542
|
let totalObjectCount = null;
|
|
3440
3543
|
let lastPercent = null;
|
|
3544
|
+
// Objects that `listpack` inflated, by pack offset. A delta finds its base here.
|
|
3545
|
+
const cache = new ObjectCache(RESOLVE_CACHE_BYTES);
|
|
3546
|
+
const offsetByOid = new Map();
|
|
3441
3547
|
|
|
3442
3548
|
await listpack([pack], async ({ data, type, reference, offset, num }) => {
|
|
3443
3549
|
if (totalObjectCount === null) totalObjectCount = num;
|
|
@@ -3473,6 +3579,20 @@ class GitPackIndex {
|
|
|
3473
3579
|
offset,
|
|
3474
3580
|
};
|
|
3475
3581
|
}
|
|
3582
|
+
|
|
3583
|
+
// The object is already inflated, so get its oid now. Then the loop below
|
|
3584
|
+
// does not inflate it again. That loop reads all other objects.
|
|
3585
|
+
const o = offsetToObject[offset];
|
|
3586
|
+
if (!o) return
|
|
3587
|
+
const resolved = resolveInflated(
|
|
3588
|
+
{ type, data, reference, offset },
|
|
3589
|
+
cache,
|
|
3590
|
+
offsetByOid
|
|
3591
|
+
);
|
|
3592
|
+
if (!resolved) return
|
|
3593
|
+
o.oid = await shasum(GitObject.wrap(resolved));
|
|
3594
|
+
offsetByOid.set(o.oid, offset);
|
|
3595
|
+
cache.set(offset, resolved);
|
|
3476
3596
|
});
|
|
3477
3597
|
|
|
3478
3598
|
// We need to know the lengths of the slices to compute the CRCs.
|
|
@@ -3516,20 +3636,21 @@ class GitPackIndex {
|
|
|
3516
3636
|
lastPercent = percent;
|
|
3517
3637
|
|
|
3518
3638
|
const o = offsetToObject[offset];
|
|
3519
|
-
if (o.oid)
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
} catch (err) {
|
|
3531
|
-
continue
|
|
3639
|
+
if (!o.oid) {
|
|
3640
|
+
// The first pass did not resolve this object, so read it.
|
|
3641
|
+
try {
|
|
3642
|
+
p.readDepth = 0;
|
|
3643
|
+
p.externalReadDepth = 0;
|
|
3644
|
+
const { type, object } = await p.readSlice({ start: offset });
|
|
3645
|
+
objectsByDepth[p.readDepth] += 1;
|
|
3646
|
+
o.oid = await shasum(GitObject.wrap({ type, object }));
|
|
3647
|
+
} catch (err) {
|
|
3648
|
+
continue
|
|
3649
|
+
}
|
|
3532
3650
|
}
|
|
3651
|
+
hashes.push(o.oid);
|
|
3652
|
+
offsets.set(o.oid, offset);
|
|
3653
|
+
crcs[o.oid] = o.crc;
|
|
3533
3654
|
}
|
|
3534
3655
|
|
|
3535
3656
|
hashes.sort();
|
|
@@ -5024,9 +5145,11 @@ class GitWalkerFs {
|
|
|
5024
5145
|
// 1) if we can (because the oid and mode are the same)
|
|
5025
5146
|
// 2) and only if we need to (because other stats differ)
|
|
5026
5147
|
// 3) and only if the caller opted in to refreshing the index
|
|
5148
|
+
// 4) and not for an intent-to-add entry, which inserting would stage
|
|
5027
5149
|
if (
|
|
5028
5150
|
self.refresh &&
|
|
5029
5151
|
stage &&
|
|
5152
|
+
!stage.flags.intentToAdd &&
|
|
5030
5153
|
oid === stage.oid &&
|
|
5031
5154
|
(!filemode || stats.mode === stage.mode) &&
|
|
5032
5155
|
compareStats(stats, stage, filemode, trustino)
|
|
@@ -6534,7 +6657,10 @@ async function _commit({
|
|
|
6534
6657
|
return GitIndexManager.acquire(
|
|
6535
6658
|
{ fs, gitdir, cache, allowUnmerged: false },
|
|
6536
6659
|
async function (index) {
|
|
6537
|
-
|
|
6660
|
+
// Entries added with `git add --intent-to-add` are not part of the tree
|
|
6661
|
+
const inodes = flatFileListToDirectoryStructure(
|
|
6662
|
+
index.entries.filter(entry => !entry.flags.intentToAdd)
|
|
6663
|
+
);
|
|
6538
6664
|
const inode = inodes.get('.');
|
|
6539
6665
|
if (!tree) {
|
|
6540
6666
|
tree = await constructTree({ fs, gitdir, inode, dryRun });
|
|
@@ -10116,8 +10242,8 @@ function filterCapabilities(server, client) {
|
|
|
10116
10242
|
|
|
10117
10243
|
const pkg = {
|
|
10118
10244
|
name: 'isomorphic-git',
|
|
10119
|
-
version: '1.44.
|
|
10120
|
-
agent: 'git/isomorphic-git@1.44.
|
|
10245
|
+
version: '1.44.7',
|
|
10246
|
+
agent: 'git/isomorphic-git@1.44.7',
|
|
10121
10247
|
};
|
|
10122
10248
|
|
|
10123
10249
|
class FIFO {
|
|
@@ -17061,8 +17187,14 @@ async function status({
|
|
|
17061
17187
|
type: 'blob',
|
|
17062
17188
|
object,
|
|
17063
17189
|
});
|
|
17064
|
-
// If the oid in the index === working dir oid but stats differed update cache
|
|
17065
|
-
|
|
17190
|
+
// If the oid in the index === working dir oid but stats differed update cache.
|
|
17191
|
+
// An intent-to-add entry is left alone: inserting it again would stage it.
|
|
17192
|
+
if (
|
|
17193
|
+
refresh &&
|
|
17194
|
+
I &&
|
|
17195
|
+
!indexEntry.flags.intentToAdd &&
|
|
17196
|
+
indexEntry.oid === workdirOid
|
|
17197
|
+
) {
|
|
17066
17198
|
// and as long as our fs.stats aren't bad.
|
|
17067
17199
|
// size of -1 happens over a BrowserFS HTTP Backend that doesn't serve Content-Length headers
|
|
17068
17200
|
// (like the Karma webserver) because BrowserFS HTTP Backend uses HTTP HEAD requests to do fs.stat
|