ranger-compiler 3.4.0 → 3.5.0
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/CHANGELOG.md +6 -25
- package/README.md +3 -2
- package/dist/api.d.ts +393 -0
- package/dist/api.js +4140 -413
- package/dist/git-http.mjs +126 -0
- package/dist/lib/zip/Inflate.rgr +675 -0
- package/dist/lib/zip/ZipBuffer.rgr +358 -0
- package/dist/package.json +1 -1
- package/dist/rgrc.js +3540 -56
- package/package.json +10 -10
package/dist/rgrc.js
CHANGED
|
@@ -14331,6 +14331,24 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
14331
14331
|
};
|
|
14332
14332
|
return 0 - 1;
|
|
14333
14333
|
};
|
|
14334
|
+
PkgImport.manifestChain = function(env, startDir, libraryPaths) {
|
|
14335
|
+
let dirs = [];
|
|
14336
|
+
const first = PkgImport.walkUp(env, startDir);
|
|
14337
|
+
if ( first.length > 0 ) {
|
|
14338
|
+
dirs.push(first);
|
|
14339
|
+
}
|
|
14340
|
+
let i = libraryPaths.length - 1;
|
|
14341
|
+
while (i >= 0) {
|
|
14342
|
+
const cand = PkgImport.walkUp(env, libraryPaths[i]);
|
|
14343
|
+
if ( cand.length > 0 ) {
|
|
14344
|
+
if ( dirs.indexOf(cand) < 0 ) {
|
|
14345
|
+
dirs.push(cand);
|
|
14346
|
+
}
|
|
14347
|
+
}
|
|
14348
|
+
i = i - 1;
|
|
14349
|
+
};
|
|
14350
|
+
return dirs;
|
|
14351
|
+
};
|
|
14334
14352
|
PkgImport.resolve = async function(env, startDir, spec, libraryPaths) {
|
|
14335
14353
|
const hit = new PkgHit();
|
|
14336
14354
|
if ( PkgImport.isPkg(spec) == false ) {
|
|
@@ -14338,6 +14356,28 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
14338
14356
|
hit.name = PkgImport.stripDot(spec);
|
|
14339
14357
|
return hit;
|
|
14340
14358
|
}
|
|
14359
|
+
const dirs = PkgImport.manifestChain(env, startDir, libraryPaths);
|
|
14360
|
+
if ( dirs.length == 0 ) {
|
|
14361
|
+
hit.err = "no ranger.json for " + spec;
|
|
14362
|
+
return hit;
|
|
14363
|
+
}
|
|
14364
|
+
let firstErr = "";
|
|
14365
|
+
let di = 0;
|
|
14366
|
+
while (di < dirs.length) {
|
|
14367
|
+
const got = await PkgImport.resolveIn(env, dirs[di], spec);
|
|
14368
|
+
if ( got.ok ) {
|
|
14369
|
+
return got;
|
|
14370
|
+
}
|
|
14371
|
+
if ( firstErr.length == 0 ) {
|
|
14372
|
+
firstErr = got.err;
|
|
14373
|
+
}
|
|
14374
|
+
di = di + 1;
|
|
14375
|
+
};
|
|
14376
|
+
hit.err = firstErr;
|
|
14377
|
+
return hit;
|
|
14378
|
+
};
|
|
14379
|
+
PkgImport.resolveIn = async function(env, manDir, spec) {
|
|
14380
|
+
const hit = new PkgHit();
|
|
14341
14381
|
const rest = spec.substring(4, spec.length );
|
|
14342
14382
|
let pkgName = rest;
|
|
14343
14383
|
let sub = "";
|
|
@@ -14346,11 +14386,6 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
14346
14386
|
pkgName = rest.substring(0, slash );
|
|
14347
14387
|
sub = rest.substring((slash + 1), rest.length );
|
|
14348
14388
|
}
|
|
14349
|
-
const manDir = PkgImport.findManifestDir(env, startDir, libraryPaths);
|
|
14350
|
-
if ( manDir.length == 0 ) {
|
|
14351
|
-
hit.err = "no ranger.json for " + spec;
|
|
14352
|
-
return hit;
|
|
14353
|
-
}
|
|
14354
14389
|
const manText = await PkgImport.readText(env, manDir, "ranger.json");
|
|
14355
14390
|
const reader = new PkgJRead();
|
|
14356
14391
|
const man = reader.parse(manText);
|
|
@@ -14365,22 +14400,37 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
14365
14400
|
pkgRoot = manDir;
|
|
14366
14401
|
entry = PkgJRead.strOf(man, "entry");
|
|
14367
14402
|
} else {
|
|
14403
|
+
let dep = new PkgJVal();
|
|
14404
|
+
let declared = false;
|
|
14368
14405
|
const deps = PkgJRead.child(man, "dependencies");
|
|
14369
|
-
if ( typeof(deps)
|
|
14370
|
-
|
|
14371
|
-
|
|
14406
|
+
if ( (typeof(deps) !== "undefined" && deps != null ) ) {
|
|
14407
|
+
const depMap = deps;
|
|
14408
|
+
const specObj = PkgJRead.child(depMap, pkgName);
|
|
14409
|
+
if ( (typeof(specObj) !== "undefined" && specObj != null ) ) {
|
|
14410
|
+
dep = specObj;
|
|
14411
|
+
declared = true;
|
|
14412
|
+
}
|
|
14372
14413
|
}
|
|
14373
|
-
|
|
14374
|
-
|
|
14375
|
-
|
|
14376
|
-
|
|
14377
|
-
|
|
14414
|
+
if ( declared == false ) {
|
|
14415
|
+
const lockOnly = await PkgImport.readText(env, manDir, "ranger.lock");
|
|
14416
|
+
const lockHit = PkgImport.lockRoot(env, lockOnly, pkgName, manDir);
|
|
14417
|
+
if ( lockHit.length == 0 ) {
|
|
14418
|
+
hit.err = ("package " + pkgName) + " is not a dependency";
|
|
14419
|
+
return hit;
|
|
14420
|
+
}
|
|
14421
|
+
pkgRoot = lockHit;
|
|
14378
14422
|
}
|
|
14379
|
-
|
|
14380
|
-
|
|
14381
|
-
|
|
14382
|
-
|
|
14383
|
-
|
|
14423
|
+
let pathDep = "";
|
|
14424
|
+
if ( declared ) {
|
|
14425
|
+
pathDep = PkgJRead.strOf(dep, "path");
|
|
14426
|
+
}
|
|
14427
|
+
if ( pathDep.length > 0 && pkgRoot.length == 0 ) {
|
|
14428
|
+
const cand = PkgImport.foldPath(PkgImport.joinPath(manDir, pathDep));
|
|
14429
|
+
if ( operatorsOf_8.filec95exists_9(env, cand, "ranger.json") ) {
|
|
14430
|
+
pkgRoot = cand;
|
|
14431
|
+
}
|
|
14432
|
+
}
|
|
14433
|
+
if ( pkgRoot.length == 0 ) {
|
|
14384
14434
|
const vendorDir = PkgImport.joinPath(manDir, ("vendor/ranger/" + pkgName));
|
|
14385
14435
|
if ( operatorsOf_8.filec95exists_9(env, vendorDir, "ranger.json") ) {
|
|
14386
14436
|
pkgRoot = vendorDir;
|
|
@@ -18419,6 +18469,11 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
18419
18469
|
if ( ctx.hasCompilerFlag("verbose") ) {
|
|
18420
18470
|
console.log((("importing " + import_file) + " from ") + filePathIs);
|
|
18421
18471
|
}
|
|
18472
|
+
const seenKey = "@" + PkgImport.foldPath(((filePathIs + "/") + searchName));
|
|
18473
|
+
if ( ( typeof(ctx.already_imported[seenKey] ) != "undefined" && Object.prototype.hasOwnProperty.call(ctx.already_imported, seenKey) ) ) {
|
|
18474
|
+
return;
|
|
18475
|
+
}
|
|
18476
|
+
ctx.already_imported[seenKey] = true;
|
|
18422
18477
|
const c = await operatorsOf_8.readc95file_9(
|
|
18423
18478
|
env,
|
|
18424
18479
|
filePathIs,
|
|
@@ -20934,21 +20989,19 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
20934
20989
|
};
|
|
20935
20990
|
}
|
|
20936
20991
|
};
|
|
20937
|
-
const cClassList = this.serializedClasses.slice().sort(((left, right) => {
|
|
20992
|
+
const cClassList = this.serializedClasses.slice().sort((async (left, right) => {
|
|
20938
20993
|
let left_had = false;
|
|
20939
20994
|
let right_had = false;
|
|
20940
|
-
|
|
20941
|
-
var item = left.variables[i_6];
|
|
20995
|
+
await operatorsOf.forEach_11(left.variables, ((item, index) => {
|
|
20942
20996
|
if ( item.nameNode.type_name == right.name || item.nameNode.array_type == right.name ) {
|
|
20943
20997
|
left_had = true;
|
|
20944
20998
|
}
|
|
20945
|
-
};
|
|
20946
|
-
|
|
20947
|
-
|
|
20948
|
-
if ( item_1.nameNode.type_name == left.name || item_1.nameNode.array_type == left.name ) {
|
|
20999
|
+
}));
|
|
21000
|
+
await operatorsOf.forEach_11(right.variables, ((item, index) => {
|
|
21001
|
+
if ( item.nameNode.type_name == left.name || item.nameNode.array_type == left.name ) {
|
|
20949
21002
|
right_had = true;
|
|
20950
21003
|
}
|
|
20951
|
-
};
|
|
21004
|
+
}));
|
|
20952
21005
|
if ( left_had ) {
|
|
20953
21006
|
return 1;
|
|
20954
21007
|
}
|
|
@@ -20957,12 +21010,12 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
20957
21010
|
}
|
|
20958
21011
|
return 0;
|
|
20959
21012
|
}));
|
|
20960
|
-
for ( let
|
|
20961
|
-
var cl_1 = cClassList[
|
|
21013
|
+
for ( let i_6 = 0; i_6 < cClassList.length; i_6++) {
|
|
21014
|
+
var cl_1 = cClassList[i_6];
|
|
20962
21015
|
cl_1.is_serialized = true;
|
|
20963
21016
|
};
|
|
20964
|
-
for ( let
|
|
20965
|
-
var cl_2 = cClassList[
|
|
21017
|
+
for ( let i_7 = 0; i_7 < cClassList.length; i_7++) {
|
|
21018
|
+
var cl_2 = cClassList[i_7];
|
|
20966
21019
|
const ser = new RangerSerializeClass();
|
|
20967
21020
|
if ( ser.validateSerializedClass(cl_2, cl_2.ctx) == false ) {
|
|
20968
21021
|
continue;
|
|
@@ -20978,8 +21031,8 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
20978
21031
|
await this.WalkCollectMethods(rn, cl_2.ctx, wr);
|
|
20979
21032
|
this.walkAlso.push(rn);
|
|
20980
21033
|
};
|
|
20981
|
-
for ( let
|
|
20982
|
-
var cl_3 = this.immutableClasses[
|
|
21034
|
+
for ( let i_8 = 0; i_8 < this.immutableClasses.length; i_8++) {
|
|
21035
|
+
var cl_3 = this.immutableClasses[i_8];
|
|
20983
21036
|
const ser_1 = new RangerImmutableExtension();
|
|
20984
21037
|
const extWr_1 = new CodeWriter();
|
|
20985
21038
|
ser_1.createImmutableExtension(cl_3, cl_3.ctx, extWr_1);
|
|
@@ -21026,12 +21079,12 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
21026
21079
|
ctx.compilerSettings["processTsHelpers"] = tsWr.getCode();
|
|
21027
21080
|
}
|
|
21028
21081
|
}
|
|
21029
|
-
for ( let
|
|
21030
|
-
var cl_4 = this.processClasses[
|
|
21082
|
+
for ( let i_9 = 0; i_9 < this.processClasses.length; i_9++) {
|
|
21083
|
+
var cl_4 = this.processClasses[i_9];
|
|
21031
21084
|
cl_4.is_process = true;
|
|
21032
21085
|
let hasProcessBase = false;
|
|
21033
|
-
for ( let
|
|
21034
|
-
var extName = cl_4.extends_classes[
|
|
21086
|
+
for ( let i_10 = 0; i_10 < cl_4.extends_classes.length; i_10++) {
|
|
21087
|
+
var extName = cl_4.extends_classes[i_10];
|
|
21035
21088
|
if ( extName == "RangerProcessBase" ) {
|
|
21036
21089
|
hasProcessBase = true;
|
|
21037
21090
|
}
|
|
@@ -21047,7 +21100,7 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
21047
21100
|
}
|
|
21048
21101
|
const procGen = new RangerProcessClass();
|
|
21049
21102
|
const extWr_2 = new CodeWriter();
|
|
21050
|
-
const processTypeId =
|
|
21103
|
+
const processTypeId = i_9 + 1;
|
|
21051
21104
|
procGen.createProcessExtension(cl_4, cl_4.ctx, extWr_2, processTypeId);
|
|
21052
21105
|
const theCode_2 = extWr_2.getCode();
|
|
21053
21106
|
const code_2 = new SourceCode(theCode_2);
|
|
@@ -21058,16 +21111,16 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
21058
21111
|
await this.WalkCollectMethods(rn_2, cl_4.ctx, wr);
|
|
21059
21112
|
this.walkAlso.push(rn_2);
|
|
21060
21113
|
};
|
|
21061
|
-
for ( let
|
|
21062
|
-
var cname = ctx.definedClassList[
|
|
21114
|
+
for ( let i_11 = 0; i_11 < ctx.definedClassList.length; i_11++) {
|
|
21115
|
+
var cname = ctx.definedClassList[i_11];
|
|
21063
21116
|
allTypes.push(cname);
|
|
21064
21117
|
const c = ( Object.prototype.hasOwnProperty.call(ctx.definedClasses, cname) ? ctx.definedClasses[cname] : undefined );
|
|
21065
21118
|
if ( ((c.is_system || c.is_interface) || c.is_template) || c.is_trait ) {
|
|
21066
21119
|
continue;
|
|
21067
21120
|
}
|
|
21068
21121
|
let varNames = {};
|
|
21069
|
-
for ( let
|
|
21070
|
-
var p = c.variables[
|
|
21122
|
+
for ( let i_12 = 0; i_12 < c.variables.length; i_12++) {
|
|
21123
|
+
var p = c.variables[i_12];
|
|
21071
21124
|
ctx.hadValidType(p.nameNode);
|
|
21072
21125
|
varNames[p.name] = true;
|
|
21073
21126
|
};
|
|
@@ -21079,8 +21132,8 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
21079
21132
|
}));
|
|
21080
21133
|
}));
|
|
21081
21134
|
};
|
|
21082
|
-
for ( let
|
|
21083
|
-
var cname_1 = ctx.definedClassList[
|
|
21135
|
+
for ( let i_13 = 0; i_13 < ctx.definedClassList.length; i_13++) {
|
|
21136
|
+
var cname_1 = ctx.definedClassList[i_13];
|
|
21084
21137
|
allTypes.push(cname_1);
|
|
21085
21138
|
};
|
|
21086
21139
|
allTypes.push("int");
|
|
@@ -21095,8 +21148,8 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
21095
21148
|
rootCtx.addClass("Any", new_class);
|
|
21096
21149
|
new_class.is_union = true;
|
|
21097
21150
|
let did_push = {};
|
|
21098
|
-
for ( let
|
|
21099
|
-
var typeName_1 = allTypes[
|
|
21151
|
+
for ( let i_14 = 0; i_14 < allTypes.length; i_14++) {
|
|
21152
|
+
var typeName_1 = allTypes[i_14];
|
|
21100
21153
|
if ( ( typeof(did_push[typeName_1] ) != "undefined" && Object.prototype.hasOwnProperty.call(did_push, typeName_1) ) ) {
|
|
21101
21154
|
continue;
|
|
21102
21155
|
}
|
|
@@ -21732,6 +21785,15 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
21732
21785
|
ctx.addError(node, "Could not import file " + import_file);
|
|
21733
21786
|
return;
|
|
21734
21787
|
}
|
|
21788
|
+
const seenKey2 = "@" + PkgImport.foldPath(((filePathIs + "/") + searchName));
|
|
21789
|
+
if ( ( typeof(ctx.already_imported[seenKey2] ) != "undefined" && Object.prototype.hasOwnProperty.call(ctx.already_imported, seenKey2) ) ) {
|
|
21790
|
+
for ( let i2 = 0; i2 < node.children.length; i2++) {
|
|
21791
|
+
var item2 = node.children[i2];
|
|
21792
|
+
await this.WalkCollectMethods(item2, ctx, wr);
|
|
21793
|
+
};
|
|
21794
|
+
return;
|
|
21795
|
+
}
|
|
21796
|
+
ctx.already_imported[seenKey2] = true;
|
|
21735
21797
|
const c = await operatorsOf_8.readc95file_9(
|
|
21736
21798
|
env,
|
|
21737
21799
|
filePathIs,
|
|
@@ -69356,7 +69418,7 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
69356
69418
|
this.inputFile = "";
|
|
69357
69419
|
this.outputFile = "";
|
|
69358
69420
|
this.targetLanguage = "";
|
|
69359
|
-
this.compilerVersion = "3.
|
|
69421
|
+
this.compilerVersion = "3.5.0";
|
|
69360
69422
|
this.useColors = ((typeof process !== "undefined" && process.stdout && process.stdout.isTTY) || false);
|
|
69361
69423
|
this.startTime = Date.now();
|
|
69362
69424
|
}
|
|
@@ -69647,6 +69709,3359 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
69647
69709
|
console.log(this.bold(title));
|
|
69648
69710
|
};
|
|
69649
69711
|
}
|
|
69712
|
+
class GitSha1 {
|
|
69713
|
+
constructor() {
|
|
69714
|
+
}
|
|
69715
|
+
}
|
|
69716
|
+
GitSha1.mask32 = function() {
|
|
69717
|
+
return (65535 | (65535 << 16));
|
|
69718
|
+
};
|
|
69719
|
+
GitSha1.add32 = function(a, b) {
|
|
69720
|
+
return ((a + b) & GitSha1.mask32());
|
|
69721
|
+
};
|
|
69722
|
+
GitSha1.not32 = function(x) {
|
|
69723
|
+
return ((~x) & GitSha1.mask32());
|
|
69724
|
+
};
|
|
69725
|
+
GitSha1.rotl = function(x, n) {
|
|
69726
|
+
const u = (x & GitSha1.mask32());
|
|
69727
|
+
return (((u << n) | (u >>> (32 - n))) & GitSha1.mask32());
|
|
69728
|
+
};
|
|
69729
|
+
GitSha1.copyRange = function(data, start, count) {
|
|
69730
|
+
let n = count;
|
|
69731
|
+
const __len = data.byteLength;
|
|
69732
|
+
if ( start < 0 ) {
|
|
69733
|
+
return (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
69734
|
+
}
|
|
69735
|
+
if ( start >= __len ) {
|
|
69736
|
+
return (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
69737
|
+
}
|
|
69738
|
+
if ( start + n > __len ) {
|
|
69739
|
+
n = __len - start;
|
|
69740
|
+
}
|
|
69741
|
+
if ( n < 0 ) {
|
|
69742
|
+
n = 0;
|
|
69743
|
+
}
|
|
69744
|
+
let out = (function(){ var b = new ArrayBuffer(n); b._view = new DataView(b); return b; })();
|
|
69745
|
+
(function(
|
|
69746
|
+
d,
|
|
69747
|
+
dOff,
|
|
69748
|
+
s,
|
|
69749
|
+
sOff,
|
|
69750
|
+
len
|
|
69751
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(out,0,data,start,n);
|
|
69752
|
+
return out;
|
|
69753
|
+
};
|
|
69754
|
+
GitSha1.ascii = function(data, start, count) {
|
|
69755
|
+
let n = count;
|
|
69756
|
+
const __len = data.byteLength;
|
|
69757
|
+
if ( start + n > __len ) {
|
|
69758
|
+
n = __len - start;
|
|
69759
|
+
}
|
|
69760
|
+
if ( n < 0 ) {
|
|
69761
|
+
n = 0;
|
|
69762
|
+
}
|
|
69763
|
+
let s = "";
|
|
69764
|
+
let i = 0;
|
|
69765
|
+
while (i < n) {
|
|
69766
|
+
s = s + String.fromCharCode(data._view.getUint8((start + i)));
|
|
69767
|
+
i = i + 1;
|
|
69768
|
+
};
|
|
69769
|
+
return s;
|
|
69770
|
+
};
|
|
69771
|
+
GitSha1.u32be = function(data, i) {
|
|
69772
|
+
const b0 = data._view.getUint8(i);
|
|
69773
|
+
const b1 = data._view.getUint8((i + 1));
|
|
69774
|
+
const b2 = data._view.getUint8((i + 2));
|
|
69775
|
+
const b3 = data._view.getUint8((i + 3));
|
|
69776
|
+
return ((b0 << 24) | ((b1 << 16) | ((b2 << 8) | b3)));
|
|
69777
|
+
};
|
|
69778
|
+
GitSha1.hexDigit = function(d) {
|
|
69779
|
+
const h = "0123456789abcdef";
|
|
69780
|
+
return h.substring(d, (d + 1) );
|
|
69781
|
+
};
|
|
69782
|
+
GitSha1.toHex = function(data) {
|
|
69783
|
+
const n = data.byteLength;
|
|
69784
|
+
let s = "";
|
|
69785
|
+
let i = 0;
|
|
69786
|
+
while (i < n) {
|
|
69787
|
+
const b = data._view.getUint8(i);
|
|
69788
|
+
const hi = (b >>> 4);
|
|
69789
|
+
const lo = (b & 15);
|
|
69790
|
+
s = s + GitSha1.hexDigit(hi);
|
|
69791
|
+
s = s + GitSha1.hexDigit(lo);
|
|
69792
|
+
i = i + 1;
|
|
69793
|
+
};
|
|
69794
|
+
return s;
|
|
69795
|
+
};
|
|
69796
|
+
GitSha1.fromHex = function(hex) {
|
|
69797
|
+
const n = hex.length;
|
|
69798
|
+
const outLen = ((n / 2) | 0);
|
|
69799
|
+
let out = (function(){ var b = new ArrayBuffer(outLen); b._view = new DataView(b); return b; })();
|
|
69800
|
+
const digits = "0123456789abcdef";
|
|
69801
|
+
let i = 0;
|
|
69802
|
+
while (i < outLen) {
|
|
69803
|
+
const c0 = hex.substring((i * 2), (i * 2 + 1) );
|
|
69804
|
+
const c1 = hex.substring((i * 2 + 1), (i * 2 + 2) );
|
|
69805
|
+
let v = 0;
|
|
69806
|
+
let d = 0;
|
|
69807
|
+
while (d < 16) {
|
|
69808
|
+
const ch = digits.substring(d, (d + 1) );
|
|
69809
|
+
if ( ch == c0 ) {
|
|
69810
|
+
v = d * 16;
|
|
69811
|
+
}
|
|
69812
|
+
d = d + 1;
|
|
69813
|
+
};
|
|
69814
|
+
d = 0;
|
|
69815
|
+
while (d < 16) {
|
|
69816
|
+
const ch2 = digits.substring(d, (d + 1) );
|
|
69817
|
+
if ( ch2 == c1 ) {
|
|
69818
|
+
v = v + d;
|
|
69819
|
+
}
|
|
69820
|
+
d = d + 1;
|
|
69821
|
+
};
|
|
69822
|
+
out._view.setUint8(i, v);
|
|
69823
|
+
i = i + 1;
|
|
69824
|
+
};
|
|
69825
|
+
return out;
|
|
69826
|
+
};
|
|
69827
|
+
GitSha1.hash = function(data) {
|
|
69828
|
+
const L = data.byteLength;
|
|
69829
|
+
const cap = L + 128;
|
|
69830
|
+
let msg = (function(){ var b = new ArrayBuffer(cap); b._view = new DataView(b); return b; })();
|
|
69831
|
+
if ( L > 0 ) {
|
|
69832
|
+
(function(
|
|
69833
|
+
d,
|
|
69834
|
+
dOff,
|
|
69835
|
+
s,
|
|
69836
|
+
sOff,
|
|
69837
|
+
len
|
|
69838
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(msg,0,data,0,L);
|
|
69839
|
+
}
|
|
69840
|
+
msg._view.setUint8(L, 128);
|
|
69841
|
+
let pos = L + 1;
|
|
69842
|
+
while ((pos & 63) != 56) {
|
|
69843
|
+
msg._view.setUint8(pos, 0);
|
|
69844
|
+
pos = pos + 1;
|
|
69845
|
+
};
|
|
69846
|
+
const bitLen = L * 8;
|
|
69847
|
+
msg._view.setUint8(pos, 0);
|
|
69848
|
+
msg._view.setUint8(pos + 1, 0);
|
|
69849
|
+
msg._view.setUint8(pos + 2, 0);
|
|
69850
|
+
msg._view.setUint8(pos + 3, 0);
|
|
69851
|
+
msg._view.setUint8(pos + 4, ((bitLen >>> 24) & 255));
|
|
69852
|
+
msg._view.setUint8(pos + 5, ((bitLen >>> 16) & 255));
|
|
69853
|
+
msg._view.setUint8(pos + 6, ((bitLen >>> 8) & 255));
|
|
69854
|
+
msg._view.setUint8(pos + 7, (bitLen & 255));
|
|
69855
|
+
const msgLen = pos + 8;
|
|
69856
|
+
let h0 = 1732584193;
|
|
69857
|
+
let h1 = 0 - 271733879;
|
|
69858
|
+
let h2 = 0 - 1732584194;
|
|
69859
|
+
let h3 = 271733878;
|
|
69860
|
+
let h4 = 0 - 1009589776;
|
|
69861
|
+
let w = [];
|
|
69862
|
+
let wi = 0;
|
|
69863
|
+
while (wi < 80) {
|
|
69864
|
+
w.push(0);
|
|
69865
|
+
wi = wi + 1;
|
|
69866
|
+
};
|
|
69867
|
+
let off = 0;
|
|
69868
|
+
while (off < msgLen) {
|
|
69869
|
+
let t = 0;
|
|
69870
|
+
while (t < 16) {
|
|
69871
|
+
w[t] = GitSha1.u32be(msg, (off + t * 4));
|
|
69872
|
+
t = t + 1;
|
|
69873
|
+
};
|
|
69874
|
+
while (t < 80) {
|
|
69875
|
+
const x = ((w[(t - 3)] ^ w[(t - 8)]) ^ (w[(t - 14)] ^ w[(t - 16)]));
|
|
69876
|
+
w[t] = GitSha1.rotl(x, 1);
|
|
69877
|
+
t = t + 1;
|
|
69878
|
+
};
|
|
69879
|
+
let a = h0;
|
|
69880
|
+
let b = h1;
|
|
69881
|
+
let c = h2;
|
|
69882
|
+
let d = h3;
|
|
69883
|
+
let e = h4;
|
|
69884
|
+
t = 0;
|
|
69885
|
+
while (t < 80) {
|
|
69886
|
+
let f = 0;
|
|
69887
|
+
let k = 0;
|
|
69888
|
+
if ( t < 20 ) {
|
|
69889
|
+
f = ((b & c) | (GitSha1.not32(b) & d));
|
|
69890
|
+
k = 1518500249;
|
|
69891
|
+
}
|
|
69892
|
+
if ( t >= 20 && t < 40 ) {
|
|
69893
|
+
f = ((b ^ c) ^ d);
|
|
69894
|
+
k = 1859775393;
|
|
69895
|
+
}
|
|
69896
|
+
if ( t >= 40 && t < 60 ) {
|
|
69897
|
+
f = (((b & c) | (b & d)) | (c & d));
|
|
69898
|
+
k = 0 - 1894007588;
|
|
69899
|
+
}
|
|
69900
|
+
if ( t >= 60 ) {
|
|
69901
|
+
f = ((b ^ c) ^ d);
|
|
69902
|
+
k = 0 - 899497514;
|
|
69903
|
+
}
|
|
69904
|
+
const temp = GitSha1.add32(GitSha1.add32(GitSha1.add32(GitSha1.add32(GitSha1.rotl(a, 5), f), e), k), w[t]);
|
|
69905
|
+
e = d;
|
|
69906
|
+
d = c;
|
|
69907
|
+
c = GitSha1.rotl(b, 30);
|
|
69908
|
+
b = a;
|
|
69909
|
+
a = temp;
|
|
69910
|
+
t = t + 1;
|
|
69911
|
+
};
|
|
69912
|
+
h0 = GitSha1.add32(h0, a);
|
|
69913
|
+
h1 = GitSha1.add32(h1, b);
|
|
69914
|
+
h2 = GitSha1.add32(h2, c);
|
|
69915
|
+
h3 = GitSha1.add32(h3, d);
|
|
69916
|
+
h4 = GitSha1.add32(h4, e);
|
|
69917
|
+
off = off + 64;
|
|
69918
|
+
};
|
|
69919
|
+
const out = (function(){ var b = new ArrayBuffer(20); b._view = new DataView(b); return b; })();
|
|
69920
|
+
GitSha1.writeU32be(out, 0, h0);
|
|
69921
|
+
GitSha1.writeU32be(out, 4, h1);
|
|
69922
|
+
GitSha1.writeU32be(out, 8, h2);
|
|
69923
|
+
GitSha1.writeU32be(out, 12, h3);
|
|
69924
|
+
GitSha1.writeU32be(out, 16, h4);
|
|
69925
|
+
return out;
|
|
69926
|
+
};
|
|
69927
|
+
GitSha1.writeU32be = function(out, i, v) {
|
|
69928
|
+
out._view.setUint8(i, ((v >>> 24) & 255));
|
|
69929
|
+
out._view.setUint8(i + 1, ((v >>> 16) & 255));
|
|
69930
|
+
out._view.setUint8(i + 2, ((v >>> 8) & 255));
|
|
69931
|
+
out._view.setUint8(i + 3, (v & 255));
|
|
69932
|
+
};
|
|
69933
|
+
GitSha1.hashHex = function(data) {
|
|
69934
|
+
return GitSha1.toHex(GitSha1.hash(data));
|
|
69935
|
+
};
|
|
69936
|
+
GitSha1.objectId = function(kind, payload) {
|
|
69937
|
+
const sizeText = (payload.byteLength.toString());
|
|
69938
|
+
const prefix = (kind + " ") + sizeText;
|
|
69939
|
+
const pLen = prefix.length;
|
|
69940
|
+
const n = payload.byteLength;
|
|
69941
|
+
let raw = (function(){ var b = new ArrayBuffer(((pLen + 1) + n)); b._view = new DataView(b); return b; })();
|
|
69942
|
+
let i = 0;
|
|
69943
|
+
while (i < pLen) {
|
|
69944
|
+
raw._view.setUint8(i, prefix.charCodeAt(i ));
|
|
69945
|
+
i = i + 1;
|
|
69946
|
+
};
|
|
69947
|
+
raw._view.setUint8(pLen, 0);
|
|
69948
|
+
if ( n > 0 ) {
|
|
69949
|
+
(function(
|
|
69950
|
+
d,
|
|
69951
|
+
dOff,
|
|
69952
|
+
s,
|
|
69953
|
+
sOff,
|
|
69954
|
+
len
|
|
69955
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(raw,pLen + 1,payload,0,n);
|
|
69956
|
+
}
|
|
69957
|
+
return GitSha1.hashHex(raw);
|
|
69958
|
+
};
|
|
69959
|
+
GitSha1.hexEq = function(a, b) {
|
|
69960
|
+
if ( a.length != b.length ) {
|
|
69961
|
+
return false;
|
|
69962
|
+
}
|
|
69963
|
+
return a == b;
|
|
69964
|
+
};
|
|
69965
|
+
class GitPkt {
|
|
69966
|
+
constructor() {
|
|
69967
|
+
this.ok = true;
|
|
69968
|
+
this.err = "";
|
|
69969
|
+
this.lines = [];
|
|
69970
|
+
this.raw = [];
|
|
69971
|
+
this.isFlush = [];
|
|
69972
|
+
}
|
|
69973
|
+
}
|
|
69974
|
+
class GitRef {
|
|
69975
|
+
constructor() {
|
|
69976
|
+
this.name = "";
|
|
69977
|
+
this.sha = "";
|
|
69978
|
+
this.peeled = "";
|
|
69979
|
+
}
|
|
69980
|
+
}
|
|
69981
|
+
class GitAdvertisement {
|
|
69982
|
+
constructor() {
|
|
69983
|
+
this.ok = true;
|
|
69984
|
+
this.err = "";
|
|
69985
|
+
this.service = "";
|
|
69986
|
+
this.caps = "";
|
|
69987
|
+
this.head = "";
|
|
69988
|
+
this.refs = [];
|
|
69989
|
+
}
|
|
69990
|
+
}
|
|
69991
|
+
class GitWant {
|
|
69992
|
+
constructor() {
|
|
69993
|
+
this.ok = true;
|
|
69994
|
+
this.err = "";
|
|
69995
|
+
this.sha = "";
|
|
69996
|
+
this.body = (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
69997
|
+
}
|
|
69998
|
+
}
|
|
69999
|
+
class GitSideband {
|
|
70000
|
+
constructor() {
|
|
70001
|
+
this.ok = true;
|
|
70002
|
+
this.err = "";
|
|
70003
|
+
this.pack = (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
70004
|
+
this.progress = "";
|
|
70005
|
+
}
|
|
70006
|
+
}
|
|
70007
|
+
class GitPktIO {
|
|
70008
|
+
constructor() {
|
|
70009
|
+
}
|
|
70010
|
+
}
|
|
70011
|
+
GitPktIO.hexVal = function(ch) {
|
|
70012
|
+
const c = ch.charCodeAt(0 );
|
|
70013
|
+
if ( c >= 48 && c <= 57 ) {
|
|
70014
|
+
return c - 48;
|
|
70015
|
+
}
|
|
70016
|
+
if ( c >= 97 && c <= 102 ) {
|
|
70017
|
+
return c - 87;
|
|
70018
|
+
}
|
|
70019
|
+
if ( c >= 65 && c <= 70 ) {
|
|
70020
|
+
return c - 55;
|
|
70021
|
+
}
|
|
70022
|
+
return 0 - 1;
|
|
70023
|
+
};
|
|
70024
|
+
GitPktIO.parseHex4 = function(data, at) {
|
|
70025
|
+
const s = GitSha1.ascii(data, at, 4);
|
|
70026
|
+
let v = 0;
|
|
70027
|
+
let i = 0;
|
|
70028
|
+
while (i < 4) {
|
|
70029
|
+
const d = GitPktIO.hexVal(s.substring(i, (i + 1) ));
|
|
70030
|
+
if ( d < 0 ) {
|
|
70031
|
+
return 0 - 1;
|
|
70032
|
+
}
|
|
70033
|
+
v = v * 16 + d;
|
|
70034
|
+
i = i + 1;
|
|
70035
|
+
};
|
|
70036
|
+
return v;
|
|
70037
|
+
};
|
|
70038
|
+
GitPktIO.hex4 = function(n) {
|
|
70039
|
+
const digits = "0123456789abcdef";
|
|
70040
|
+
const d0 = ((n >>> 12) & 15);
|
|
70041
|
+
const d1 = ((n >>> 8) & 15);
|
|
70042
|
+
const d2 = ((n >>> 4) & 15);
|
|
70043
|
+
const d3 = (n & 15);
|
|
70044
|
+
return ((digits.substring(d0, (d0 + 1) ) + digits.substring(d1, (d1 + 1) )) + digits.substring(d2, (d2 + 1) )) + digits.substring(d3, (d3 + 1) );
|
|
70045
|
+
};
|
|
70046
|
+
GitPktIO.encodeLine = function(text) {
|
|
70047
|
+
const n = text.length + 4;
|
|
70048
|
+
const h = GitPktIO.hex4(n);
|
|
70049
|
+
let raw = (function(){ var b = new ArrayBuffer(n); b._view = new DataView(b); return b; })();
|
|
70050
|
+
let i = 0;
|
|
70051
|
+
while (i < 4) {
|
|
70052
|
+
raw._view.setUint8(i, h.charCodeAt(i ));
|
|
70053
|
+
i = i + 1;
|
|
70054
|
+
};
|
|
70055
|
+
while (i < n) {
|
|
70056
|
+
raw._view.setUint8(i, text.charCodeAt((i - 4) ));
|
|
70057
|
+
i = i + 1;
|
|
70058
|
+
};
|
|
70059
|
+
return raw;
|
|
70060
|
+
};
|
|
70061
|
+
GitPktIO.encodeFlush = function() {
|
|
70062
|
+
let raw = (function(){ var b = new ArrayBuffer(4); b._view = new DataView(b); return b; })();
|
|
70063
|
+
raw._view.setUint8(0, 48);
|
|
70064
|
+
raw._view.setUint8(1, 48);
|
|
70065
|
+
raw._view.setUint8(2, 48);
|
|
70066
|
+
raw._view.setUint8(3, 48);
|
|
70067
|
+
return raw;
|
|
70068
|
+
};
|
|
70069
|
+
GitPktIO.parse = function(data) {
|
|
70070
|
+
const pkt = new GitPkt();
|
|
70071
|
+
const n = data.byteLength;
|
|
70072
|
+
let at = 0;
|
|
70073
|
+
while (at < n) {
|
|
70074
|
+
if ( at + 4 > n ) {
|
|
70075
|
+
pkt.ok = false;
|
|
70076
|
+
pkt.err = "truncated pkt-line length";
|
|
70077
|
+
return pkt;
|
|
70078
|
+
}
|
|
70079
|
+
const __len = GitPktIO.parseHex4(data, at);
|
|
70080
|
+
if ( __len < 0 ) {
|
|
70081
|
+
pkt.ok = false;
|
|
70082
|
+
pkt.err = "bad pkt-line hex";
|
|
70083
|
+
return pkt;
|
|
70084
|
+
}
|
|
70085
|
+
if ( __len == 0 ) {
|
|
70086
|
+
pkt.isFlush.push(true);
|
|
70087
|
+
pkt.lines.push("");
|
|
70088
|
+
pkt.raw.push(GitSha1.copyRange(data, at, 4));
|
|
70089
|
+
at = at + 4;
|
|
70090
|
+
} else {
|
|
70091
|
+
if ( __len == 1 || __len == 2 ) {
|
|
70092
|
+
pkt.isFlush.push(true);
|
|
70093
|
+
pkt.lines.push("");
|
|
70094
|
+
pkt.raw.push(GitSha1.copyRange(data, at, 4));
|
|
70095
|
+
at = at + 4;
|
|
70096
|
+
} else {
|
|
70097
|
+
if ( __len < 4 ) {
|
|
70098
|
+
pkt.ok = false;
|
|
70099
|
+
pkt.err = "pkt-line length < 4";
|
|
70100
|
+
return pkt;
|
|
70101
|
+
}
|
|
70102
|
+
if ( at + __len > n ) {
|
|
70103
|
+
pkt.ok = false;
|
|
70104
|
+
pkt.err = "truncated pkt-line body";
|
|
70105
|
+
return pkt;
|
|
70106
|
+
}
|
|
70107
|
+
const body = GitSha1.copyRange(
|
|
70108
|
+
data,
|
|
70109
|
+
(at + 4),
|
|
70110
|
+
(__len - 4)
|
|
70111
|
+
);
|
|
70112
|
+
pkt.raw.push(body);
|
|
70113
|
+
pkt.lines.push(GitSha1.ascii(
|
|
70114
|
+
body,
|
|
70115
|
+
0,
|
|
70116
|
+
body.byteLength
|
|
70117
|
+
));
|
|
70118
|
+
pkt.isFlush.push(false);
|
|
70119
|
+
at = at + __len;
|
|
70120
|
+
}
|
|
70121
|
+
}
|
|
70122
|
+
};
|
|
70123
|
+
return pkt;
|
|
70124
|
+
};
|
|
70125
|
+
GitPktIO.parseAdvertisement = function(data) {
|
|
70126
|
+
const adv = new GitAdvertisement();
|
|
70127
|
+
const pkt = GitPktIO.parse(data);
|
|
70128
|
+
if ( pkt.ok == false ) {
|
|
70129
|
+
adv.ok = false;
|
|
70130
|
+
adv.err = pkt.err;
|
|
70131
|
+
return adv;
|
|
70132
|
+
}
|
|
70133
|
+
let i = 0;
|
|
70134
|
+
const n = pkt.lines.length;
|
|
70135
|
+
while (i < n) {
|
|
70136
|
+
const line = pkt.lines[i];
|
|
70137
|
+
const flush = pkt.isFlush[i];
|
|
70138
|
+
if ( flush ) {
|
|
70139
|
+
i = i + 1;
|
|
70140
|
+
} else {
|
|
70141
|
+
if ( line.length > 10 ) {
|
|
70142
|
+
if ( line.substring(0, 10 ) == "# service=" ) {
|
|
70143
|
+
adv.service = GitPktIO.trimNl(line.substring(10, line.length ));
|
|
70144
|
+
}
|
|
70145
|
+
}
|
|
70146
|
+
if ( line.length >= 41 ) {
|
|
70147
|
+
const sha = line.substring(0, 40 );
|
|
70148
|
+
const rest = line.substring(41, line.length );
|
|
70149
|
+
const nulAt = GitPktIO.indexOfChar(rest, 0);
|
|
70150
|
+
let namePart = rest;
|
|
70151
|
+
if ( nulAt >= 0 ) {
|
|
70152
|
+
namePart = rest.substring(0, nulAt );
|
|
70153
|
+
adv.caps = rest.substring((nulAt + 1), rest.length );
|
|
70154
|
+
}
|
|
70155
|
+
let name = GitPktIO.trimNl(namePart);
|
|
70156
|
+
if ( name == "HEAD" ) {
|
|
70157
|
+
adv.head = sha;
|
|
70158
|
+
}
|
|
70159
|
+
let peeled = false;
|
|
70160
|
+
if ( name.length > 3 ) {
|
|
70161
|
+
const tail = name.substring((name.length - 3), name.length );
|
|
70162
|
+
if ( tail == "^{}" ) {
|
|
70163
|
+
peeled = true;
|
|
70164
|
+
name = name.substring(0, (name.length - 3) );
|
|
70165
|
+
}
|
|
70166
|
+
}
|
|
70167
|
+
if ( peeled ) {
|
|
70168
|
+
let r = 0;
|
|
70169
|
+
while (r < adv.refs.length) {
|
|
70170
|
+
const existing = adv.refs[r];
|
|
70171
|
+
if ( existing.name == name ) {
|
|
70172
|
+
existing.peeled = sha;
|
|
70173
|
+
}
|
|
70174
|
+
r = r + 1;
|
|
70175
|
+
};
|
|
70176
|
+
} else {
|
|
70177
|
+
const ref = new GitRef();
|
|
70178
|
+
ref.name = name;
|
|
70179
|
+
ref.sha = sha;
|
|
70180
|
+
adv.refs.push(ref);
|
|
70181
|
+
}
|
|
70182
|
+
if ( adv.head.length == 0 ) {
|
|
70183
|
+
if ( name == "refs/heads/master" ) {
|
|
70184
|
+
adv.head = sha;
|
|
70185
|
+
}
|
|
70186
|
+
if ( name == "refs/heads/main" ) {
|
|
70187
|
+
if ( adv.head.length == 0 ) {
|
|
70188
|
+
adv.head = sha;
|
|
70189
|
+
}
|
|
70190
|
+
}
|
|
70191
|
+
}
|
|
70192
|
+
}
|
|
70193
|
+
i = i + 1;
|
|
70194
|
+
}
|
|
70195
|
+
};
|
|
70196
|
+
return adv;
|
|
70197
|
+
};
|
|
70198
|
+
GitPktIO.findRef = function(adv, spec) {
|
|
70199
|
+
if ( spec.length == 40 ) {
|
|
70200
|
+
return spec;
|
|
70201
|
+
}
|
|
70202
|
+
if ( spec.length == 0 ) {
|
|
70203
|
+
return adv.head;
|
|
70204
|
+
}
|
|
70205
|
+
if ( spec == "HEAD" ) {
|
|
70206
|
+
return adv.head;
|
|
70207
|
+
}
|
|
70208
|
+
let i = 0;
|
|
70209
|
+
while (i < adv.refs.length) {
|
|
70210
|
+
const r = adv.refs[i];
|
|
70211
|
+
if ( r.name == spec ) {
|
|
70212
|
+
if ( r.peeled.length == 40 ) {
|
|
70213
|
+
return r.peeled;
|
|
70214
|
+
}
|
|
70215
|
+
return r.sha;
|
|
70216
|
+
}
|
|
70217
|
+
if ( r.name == "refs/heads/" + spec ) {
|
|
70218
|
+
return r.sha;
|
|
70219
|
+
}
|
|
70220
|
+
if ( r.name == "refs/tags/" + spec ) {
|
|
70221
|
+
if ( r.peeled.length == 40 ) {
|
|
70222
|
+
return r.peeled;
|
|
70223
|
+
}
|
|
70224
|
+
return r.sha;
|
|
70225
|
+
}
|
|
70226
|
+
i = i + 1;
|
|
70227
|
+
};
|
|
70228
|
+
return "";
|
|
70229
|
+
};
|
|
70230
|
+
GitPktIO.hasToken = function(caps, name) {
|
|
70231
|
+
const n = caps.length;
|
|
70232
|
+
const m = name.length;
|
|
70233
|
+
if ( m == 0 ) {
|
|
70234
|
+
return false;
|
|
70235
|
+
}
|
|
70236
|
+
let i = 0;
|
|
70237
|
+
while (i <= n - m) {
|
|
70238
|
+
if ( caps.substring(i, (i + m) ) == name ) {
|
|
70239
|
+
let left = false;
|
|
70240
|
+
if ( i == 0 ) {
|
|
70241
|
+
left = true;
|
|
70242
|
+
} else {
|
|
70243
|
+
const lc = caps.charCodeAt((i - 1) );
|
|
70244
|
+
if ( (lc == 32 || lc == 10) || lc == 0 ) {
|
|
70245
|
+
left = true;
|
|
70246
|
+
}
|
|
70247
|
+
}
|
|
70248
|
+
let right = false;
|
|
70249
|
+
if ( i + m == n ) {
|
|
70250
|
+
right = true;
|
|
70251
|
+
} else {
|
|
70252
|
+
const rc = caps.charCodeAt((i + m) );
|
|
70253
|
+
if ( ((rc == 32 || rc == 10) || rc == 0) || rc == 61 ) {
|
|
70254
|
+
right = true;
|
|
70255
|
+
}
|
|
70256
|
+
}
|
|
70257
|
+
if ( left && right ) {
|
|
70258
|
+
return true;
|
|
70259
|
+
}
|
|
70260
|
+
}
|
|
70261
|
+
i = i + 1;
|
|
70262
|
+
};
|
|
70263
|
+
return false;
|
|
70264
|
+
};
|
|
70265
|
+
GitPktIO.joinBuf = function(parts) {
|
|
70266
|
+
let total = 0;
|
|
70267
|
+
let i = 0;
|
|
70268
|
+
while (i < parts.length) {
|
|
70269
|
+
total = total + parts[i].byteLength;
|
|
70270
|
+
i = i + 1;
|
|
70271
|
+
};
|
|
70272
|
+
let out = (function(){ var b = new ArrayBuffer(total); b._view = new DataView(b); return b; })();
|
|
70273
|
+
let at = 0;
|
|
70274
|
+
i = 0;
|
|
70275
|
+
while (i < parts.length) {
|
|
70276
|
+
const p = parts[i];
|
|
70277
|
+
const pn = p.byteLength;
|
|
70278
|
+
(function(
|
|
70279
|
+
d,
|
|
70280
|
+
dOff,
|
|
70281
|
+
s,
|
|
70282
|
+
sOff,
|
|
70283
|
+
len
|
|
70284
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(out,at,p,0,pn);
|
|
70285
|
+
at = at + pn;
|
|
70286
|
+
i = i + 1;
|
|
70287
|
+
};
|
|
70288
|
+
return out;
|
|
70289
|
+
};
|
|
70290
|
+
GitPktIO.encodeDelim = function() {
|
|
70291
|
+
let raw = (function(){ var b = new ArrayBuffer(4); b._view = new DataView(b); return b; })();
|
|
70292
|
+
raw._view.setUint8(0, 48);
|
|
70293
|
+
raw._view.setUint8(1, 48);
|
|
70294
|
+
raw._view.setUint8(2, 48);
|
|
70295
|
+
raw._view.setUint8(3, 49);
|
|
70296
|
+
return raw;
|
|
70297
|
+
};
|
|
70298
|
+
GitPktIO.buildWant = function(adv, spec) {
|
|
70299
|
+
const w = new GitWant();
|
|
70300
|
+
const sha = GitPktIO.findRef(adv, spec);
|
|
70301
|
+
if ( sha.length != 40 ) {
|
|
70302
|
+
w.ok = false;
|
|
70303
|
+
w.err = "unknown rev: " + spec;
|
|
70304
|
+
return w;
|
|
70305
|
+
}
|
|
70306
|
+
let extras = [];
|
|
70307
|
+
return GitPktIO.buildWantFetch(sha, 0, "", extras);
|
|
70308
|
+
};
|
|
70309
|
+
GitPktIO.buildWantFetch = function(sha, deepen, filter, extras) {
|
|
70310
|
+
const w = new GitWant();
|
|
70311
|
+
if ( sha.length != 40 ) {
|
|
70312
|
+
w.ok = false;
|
|
70313
|
+
w.err = "want needs a 40-char sha";
|
|
70314
|
+
return w;
|
|
70315
|
+
}
|
|
70316
|
+
w.sha = sha;
|
|
70317
|
+
let caps = "multi_ack_detailed no-done side-band-64k ofs-delta agent=ranger-pkg/0.1";
|
|
70318
|
+
if ( deepen > 0 ) {
|
|
70319
|
+
caps = caps + " shallow";
|
|
70320
|
+
}
|
|
70321
|
+
if ( filter.length > 0 ) {
|
|
70322
|
+
caps = caps + " filter";
|
|
70323
|
+
}
|
|
70324
|
+
let parts = [];
|
|
70325
|
+
parts.push(GitPktIO.encodeLine((((("want " + sha) + " ") + caps) + "\n")));
|
|
70326
|
+
let i = 0;
|
|
70327
|
+
while (i < extras.length) {
|
|
70328
|
+
parts.push(GitPktIO.encodeLine((("want " + extras[i]) + "\n")));
|
|
70329
|
+
i = i + 1;
|
|
70330
|
+
};
|
|
70331
|
+
if ( deepen > 0 ) {
|
|
70332
|
+
parts.push(GitPktIO.encodeLine((("deepen " + (deepen.toString())) + "\n")));
|
|
70333
|
+
}
|
|
70334
|
+
if ( filter.length > 0 ) {
|
|
70335
|
+
parts.push(GitPktIO.encodeLine((("filter " + filter) + "\n")));
|
|
70336
|
+
}
|
|
70337
|
+
parts.push(GitPktIO.encodeFlush());
|
|
70338
|
+
parts.push(GitPktIO.encodeLine("done\n"));
|
|
70339
|
+
w.body = GitPktIO.joinBuf(parts);
|
|
70340
|
+
return w;
|
|
70341
|
+
};
|
|
70342
|
+
GitPktIO.buildWantTrees = function(adv, spec) {
|
|
70343
|
+
const w = new GitWant();
|
|
70344
|
+
const sha = GitPktIO.findRef(adv, spec);
|
|
70345
|
+
if ( sha.length != 40 ) {
|
|
70346
|
+
w.ok = false;
|
|
70347
|
+
w.err = "unknown rev: " + spec;
|
|
70348
|
+
return w;
|
|
70349
|
+
}
|
|
70350
|
+
let extras = [];
|
|
70351
|
+
let filter = "";
|
|
70352
|
+
if ( GitPktIO.hasToken(adv.caps, "filter") ) {
|
|
70353
|
+
filter = "blob:none";
|
|
70354
|
+
}
|
|
70355
|
+
return GitPktIO.buildWantFetch(
|
|
70356
|
+
sha,
|
|
70357
|
+
1,
|
|
70358
|
+
filter,
|
|
70359
|
+
extras
|
|
70360
|
+
);
|
|
70361
|
+
};
|
|
70362
|
+
GitPktIO.buildWantSha = function(sha) {
|
|
70363
|
+
let extras = [];
|
|
70364
|
+
return GitPktIO.buildWantFetch(sha, 0, "", extras);
|
|
70365
|
+
};
|
|
70366
|
+
GitPktIO.buildFetchV2 = function(sha, deepen, filter) {
|
|
70367
|
+
const w = new GitWant();
|
|
70368
|
+
if ( sha.length != 40 ) {
|
|
70369
|
+
w.ok = false;
|
|
70370
|
+
w.err = "want needs a 40-char sha";
|
|
70371
|
+
return w;
|
|
70372
|
+
}
|
|
70373
|
+
w.sha = sha;
|
|
70374
|
+
let parts = [];
|
|
70375
|
+
parts.push(GitPktIO.encodeLine("command=fetch"));
|
|
70376
|
+
parts.push(GitPktIO.encodeDelim());
|
|
70377
|
+
parts.push(GitPktIO.encodeLine(("want " + sha)));
|
|
70378
|
+
if ( deepen > 0 ) {
|
|
70379
|
+
parts.push(GitPktIO.encodeLine(("deepen " + (deepen.toString()))));
|
|
70380
|
+
}
|
|
70381
|
+
if ( filter.length > 0 ) {
|
|
70382
|
+
parts.push(GitPktIO.encodeLine(("filter " + filter)));
|
|
70383
|
+
}
|
|
70384
|
+
parts.push(GitPktIO.encodeLine("done"));
|
|
70385
|
+
parts.push(GitPktIO.encodeFlush());
|
|
70386
|
+
w.body = GitPktIO.joinBuf(parts);
|
|
70387
|
+
return w;
|
|
70388
|
+
};
|
|
70389
|
+
GitPktIO.demux = function(data) {
|
|
70390
|
+
const sb = new GitSideband();
|
|
70391
|
+
const n = data.byteLength;
|
|
70392
|
+
const mag = GitPktIO.indexOfPack(data);
|
|
70393
|
+
const pkt = GitPktIO.parse(data);
|
|
70394
|
+
if ( pkt.ok == false ) {
|
|
70395
|
+
if ( mag >= 0 ) {
|
|
70396
|
+
sb.pack = GitSha1.copyRange(data, mag, (n - mag));
|
|
70397
|
+
return sb;
|
|
70398
|
+
}
|
|
70399
|
+
sb.ok = false;
|
|
70400
|
+
sb.err = pkt.err;
|
|
70401
|
+
return sb;
|
|
70402
|
+
}
|
|
70403
|
+
let chunks = [];
|
|
70404
|
+
let total = 0;
|
|
70405
|
+
let i = 0;
|
|
70406
|
+
while (i < pkt.raw.length) {
|
|
70407
|
+
if ( pkt.isFlush[i] == false ) {
|
|
70408
|
+
const body = pkt.raw[i];
|
|
70409
|
+
if ( body.byteLength > 0 ) {
|
|
70410
|
+
const ch = body._view.getUint8(0);
|
|
70411
|
+
if ( ch == 1 ) {
|
|
70412
|
+
const piece = GitSha1.copyRange(
|
|
70413
|
+
body,
|
|
70414
|
+
1,
|
|
70415
|
+
(body.byteLength - 1)
|
|
70416
|
+
);
|
|
70417
|
+
chunks.push(piece);
|
|
70418
|
+
total = total + piece.byteLength;
|
|
70419
|
+
}
|
|
70420
|
+
if ( ch == 2 ) {
|
|
70421
|
+
sb.progress = sb.progress + GitSha1.ascii(
|
|
70422
|
+
body,
|
|
70423
|
+
1,
|
|
70424
|
+
(body.byteLength - 1)
|
|
70425
|
+
);
|
|
70426
|
+
}
|
|
70427
|
+
if ( ch == 3 ) {
|
|
70428
|
+
sb.ok = false;
|
|
70429
|
+
sb.err = GitSha1.ascii(
|
|
70430
|
+
body,
|
|
70431
|
+
1,
|
|
70432
|
+
(body.byteLength - 1)
|
|
70433
|
+
);
|
|
70434
|
+
}
|
|
70435
|
+
}
|
|
70436
|
+
}
|
|
70437
|
+
i = i + 1;
|
|
70438
|
+
};
|
|
70439
|
+
if ( chunks.length == 0 ) {
|
|
70440
|
+
if ( mag >= 0 ) {
|
|
70441
|
+
sb.pack = GitSha1.copyRange(data, mag, (n - mag));
|
|
70442
|
+
return sb;
|
|
70443
|
+
}
|
|
70444
|
+
sb.ok = false;
|
|
70445
|
+
sb.err = "no pack data in response";
|
|
70446
|
+
return sb;
|
|
70447
|
+
}
|
|
70448
|
+
let pack = (function(){ var b = new ArrayBuffer(total); b._view = new DataView(b); return b; })();
|
|
70449
|
+
let at = 0;
|
|
70450
|
+
i = 0;
|
|
70451
|
+
while (i < chunks.length) {
|
|
70452
|
+
const piece2 = chunks[i];
|
|
70453
|
+
const pn = piece2.byteLength;
|
|
70454
|
+
(function(
|
|
70455
|
+
d,
|
|
70456
|
+
dOff,
|
|
70457
|
+
s,
|
|
70458
|
+
sOff,
|
|
70459
|
+
len
|
|
70460
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(pack,at,piece2,0,pn);
|
|
70461
|
+
at = at + pn;
|
|
70462
|
+
i = i + 1;
|
|
70463
|
+
};
|
|
70464
|
+
sb.pack = pack;
|
|
70465
|
+
return sb;
|
|
70466
|
+
};
|
|
70467
|
+
GitPktIO.indexOfPack = function(data) {
|
|
70468
|
+
const n = data.byteLength;
|
|
70469
|
+
let i = 0;
|
|
70470
|
+
while (i < n - 3) {
|
|
70471
|
+
if ( data._view.getUint8(i) == 80 ) {
|
|
70472
|
+
if ( data._view.getUint8((i + 1)) == 65 ) {
|
|
70473
|
+
if ( data._view.getUint8((i + 2)) == 67 ) {
|
|
70474
|
+
if ( data._view.getUint8((i + 3)) == 75 ) {
|
|
70475
|
+
return i;
|
|
70476
|
+
}
|
|
70477
|
+
}
|
|
70478
|
+
}
|
|
70479
|
+
}
|
|
70480
|
+
i = i + 1;
|
|
70481
|
+
};
|
|
70482
|
+
return 0 - 1;
|
|
70483
|
+
};
|
|
70484
|
+
GitPktIO.indexOfChar = function(s, code) {
|
|
70485
|
+
const n = s.length;
|
|
70486
|
+
let i = 0;
|
|
70487
|
+
while (i < n) {
|
|
70488
|
+
if ( s.charCodeAt(i ) == code ) {
|
|
70489
|
+
return i;
|
|
70490
|
+
}
|
|
70491
|
+
i = i + 1;
|
|
70492
|
+
};
|
|
70493
|
+
return 0 - 1;
|
|
70494
|
+
};
|
|
70495
|
+
GitPktIO.trimNl = function(s) {
|
|
70496
|
+
let n = s.length;
|
|
70497
|
+
while (n > 0) {
|
|
70498
|
+
const c = s.charCodeAt((n - 1) );
|
|
70499
|
+
if ( c == 10 ) {
|
|
70500
|
+
n = n - 1;
|
|
70501
|
+
} else {
|
|
70502
|
+
if ( c == 13 ) {
|
|
70503
|
+
n = n - 1;
|
|
70504
|
+
} else {
|
|
70505
|
+
if ( c == 0 ) {
|
|
70506
|
+
n = n - 1;
|
|
70507
|
+
} else {
|
|
70508
|
+
return s.substring(0, n );
|
|
70509
|
+
}
|
|
70510
|
+
}
|
|
70511
|
+
}
|
|
70512
|
+
};
|
|
70513
|
+
return "";
|
|
70514
|
+
};
|
|
70515
|
+
class ZipBuffer {
|
|
70516
|
+
constructor() {
|
|
70517
|
+
this.data = (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
70518
|
+
this.pos = 0;
|
|
70519
|
+
this.length = 0;
|
|
70520
|
+
}
|
|
70521
|
+
initWithBuffer (buf) {
|
|
70522
|
+
this.data = buf;
|
|
70523
|
+
this.length = buf.byteLength;
|
|
70524
|
+
this.pos = 0;
|
|
70525
|
+
};
|
|
70526
|
+
initWithSize (size) {
|
|
70527
|
+
this.data = (function(){ var b = new ArrayBuffer(size); b._view = new DataView(b); return b; })();
|
|
70528
|
+
this.length = size;
|
|
70529
|
+
this.pos = 0;
|
|
70530
|
+
};
|
|
70531
|
+
getPosition () {
|
|
70532
|
+
return this.pos;
|
|
70533
|
+
};
|
|
70534
|
+
setPosition (newPos) {
|
|
70535
|
+
this.pos = newPos;
|
|
70536
|
+
};
|
|
70537
|
+
seek (offset) {
|
|
70538
|
+
this.pos = offset;
|
|
70539
|
+
};
|
|
70540
|
+
skip (count) {
|
|
70541
|
+
this.pos = this.pos + count;
|
|
70542
|
+
};
|
|
70543
|
+
remaining () {
|
|
70544
|
+
return this.length - this.pos;
|
|
70545
|
+
};
|
|
70546
|
+
isEOF () {
|
|
70547
|
+
return this.pos >= this.length;
|
|
70548
|
+
};
|
|
70549
|
+
readUint8 () {
|
|
70550
|
+
if ( this.pos >= this.length ) {
|
|
70551
|
+
return 0;
|
|
70552
|
+
}
|
|
70553
|
+
const value = this.data._view.getUint8(this.pos);
|
|
70554
|
+
this.pos = this.pos + 1;
|
|
70555
|
+
return value;
|
|
70556
|
+
};
|
|
70557
|
+
readUint16LE () {
|
|
70558
|
+
const b0 = this.readUint8();
|
|
70559
|
+
const b1 = this.readUint8();
|
|
70560
|
+
return b0 + b1 * 256;
|
|
70561
|
+
};
|
|
70562
|
+
readUint32LE () {
|
|
70563
|
+
const b0 = this.readUint8();
|
|
70564
|
+
const b1 = this.readUint8();
|
|
70565
|
+
const b2 = this.readUint8();
|
|
70566
|
+
const b3 = this.readUint8();
|
|
70567
|
+
return ((b0 + b1 * 256) + b2 * 65536) + b3 * 16777216;
|
|
70568
|
+
};
|
|
70569
|
+
readBytes (count) {
|
|
70570
|
+
let result = (function(){ var b = new ArrayBuffer(count); b._view = new DataView(b); return b; })();
|
|
70571
|
+
let i = 0;
|
|
70572
|
+
while (i < count) {
|
|
70573
|
+
if ( this.pos < this.length ) {
|
|
70574
|
+
const b = this.data._view.getUint8(this.pos);
|
|
70575
|
+
result._view.setUint8(i, b);
|
|
70576
|
+
this.pos = this.pos + 1;
|
|
70577
|
+
}
|
|
70578
|
+
i = i + 1;
|
|
70579
|
+
};
|
|
70580
|
+
return result;
|
|
70581
|
+
};
|
|
70582
|
+
readString (count) {
|
|
70583
|
+
let result = "";
|
|
70584
|
+
let i = 0;
|
|
70585
|
+
while (i < count) {
|
|
70586
|
+
if ( this.pos < this.length ) {
|
|
70587
|
+
const ch = this.data._view.getUint8(this.pos);
|
|
70588
|
+
result = result + String.fromCharCode(ch);
|
|
70589
|
+
this.pos = this.pos + 1;
|
|
70590
|
+
}
|
|
70591
|
+
i = i + 1;
|
|
70592
|
+
};
|
|
70593
|
+
return result;
|
|
70594
|
+
};
|
|
70595
|
+
peekUint8 () {
|
|
70596
|
+
if ( this.pos >= this.length ) {
|
|
70597
|
+
return 0;
|
|
70598
|
+
}
|
|
70599
|
+
return this.data._view.getUint8(this.pos);
|
|
70600
|
+
};
|
|
70601
|
+
peekUint32LE () {
|
|
70602
|
+
const savedPos = this.pos;
|
|
70603
|
+
const value = this.readUint32LE();
|
|
70604
|
+
this.pos = savedPos;
|
|
70605
|
+
return value;
|
|
70606
|
+
};
|
|
70607
|
+
writeUint8 (value) {
|
|
70608
|
+
if ( this.pos < this.length ) {
|
|
70609
|
+
this.data._view.setUint8(this.pos, value);
|
|
70610
|
+
this.pos = this.pos + 1;
|
|
70611
|
+
}
|
|
70612
|
+
};
|
|
70613
|
+
writeUint16LE (value) {
|
|
70614
|
+
const b0 = (value & 255);
|
|
70615
|
+
const b1 = ((value >>> 8) & 255);
|
|
70616
|
+
this.writeUint8(b0);
|
|
70617
|
+
this.writeUint8(b1);
|
|
70618
|
+
};
|
|
70619
|
+
writeUint32LE (value) {
|
|
70620
|
+
const b0 = (value & 255);
|
|
70621
|
+
const b1 = ((value >>> 8) & 255);
|
|
70622
|
+
const b2 = ((value >>> 16) & 255);
|
|
70623
|
+
const b3 = ((value >>> 24) & 255);
|
|
70624
|
+
this.writeUint8(b0);
|
|
70625
|
+
this.writeUint8(b1);
|
|
70626
|
+
this.writeUint8(b2);
|
|
70627
|
+
this.writeUint8(b3);
|
|
70628
|
+
};
|
|
70629
|
+
writeBytes (src, srcOffset, count) {
|
|
70630
|
+
let i = 0;
|
|
70631
|
+
while (i < count) {
|
|
70632
|
+
const b = src._view.getUint8((srcOffset + i));
|
|
70633
|
+
this.writeUint8(b);
|
|
70634
|
+
i = i + 1;
|
|
70635
|
+
};
|
|
70636
|
+
};
|
|
70637
|
+
writeBuffer (src) {
|
|
70638
|
+
const __len = src.byteLength;
|
|
70639
|
+
this.writeBytes(src, 0, __len);
|
|
70640
|
+
};
|
|
70641
|
+
writeString (s) {
|
|
70642
|
+
const __len = s.length;
|
|
70643
|
+
let i = 0;
|
|
70644
|
+
while (i < __len) {
|
|
70645
|
+
const ch = s.charCodeAt(i );
|
|
70646
|
+
this.writeUint8(ch);
|
|
70647
|
+
i = i + 1;
|
|
70648
|
+
};
|
|
70649
|
+
};
|
|
70650
|
+
getBuffer () {
|
|
70651
|
+
return this.data;
|
|
70652
|
+
};
|
|
70653
|
+
getLength () {
|
|
70654
|
+
return this.length;
|
|
70655
|
+
};
|
|
70656
|
+
findSignatureBackward (sig, startPos) {
|
|
70657
|
+
let searchPos = startPos;
|
|
70658
|
+
while (searchPos >= 0) {
|
|
70659
|
+
const savedPos = this.pos;
|
|
70660
|
+
this.pos = searchPos;
|
|
70661
|
+
const value = this.readUint32LE();
|
|
70662
|
+
this.pos = savedPos;
|
|
70663
|
+
if ( value == sig ) {
|
|
70664
|
+
return searchPos;
|
|
70665
|
+
}
|
|
70666
|
+
searchPos = searchPos - 1;
|
|
70667
|
+
};
|
|
70668
|
+
return -1;
|
|
70669
|
+
};
|
|
70670
|
+
}
|
|
70671
|
+
class GrowableZipBuffer {
|
|
70672
|
+
constructor() {
|
|
70673
|
+
this.chunks = [];
|
|
70674
|
+
this.chunkLens = [];
|
|
70675
|
+
this.chunkSize = 65536;
|
|
70676
|
+
this.currentChunk = (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
70677
|
+
this.currentPos = 0;
|
|
70678
|
+
this.totalSize = 0;
|
|
70679
|
+
this.currentPos = 0;
|
|
70680
|
+
this.totalSize = 0;
|
|
70681
|
+
const initSize = this.chunkSize;
|
|
70682
|
+
this.currentChunk = (function(){ var b = new ArrayBuffer(initSize); b._view = new DataView(b); return b; })();
|
|
70683
|
+
}
|
|
70684
|
+
setChunkSize (size) {
|
|
70685
|
+
if ( size < 1 ) {
|
|
70686
|
+
return;
|
|
70687
|
+
}
|
|
70688
|
+
if ( this.totalSize > 0 ) {
|
|
70689
|
+
return;
|
|
70690
|
+
}
|
|
70691
|
+
this.chunkSize = size;
|
|
70692
|
+
this.currentChunk = (function(){ var b = new ArrayBuffer(size); b._view = new DataView(b); return b; })();
|
|
70693
|
+
this.currentPos = 0;
|
|
70694
|
+
};
|
|
70695
|
+
allocateNewChunk () {
|
|
70696
|
+
this.chunks.push(this.currentChunk);
|
|
70697
|
+
this.chunkLens.push(this.currentPos);
|
|
70698
|
+
const size = this.chunkSize;
|
|
70699
|
+
this.currentChunk = (function(){ var b = new ArrayBuffer(size); b._view = new DataView(b); return b; })();
|
|
70700
|
+
this.currentPos = 0;
|
|
70701
|
+
};
|
|
70702
|
+
writeUint8 (value) {
|
|
70703
|
+
if ( this.currentPos >= this.chunkSize ) {
|
|
70704
|
+
this.allocateNewChunk();
|
|
70705
|
+
}
|
|
70706
|
+
this.currentChunk._view.setUint8(this.currentPos, value);
|
|
70707
|
+
this.currentPos = this.currentPos + 1;
|
|
70708
|
+
this.totalSize = this.totalSize + 1;
|
|
70709
|
+
};
|
|
70710
|
+
writeUint16LE (value) {
|
|
70711
|
+
const b0 = value % 256;
|
|
70712
|
+
const b1D = value / 256.0;
|
|
70713
|
+
const b1 = Math.floor( b1D) % 256;
|
|
70714
|
+
this.writeUint8(b0);
|
|
70715
|
+
this.writeUint8(b1);
|
|
70716
|
+
};
|
|
70717
|
+
writeUint32LE (value) {
|
|
70718
|
+
const b0 = value % 256;
|
|
70719
|
+
const rem1D = value / 256.0;
|
|
70720
|
+
const rem1 = Math.floor( rem1D);
|
|
70721
|
+
const b1 = rem1 % 256;
|
|
70722
|
+
const rem2D = rem1 / 256.0;
|
|
70723
|
+
const rem2 = Math.floor( rem2D);
|
|
70724
|
+
const b2 = rem2 % 256;
|
|
70725
|
+
const rem3D = rem2 / 256.0;
|
|
70726
|
+
const b3 = Math.floor( rem3D);
|
|
70727
|
+
this.writeUint8(b0);
|
|
70728
|
+
this.writeUint8(b1);
|
|
70729
|
+
this.writeUint8(b2);
|
|
70730
|
+
this.writeUint8(b3);
|
|
70731
|
+
};
|
|
70732
|
+
writeBytes (src, srcOffset, count) {
|
|
70733
|
+
let left = count;
|
|
70734
|
+
let at = srcOffset;
|
|
70735
|
+
while (left > 0) {
|
|
70736
|
+
if ( this.currentPos >= this.chunkSize ) {
|
|
70737
|
+
this.allocateNewChunk();
|
|
70738
|
+
}
|
|
70739
|
+
const room = this.chunkSize - this.currentPos;
|
|
70740
|
+
let take = left;
|
|
70741
|
+
if ( take > room ) {
|
|
70742
|
+
take = room;
|
|
70743
|
+
}
|
|
70744
|
+
(function(
|
|
70745
|
+
d,
|
|
70746
|
+
dOff,
|
|
70747
|
+
s,
|
|
70748
|
+
sOff,
|
|
70749
|
+
len
|
|
70750
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(this.currentChunk,this.currentPos,src,at,take);
|
|
70751
|
+
this.currentPos = this.currentPos + take;
|
|
70752
|
+
this.totalSize = this.totalSize + take;
|
|
70753
|
+
at = at + take;
|
|
70754
|
+
left = left - take;
|
|
70755
|
+
};
|
|
70756
|
+
};
|
|
70757
|
+
writeBuffer (src) {
|
|
70758
|
+
const __len = src.byteLength;
|
|
70759
|
+
this.writeBytes(src, 0, __len);
|
|
70760
|
+
};
|
|
70761
|
+
writeString (s) {
|
|
70762
|
+
const __len = s.length;
|
|
70763
|
+
let i = 0;
|
|
70764
|
+
while (i < __len) {
|
|
70765
|
+
const ch = s.charCodeAt(i );
|
|
70766
|
+
this.writeUint8(ch);
|
|
70767
|
+
i = i + 1;
|
|
70768
|
+
};
|
|
70769
|
+
};
|
|
70770
|
+
getSize () {
|
|
70771
|
+
return this.totalSize;
|
|
70772
|
+
};
|
|
70773
|
+
toBuffer () {
|
|
70774
|
+
const size = this.totalSize;
|
|
70775
|
+
let result = (function(){ var b = new ArrayBuffer(size); b._view = new DataView(b); return b; })();
|
|
70776
|
+
let destPos = 0;
|
|
70777
|
+
const numChunks = this.chunks.length;
|
|
70778
|
+
let i = 0;
|
|
70779
|
+
while (i < numChunks) {
|
|
70780
|
+
const chunk = this.chunks[i];
|
|
70781
|
+
const used = this.chunkLens[i];
|
|
70782
|
+
if ( used > 0 ) {
|
|
70783
|
+
(function(
|
|
70784
|
+
d,
|
|
70785
|
+
dOff,
|
|
70786
|
+
s,
|
|
70787
|
+
sOff,
|
|
70788
|
+
len
|
|
70789
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(result,destPos,chunk,0,used);
|
|
70790
|
+
destPos = destPos + used;
|
|
70791
|
+
}
|
|
70792
|
+
i = i + 1;
|
|
70793
|
+
};
|
|
70794
|
+
const curPos = this.currentPos;
|
|
70795
|
+
if ( curPos > 0 ) {
|
|
70796
|
+
const curChunk = this.currentChunk;
|
|
70797
|
+
(function(
|
|
70798
|
+
d,
|
|
70799
|
+
dOff,
|
|
70800
|
+
s,
|
|
70801
|
+
sOff,
|
|
70802
|
+
len
|
|
70803
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(result,destPos,curChunk,0,curPos);
|
|
70804
|
+
destPos = destPos + curPos;
|
|
70805
|
+
}
|
|
70806
|
+
return result;
|
|
70807
|
+
};
|
|
70808
|
+
}
|
|
70809
|
+
class InflateHuffmanTable {
|
|
70810
|
+
constructor() {
|
|
70811
|
+
this.counts = [];
|
|
70812
|
+
this.symbols = [];
|
|
70813
|
+
this.maxBits = 0;
|
|
70814
|
+
let i_28 = 0;
|
|
70815
|
+
while (i_28 < 16) {
|
|
70816
|
+
this.counts.push(0);
|
|
70817
|
+
i_28 = i_28 + 1;
|
|
70818
|
+
};
|
|
70819
|
+
}
|
|
70820
|
+
build (lengths, numSymbols) {
|
|
70821
|
+
let i = 0;
|
|
70822
|
+
while (i < 16) {
|
|
70823
|
+
this.counts[i] = 0;
|
|
70824
|
+
i = i + 1;
|
|
70825
|
+
};
|
|
70826
|
+
i = 0;
|
|
70827
|
+
while (i < numSymbols) {
|
|
70828
|
+
const __len = lengths[i];
|
|
70829
|
+
if ( __len > 0 ) {
|
|
70830
|
+
const cnt = this.counts[__len];
|
|
70831
|
+
this.counts[__len] = cnt + 1;
|
|
70832
|
+
if ( __len > this.maxBits ) {
|
|
70833
|
+
this.maxBits = __len;
|
|
70834
|
+
}
|
|
70835
|
+
}
|
|
70836
|
+
i = i + 1;
|
|
70837
|
+
};
|
|
70838
|
+
let offsets = [];
|
|
70839
|
+
let offset = 0;
|
|
70840
|
+
i = 0;
|
|
70841
|
+
while (i < 16) {
|
|
70842
|
+
offsets.push(offset);
|
|
70843
|
+
const cnt_1 = this.counts[i];
|
|
70844
|
+
offset = offset + cnt_1;
|
|
70845
|
+
i = i + 1;
|
|
70846
|
+
};
|
|
70847
|
+
i = 0;
|
|
70848
|
+
while (i < numSymbols) {
|
|
70849
|
+
this.symbols.push(0);
|
|
70850
|
+
i = i + 1;
|
|
70851
|
+
};
|
|
70852
|
+
i = 0;
|
|
70853
|
+
while (i < numSymbols) {
|
|
70854
|
+
const len_1 = lengths[i];
|
|
70855
|
+
if ( len_1 > 0 ) {
|
|
70856
|
+
const off = offsets[len_1];
|
|
70857
|
+
this.symbols[off] = i;
|
|
70858
|
+
offsets[len_1] = off + 1;
|
|
70859
|
+
}
|
|
70860
|
+
i = i + 1;
|
|
70861
|
+
};
|
|
70862
|
+
};
|
|
70863
|
+
decode (reader) {
|
|
70864
|
+
let code = 0;
|
|
70865
|
+
let first = 0;
|
|
70866
|
+
let index = 0;
|
|
70867
|
+
let __len = 1;
|
|
70868
|
+
while (__len <= this.maxBits) {
|
|
70869
|
+
const bit = reader.readBit();
|
|
70870
|
+
code = code * 2 + bit;
|
|
70871
|
+
const count = this.counts[__len];
|
|
70872
|
+
if ( code - first < count ) {
|
|
70873
|
+
return this.symbols[((index + code) - first)];
|
|
70874
|
+
}
|
|
70875
|
+
index = index + count;
|
|
70876
|
+
first = (first + count) * 2;
|
|
70877
|
+
__len = __len + 1;
|
|
70878
|
+
};
|
|
70879
|
+
return -1;
|
|
70880
|
+
};
|
|
70881
|
+
}
|
|
70882
|
+
class InflateBitReader {
|
|
70883
|
+
constructor() {
|
|
70884
|
+
this.data = (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
70885
|
+
this.bytePos = 0;
|
|
70886
|
+
this.bitPos = 0;
|
|
70887
|
+
this.currentByte = 0;
|
|
70888
|
+
this.dataLength = 0;
|
|
70889
|
+
}
|
|
70890
|
+
init (buf, offset, length) {
|
|
70891
|
+
this.data = buf;
|
|
70892
|
+
this.bytePos = offset;
|
|
70893
|
+
this.dataLength = offset + length;
|
|
70894
|
+
this.bitPos = 0;
|
|
70895
|
+
this.currentByte = 0;
|
|
70896
|
+
};
|
|
70897
|
+
readBit () {
|
|
70898
|
+
if ( this.bitPos == 0 ) {
|
|
70899
|
+
if ( this.bytePos >= this.dataLength ) {
|
|
70900
|
+
return 0;
|
|
70901
|
+
}
|
|
70902
|
+
this.currentByte = this.data._view.getUint8(this.bytePos);
|
|
70903
|
+
this.bytePos = this.bytePos + 1;
|
|
70904
|
+
this.bitPos = 8;
|
|
70905
|
+
}
|
|
70906
|
+
const bit = (this.currentByte & 1);
|
|
70907
|
+
this.currentByte = (this.currentByte >> 1);
|
|
70908
|
+
this.bitPos = this.bitPos - 1;
|
|
70909
|
+
return bit;
|
|
70910
|
+
};
|
|
70911
|
+
readBits (count) {
|
|
70912
|
+
let result = 0;
|
|
70913
|
+
let multiplier = 1;
|
|
70914
|
+
let i = 0;
|
|
70915
|
+
while (i < count) {
|
|
70916
|
+
const bit = this.readBit();
|
|
70917
|
+
result = result + bit * multiplier;
|
|
70918
|
+
multiplier = multiplier * 2;
|
|
70919
|
+
i = i + 1;
|
|
70920
|
+
};
|
|
70921
|
+
return result;
|
|
70922
|
+
};
|
|
70923
|
+
alignToByte () {
|
|
70924
|
+
this.bitPos = 0;
|
|
70925
|
+
};
|
|
70926
|
+
readByte () {
|
|
70927
|
+
this.alignToByte();
|
|
70928
|
+
if ( this.bytePos >= this.dataLength ) {
|
|
70929
|
+
return 0;
|
|
70930
|
+
}
|
|
70931
|
+
const b = this.data._view.getUint8(this.bytePos);
|
|
70932
|
+
this.bytePos = this.bytePos + 1;
|
|
70933
|
+
return b;
|
|
70934
|
+
};
|
|
70935
|
+
readUint16LE () {
|
|
70936
|
+
const b0 = this.readByte();
|
|
70937
|
+
const b1 = this.readByte();
|
|
70938
|
+
return b0 + b1 * 256;
|
|
70939
|
+
};
|
|
70940
|
+
getBytePosition () {
|
|
70941
|
+
return this.bytePos;
|
|
70942
|
+
};
|
|
70943
|
+
isEOF () {
|
|
70944
|
+
return this.bytePos >= this.dataLength && this.bitPos == 0;
|
|
70945
|
+
};
|
|
70946
|
+
}
|
|
70947
|
+
class Inflate {
|
|
70948
|
+
constructor() {
|
|
70949
|
+
this.input = (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
70950
|
+
this.reader = new InflateBitReader();
|
|
70951
|
+
this.outBuf = (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
70952
|
+
this.outLen = 0;
|
|
70953
|
+
this.outCap = 0;
|
|
70954
|
+
this.fixedLitLen = new InflateHuffmanTable();
|
|
70955
|
+
this.fixedDist = new InflateHuffmanTable();
|
|
70956
|
+
this.fixedTablesBuilt = false;
|
|
70957
|
+
this.lengthBase = [];
|
|
70958
|
+
this.lengthExtra = [];
|
|
70959
|
+
this.distBase = [];
|
|
70960
|
+
this.distExtra = [];
|
|
70961
|
+
this.buildLengthDistTables();
|
|
70962
|
+
}
|
|
70963
|
+
resetOutput (hint) {
|
|
70964
|
+
let cap = hint;
|
|
70965
|
+
if ( cap < 4096 ) {
|
|
70966
|
+
cap = 4096;
|
|
70967
|
+
}
|
|
70968
|
+
this.outBuf = (function(){ var b = new ArrayBuffer(cap); b._view = new DataView(b); return b; })();
|
|
70969
|
+
this.outCap = cap;
|
|
70970
|
+
this.outLen = 0;
|
|
70971
|
+
};
|
|
70972
|
+
ensureCapacity (extra) {
|
|
70973
|
+
const need = this.outLen + extra;
|
|
70974
|
+
if ( need <= this.outCap ) {
|
|
70975
|
+
return;
|
|
70976
|
+
}
|
|
70977
|
+
let newCap = this.outCap * 2;
|
|
70978
|
+
if ( newCap < need ) {
|
|
70979
|
+
newCap = need;
|
|
70980
|
+
}
|
|
70981
|
+
let grown = (function(){ var b = new ArrayBuffer(newCap); b._view = new DataView(b); return b; })();
|
|
70982
|
+
(function(
|
|
70983
|
+
d,
|
|
70984
|
+
dOff,
|
|
70985
|
+
s,
|
|
70986
|
+
sOff,
|
|
70987
|
+
len
|
|
70988
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(grown,0,this.outBuf,0,this.outLen);
|
|
70989
|
+
this.outBuf = grown;
|
|
70990
|
+
this.outCap = newCap;
|
|
70991
|
+
};
|
|
70992
|
+
pushByte (b) {
|
|
70993
|
+
this.ensureCapacity(1);
|
|
70994
|
+
this.outBuf._view.setUint8(this.outLen, b);
|
|
70995
|
+
this.outLen = this.outLen + 1;
|
|
70996
|
+
};
|
|
70997
|
+
finalOutput () {
|
|
70998
|
+
const size = this.outLen;
|
|
70999
|
+
let result = (function(){ var b = new ArrayBuffer(size); b._view = new DataView(b); return b; })();
|
|
71000
|
+
(function(
|
|
71001
|
+
d,
|
|
71002
|
+
dOff,
|
|
71003
|
+
s,
|
|
71004
|
+
sOff,
|
|
71005
|
+
len
|
|
71006
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(result,0,this.outBuf,0,size);
|
|
71007
|
+
return result;
|
|
71008
|
+
};
|
|
71009
|
+
buildLengthDistTables () {
|
|
71010
|
+
let bases = [];
|
|
71011
|
+
bases.push(3);
|
|
71012
|
+
bases.push(4);
|
|
71013
|
+
bases.push(5);
|
|
71014
|
+
bases.push(6);
|
|
71015
|
+
bases.push(7);
|
|
71016
|
+
bases.push(8);
|
|
71017
|
+
bases.push(9);
|
|
71018
|
+
bases.push(10);
|
|
71019
|
+
bases.push(11);
|
|
71020
|
+
bases.push(13);
|
|
71021
|
+
bases.push(15);
|
|
71022
|
+
bases.push(17);
|
|
71023
|
+
bases.push(19);
|
|
71024
|
+
bases.push(23);
|
|
71025
|
+
bases.push(27);
|
|
71026
|
+
bases.push(31);
|
|
71027
|
+
bases.push(35);
|
|
71028
|
+
bases.push(43);
|
|
71029
|
+
bases.push(51);
|
|
71030
|
+
bases.push(59);
|
|
71031
|
+
bases.push(67);
|
|
71032
|
+
bases.push(83);
|
|
71033
|
+
bases.push(99);
|
|
71034
|
+
bases.push(115);
|
|
71035
|
+
bases.push(131);
|
|
71036
|
+
bases.push(163);
|
|
71037
|
+
bases.push(195);
|
|
71038
|
+
bases.push(227);
|
|
71039
|
+
bases.push(258);
|
|
71040
|
+
this.lengthBase = bases;
|
|
71041
|
+
let extras = [];
|
|
71042
|
+
extras.push(0);
|
|
71043
|
+
extras.push(0);
|
|
71044
|
+
extras.push(0);
|
|
71045
|
+
extras.push(0);
|
|
71046
|
+
extras.push(0);
|
|
71047
|
+
extras.push(0);
|
|
71048
|
+
extras.push(0);
|
|
71049
|
+
extras.push(0);
|
|
71050
|
+
extras.push(1);
|
|
71051
|
+
extras.push(1);
|
|
71052
|
+
extras.push(1);
|
|
71053
|
+
extras.push(1);
|
|
71054
|
+
extras.push(2);
|
|
71055
|
+
extras.push(2);
|
|
71056
|
+
extras.push(2);
|
|
71057
|
+
extras.push(2);
|
|
71058
|
+
extras.push(3);
|
|
71059
|
+
extras.push(3);
|
|
71060
|
+
extras.push(3);
|
|
71061
|
+
extras.push(3);
|
|
71062
|
+
extras.push(4);
|
|
71063
|
+
extras.push(4);
|
|
71064
|
+
extras.push(4);
|
|
71065
|
+
extras.push(4);
|
|
71066
|
+
extras.push(5);
|
|
71067
|
+
extras.push(5);
|
|
71068
|
+
extras.push(5);
|
|
71069
|
+
extras.push(5);
|
|
71070
|
+
extras.push(0);
|
|
71071
|
+
this.lengthExtra = extras;
|
|
71072
|
+
let dBases = [];
|
|
71073
|
+
dBases.push(1);
|
|
71074
|
+
dBases.push(2);
|
|
71075
|
+
dBases.push(3);
|
|
71076
|
+
dBases.push(4);
|
|
71077
|
+
dBases.push(5);
|
|
71078
|
+
dBases.push(7);
|
|
71079
|
+
dBases.push(9);
|
|
71080
|
+
dBases.push(13);
|
|
71081
|
+
dBases.push(17);
|
|
71082
|
+
dBases.push(25);
|
|
71083
|
+
dBases.push(33);
|
|
71084
|
+
dBases.push(49);
|
|
71085
|
+
dBases.push(65);
|
|
71086
|
+
dBases.push(97);
|
|
71087
|
+
dBases.push(129);
|
|
71088
|
+
dBases.push(193);
|
|
71089
|
+
dBases.push(257);
|
|
71090
|
+
dBases.push(385);
|
|
71091
|
+
dBases.push(513);
|
|
71092
|
+
dBases.push(769);
|
|
71093
|
+
dBases.push(1025);
|
|
71094
|
+
dBases.push(1537);
|
|
71095
|
+
dBases.push(2049);
|
|
71096
|
+
dBases.push(3073);
|
|
71097
|
+
dBases.push(4097);
|
|
71098
|
+
dBases.push(6145);
|
|
71099
|
+
dBases.push(8193);
|
|
71100
|
+
dBases.push(12289);
|
|
71101
|
+
dBases.push(16385);
|
|
71102
|
+
dBases.push(24577);
|
|
71103
|
+
this.distBase = dBases;
|
|
71104
|
+
let dExtras = [];
|
|
71105
|
+
dExtras.push(0);
|
|
71106
|
+
dExtras.push(0);
|
|
71107
|
+
dExtras.push(0);
|
|
71108
|
+
dExtras.push(0);
|
|
71109
|
+
dExtras.push(1);
|
|
71110
|
+
dExtras.push(1);
|
|
71111
|
+
dExtras.push(2);
|
|
71112
|
+
dExtras.push(2);
|
|
71113
|
+
dExtras.push(3);
|
|
71114
|
+
dExtras.push(3);
|
|
71115
|
+
dExtras.push(4);
|
|
71116
|
+
dExtras.push(4);
|
|
71117
|
+
dExtras.push(5);
|
|
71118
|
+
dExtras.push(5);
|
|
71119
|
+
dExtras.push(6);
|
|
71120
|
+
dExtras.push(6);
|
|
71121
|
+
dExtras.push(7);
|
|
71122
|
+
dExtras.push(7);
|
|
71123
|
+
dExtras.push(8);
|
|
71124
|
+
dExtras.push(8);
|
|
71125
|
+
dExtras.push(9);
|
|
71126
|
+
dExtras.push(9);
|
|
71127
|
+
dExtras.push(10);
|
|
71128
|
+
dExtras.push(10);
|
|
71129
|
+
dExtras.push(11);
|
|
71130
|
+
dExtras.push(11);
|
|
71131
|
+
dExtras.push(12);
|
|
71132
|
+
dExtras.push(12);
|
|
71133
|
+
dExtras.push(13);
|
|
71134
|
+
dExtras.push(13);
|
|
71135
|
+
this.distExtra = dExtras;
|
|
71136
|
+
};
|
|
71137
|
+
buildFixedTables () {
|
|
71138
|
+
if ( this.fixedTablesBuilt ) {
|
|
71139
|
+
return;
|
|
71140
|
+
}
|
|
71141
|
+
let lengths = [];
|
|
71142
|
+
let i = 0;
|
|
71143
|
+
while (i < 144) {
|
|
71144
|
+
lengths.push(8);
|
|
71145
|
+
i = i + 1;
|
|
71146
|
+
};
|
|
71147
|
+
while (i < 256) {
|
|
71148
|
+
lengths.push(9);
|
|
71149
|
+
i = i + 1;
|
|
71150
|
+
};
|
|
71151
|
+
while (i < 280) {
|
|
71152
|
+
lengths.push(7);
|
|
71153
|
+
i = i + 1;
|
|
71154
|
+
};
|
|
71155
|
+
while (i < 288) {
|
|
71156
|
+
lengths.push(8);
|
|
71157
|
+
i = i + 1;
|
|
71158
|
+
};
|
|
71159
|
+
this.fixedLitLen.build(lengths, 288);
|
|
71160
|
+
let distLengths = [];
|
|
71161
|
+
i = 0;
|
|
71162
|
+
while (i < 32) {
|
|
71163
|
+
distLengths.push(5);
|
|
71164
|
+
i = i + 1;
|
|
71165
|
+
};
|
|
71166
|
+
this.fixedDist.build(distLengths, 32);
|
|
71167
|
+
this.fixedTablesBuilt = true;
|
|
71168
|
+
};
|
|
71169
|
+
decompress (data) {
|
|
71170
|
+
return this.decompressFrom(data, 0);
|
|
71171
|
+
};
|
|
71172
|
+
decompressFrom (data, offset) {
|
|
71173
|
+
this.input = data;
|
|
71174
|
+
const dataLen = data.byteLength;
|
|
71175
|
+
let from = offset;
|
|
71176
|
+
if ( from < 0 ) {
|
|
71177
|
+
from = 0;
|
|
71178
|
+
}
|
|
71179
|
+
if ( from > dataLen ) {
|
|
71180
|
+
from = dataLen;
|
|
71181
|
+
}
|
|
71182
|
+
const rest = dataLen - from;
|
|
71183
|
+
this.resetOutput(rest * 4);
|
|
71184
|
+
this.reader.init(data, from, rest);
|
|
71185
|
+
this.buildFixedTables();
|
|
71186
|
+
let finalBlock = false;
|
|
71187
|
+
while (false == finalBlock) {
|
|
71188
|
+
const bfinal = this.reader.readBit();
|
|
71189
|
+
const btype = this.reader.readBits(2);
|
|
71190
|
+
finalBlock = bfinal == 1;
|
|
71191
|
+
if ( btype == 0 ) {
|
|
71192
|
+
this.decompressStored();
|
|
71193
|
+
}
|
|
71194
|
+
if ( btype == 1 ) {
|
|
71195
|
+
this.decompressHuffman(this.fixedLitLen, this.fixedDist);
|
|
71196
|
+
}
|
|
71197
|
+
if ( btype == 2 ) {
|
|
71198
|
+
this.decompressDynamic();
|
|
71199
|
+
}
|
|
71200
|
+
};
|
|
71201
|
+
return this.finalOutput();
|
|
71202
|
+
};
|
|
71203
|
+
inputPos () {
|
|
71204
|
+
return this.reader.getBytePosition();
|
|
71205
|
+
};
|
|
71206
|
+
decompressStored () {
|
|
71207
|
+
this.reader.alignToByte();
|
|
71208
|
+
const __len = this.reader.readUint16LE();
|
|
71209
|
+
const nlen = this.reader.readUint16LE();
|
|
71210
|
+
if ( __len + nlen != 65535 ) {
|
|
71211
|
+
}
|
|
71212
|
+
this.ensureCapacity(__len);
|
|
71213
|
+
let i = 0;
|
|
71214
|
+
while (i < __len) {
|
|
71215
|
+
const b = this.reader.readByte();
|
|
71216
|
+
this.pushByte(b);
|
|
71217
|
+
i = i + 1;
|
|
71218
|
+
};
|
|
71219
|
+
};
|
|
71220
|
+
decompressHuffman (litLenTable, distTable) {
|
|
71221
|
+
let done = false;
|
|
71222
|
+
while (false == done) {
|
|
71223
|
+
const sym = litLenTable.decode(this.reader);
|
|
71224
|
+
if ( sym < 256 ) {
|
|
71225
|
+
this.pushByte(sym);
|
|
71226
|
+
}
|
|
71227
|
+
if ( sym == 256 ) {
|
|
71228
|
+
done = true;
|
|
71229
|
+
}
|
|
71230
|
+
if ( sym > 256 ) {
|
|
71231
|
+
const lengthCode = sym - 257;
|
|
71232
|
+
let length = this.lengthBase[lengthCode];
|
|
71233
|
+
const extraBits = this.lengthExtra[lengthCode];
|
|
71234
|
+
if ( extraBits > 0 ) {
|
|
71235
|
+
length = length + this.reader.readBits(extraBits);
|
|
71236
|
+
}
|
|
71237
|
+
const distCode = distTable.decode(this.reader);
|
|
71238
|
+
let dist = this.distBase[distCode];
|
|
71239
|
+
const distExtraBits = this.distExtra[distCode];
|
|
71240
|
+
if ( distExtraBits > 0 ) {
|
|
71241
|
+
dist = dist + this.reader.readBits(distExtraBits);
|
|
71242
|
+
}
|
|
71243
|
+
this.copyFromOutput(dist, length);
|
|
71244
|
+
}
|
|
71245
|
+
};
|
|
71246
|
+
};
|
|
71247
|
+
decompressDynamic () {
|
|
71248
|
+
const hlit = this.reader.readBits(5) + 257;
|
|
71249
|
+
const hdist = this.reader.readBits(5) + 1;
|
|
71250
|
+
const hclen = this.reader.readBits(4) + 4;
|
|
71251
|
+
let clOrder = [];
|
|
71252
|
+
clOrder.push(16);
|
|
71253
|
+
clOrder.push(17);
|
|
71254
|
+
clOrder.push(18);
|
|
71255
|
+
clOrder.push(0);
|
|
71256
|
+
clOrder.push(8);
|
|
71257
|
+
clOrder.push(7);
|
|
71258
|
+
clOrder.push(9);
|
|
71259
|
+
clOrder.push(6);
|
|
71260
|
+
clOrder.push(10);
|
|
71261
|
+
clOrder.push(5);
|
|
71262
|
+
clOrder.push(11);
|
|
71263
|
+
clOrder.push(4);
|
|
71264
|
+
clOrder.push(12);
|
|
71265
|
+
clOrder.push(3);
|
|
71266
|
+
clOrder.push(13);
|
|
71267
|
+
clOrder.push(2);
|
|
71268
|
+
clOrder.push(14);
|
|
71269
|
+
clOrder.push(1);
|
|
71270
|
+
clOrder.push(15);
|
|
71271
|
+
let clLengths = [];
|
|
71272
|
+
let i = 0;
|
|
71273
|
+
while (i < 19) {
|
|
71274
|
+
clLengths.push(0);
|
|
71275
|
+
i = i + 1;
|
|
71276
|
+
};
|
|
71277
|
+
i = 0;
|
|
71278
|
+
while (i < hclen) {
|
|
71279
|
+
const idx = clOrder[i];
|
|
71280
|
+
const __len = this.reader.readBits(3);
|
|
71281
|
+
clLengths[idx] = __len;
|
|
71282
|
+
i = i + 1;
|
|
71283
|
+
};
|
|
71284
|
+
const clTable = new InflateHuffmanTable();
|
|
71285
|
+
clTable.build(clLengths, 19);
|
|
71286
|
+
let allLengths = [];
|
|
71287
|
+
const totalCodes = hlit + hdist;
|
|
71288
|
+
i = 0;
|
|
71289
|
+
while (i < totalCodes) {
|
|
71290
|
+
const sym = clTable.decode(this.reader);
|
|
71291
|
+
if ( sym < 16 ) {
|
|
71292
|
+
allLengths.push(sym);
|
|
71293
|
+
i = i + 1;
|
|
71294
|
+
}
|
|
71295
|
+
if ( sym == 16 ) {
|
|
71296
|
+
const repeat = this.reader.readBits(2) + 3;
|
|
71297
|
+
let prevLen = 0;
|
|
71298
|
+
const arrLen = allLengths.length;
|
|
71299
|
+
if ( arrLen > 0 ) {
|
|
71300
|
+
prevLen = allLengths[(arrLen - 1)];
|
|
71301
|
+
}
|
|
71302
|
+
let j = 0;
|
|
71303
|
+
while (j < repeat) {
|
|
71304
|
+
allLengths.push(prevLen);
|
|
71305
|
+
j = j + 1;
|
|
71306
|
+
};
|
|
71307
|
+
i = i + repeat;
|
|
71308
|
+
}
|
|
71309
|
+
if ( sym == 17 ) {
|
|
71310
|
+
const repeat_1 = this.reader.readBits(3) + 3;
|
|
71311
|
+
let j_1 = 0;
|
|
71312
|
+
while (j_1 < repeat_1) {
|
|
71313
|
+
allLengths.push(0);
|
|
71314
|
+
j_1 = j_1 + 1;
|
|
71315
|
+
};
|
|
71316
|
+
i = i + repeat_1;
|
|
71317
|
+
}
|
|
71318
|
+
if ( sym == 18 ) {
|
|
71319
|
+
const repeat_2 = this.reader.readBits(7) + 11;
|
|
71320
|
+
let j_2 = 0;
|
|
71321
|
+
while (j_2 < repeat_2) {
|
|
71322
|
+
allLengths.push(0);
|
|
71323
|
+
j_2 = j_2 + 1;
|
|
71324
|
+
};
|
|
71325
|
+
i = i + repeat_2;
|
|
71326
|
+
}
|
|
71327
|
+
};
|
|
71328
|
+
let litLenLengths = [];
|
|
71329
|
+
let distLengths = [];
|
|
71330
|
+
i = 0;
|
|
71331
|
+
while (i < hlit) {
|
|
71332
|
+
litLenLengths.push(allLengths[i]);
|
|
71333
|
+
i = i + 1;
|
|
71334
|
+
};
|
|
71335
|
+
while (i < totalCodes) {
|
|
71336
|
+
distLengths.push(allLengths[i]);
|
|
71337
|
+
i = i + 1;
|
|
71338
|
+
};
|
|
71339
|
+
const dynLitLen = new InflateHuffmanTable();
|
|
71340
|
+
dynLitLen.build(litLenLengths, hlit);
|
|
71341
|
+
const dynDist = new InflateHuffmanTable();
|
|
71342
|
+
dynDist.build(distLengths, hdist);
|
|
71343
|
+
this.decompressHuffman(dynLitLen, dynDist);
|
|
71344
|
+
};
|
|
71345
|
+
copyFromOutput (distance, length) {
|
|
71346
|
+
const srcPos = this.outLen - distance;
|
|
71347
|
+
this.ensureCapacity(length);
|
|
71348
|
+
let i = 0;
|
|
71349
|
+
while (i < length) {
|
|
71350
|
+
let b = 0;
|
|
71351
|
+
const readPos = srcPos + i;
|
|
71352
|
+
if ( readPos >= 0 ) {
|
|
71353
|
+
if ( readPos < this.outLen ) {
|
|
71354
|
+
b = this.outBuf._view.getUint8(readPos);
|
|
71355
|
+
}
|
|
71356
|
+
}
|
|
71357
|
+
this.outBuf._view.setUint8(this.outLen, b);
|
|
71358
|
+
this.outLen = this.outLen + 1;
|
|
71359
|
+
i = i + 1;
|
|
71360
|
+
};
|
|
71361
|
+
};
|
|
71362
|
+
}
|
|
71363
|
+
class GitZlib {
|
|
71364
|
+
constructor() {
|
|
71365
|
+
this.ok = true;
|
|
71366
|
+
this.err = "";
|
|
71367
|
+
this.nextPos = 0;
|
|
71368
|
+
this.ok = true;
|
|
71369
|
+
this.err = "";
|
|
71370
|
+
this.nextPos = 0;
|
|
71371
|
+
}
|
|
71372
|
+
inflateAt (data, offset) {
|
|
71373
|
+
this.ok = true;
|
|
71374
|
+
this.err = "";
|
|
71375
|
+
this.nextPos = offset;
|
|
71376
|
+
const n = data.byteLength;
|
|
71377
|
+
if ( offset + 6 > n ) {
|
|
71378
|
+
this.ok = false;
|
|
71379
|
+
this.err = "zlib stream truncated";
|
|
71380
|
+
return (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
71381
|
+
}
|
|
71382
|
+
const cmf = data._view.getUint8(offset);
|
|
71383
|
+
const flg = data._view.getUint8((offset + 1));
|
|
71384
|
+
const method = (cmf & 15);
|
|
71385
|
+
if ( method != 8 ) {
|
|
71386
|
+
this.ok = false;
|
|
71387
|
+
this.err = "zlib method is not deflate";
|
|
71388
|
+
return (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
71389
|
+
}
|
|
71390
|
+
if ( (flg & 32) != 0 ) {
|
|
71391
|
+
this.ok = false;
|
|
71392
|
+
this.err = "zlib preset dictionary is not used by Git";
|
|
71393
|
+
return (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
71394
|
+
}
|
|
71395
|
+
const inf = new Inflate();
|
|
71396
|
+
const out = inf.decompressFrom(data, (offset + 2));
|
|
71397
|
+
const end = inf.inputPos();
|
|
71398
|
+
if ( end + 4 > n ) {
|
|
71399
|
+
this.ok = false;
|
|
71400
|
+
this.err = "zlib Adler-32 truncated";
|
|
71401
|
+
this.nextPos = n;
|
|
71402
|
+
return out;
|
|
71403
|
+
}
|
|
71404
|
+
this.nextPos = end + 4;
|
|
71405
|
+
return out;
|
|
71406
|
+
};
|
|
71407
|
+
inflate (data) {
|
|
71408
|
+
return this.inflateAt(data, 0);
|
|
71409
|
+
};
|
|
71410
|
+
}
|
|
71411
|
+
class GitObj {
|
|
71412
|
+
constructor() {
|
|
71413
|
+
this.kind = 0;
|
|
71414
|
+
this.sha = "";
|
|
71415
|
+
this.data = (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
71416
|
+
this.packOff = 0;
|
|
71417
|
+
this.resolved = false;
|
|
71418
|
+
this.delta = false;
|
|
71419
|
+
this.baseOff = 0;
|
|
71420
|
+
this.baseSha = "";
|
|
71421
|
+
}
|
|
71422
|
+
}
|
|
71423
|
+
class GitPack {
|
|
71424
|
+
constructor() {
|
|
71425
|
+
this.ok = true;
|
|
71426
|
+
this.err = "";
|
|
71427
|
+
this.version = 0;
|
|
71428
|
+
this.count = 0;
|
|
71429
|
+
this.objects = [];
|
|
71430
|
+
this.bySha = {};
|
|
71431
|
+
this.byOff = {};
|
|
71432
|
+
}
|
|
71433
|
+
}
|
|
71434
|
+
class GitDelta {
|
|
71435
|
+
constructor() {
|
|
71436
|
+
}
|
|
71437
|
+
}
|
|
71438
|
+
GitDelta.varInt = function(data, pos) {
|
|
71439
|
+
let at = pos[0];
|
|
71440
|
+
const n = data.byteLength;
|
|
71441
|
+
if ( at >= n ) {
|
|
71442
|
+
return 0;
|
|
71443
|
+
}
|
|
71444
|
+
let c = data._view.getUint8(at);
|
|
71445
|
+
at = at + 1;
|
|
71446
|
+
let v = (c & 127);
|
|
71447
|
+
let shift = 7;
|
|
71448
|
+
while ((c & 128) != 0) {
|
|
71449
|
+
if ( at >= n ) {
|
|
71450
|
+
pos[0] = at;
|
|
71451
|
+
return v;
|
|
71452
|
+
}
|
|
71453
|
+
c = data._view.getUint8(at);
|
|
71454
|
+
at = at + 1;
|
|
71455
|
+
v = (v | ((c & 127) << shift));
|
|
71456
|
+
shift = shift + 7;
|
|
71457
|
+
};
|
|
71458
|
+
pos[0] = at;
|
|
71459
|
+
return v;
|
|
71460
|
+
};
|
|
71461
|
+
GitDelta.apply = function(src, delta) {
|
|
71462
|
+
let pos = [];
|
|
71463
|
+
pos.push(0);
|
|
71464
|
+
const srcSize = GitDelta.varInt(delta, pos);
|
|
71465
|
+
const dstSize = GitDelta.varInt(delta, pos);
|
|
71466
|
+
const srcLen = src.byteLength;
|
|
71467
|
+
if ( srcSize != srcLen ) {
|
|
71468
|
+
}
|
|
71469
|
+
let out = (function(){ var b = new ArrayBuffer(dstSize); b._view = new DataView(b); return b; })();
|
|
71470
|
+
let o = 0;
|
|
71471
|
+
const n = delta.byteLength;
|
|
71472
|
+
let at = pos[0];
|
|
71473
|
+
while (at < n) {
|
|
71474
|
+
const cmd = delta._view.getUint8(at);
|
|
71475
|
+
at = at + 1;
|
|
71476
|
+
if ( (cmd & 128) != 0 ) {
|
|
71477
|
+
let cpOff = 0;
|
|
71478
|
+
let cpSize = 0;
|
|
71479
|
+
if ( (cmd & 1) != 0 ) {
|
|
71480
|
+
cpOff = delta._view.getUint8(at);
|
|
71481
|
+
at = at + 1;
|
|
71482
|
+
}
|
|
71483
|
+
if ( (cmd & 2) != 0 ) {
|
|
71484
|
+
cpOff = (cpOff | (delta._view.getUint8(at) << 8));
|
|
71485
|
+
at = at + 1;
|
|
71486
|
+
}
|
|
71487
|
+
if ( (cmd & 4) != 0 ) {
|
|
71488
|
+
cpOff = (cpOff | (delta._view.getUint8(at) << 16));
|
|
71489
|
+
at = at + 1;
|
|
71490
|
+
}
|
|
71491
|
+
if ( (cmd & 8) != 0 ) {
|
|
71492
|
+
cpOff = (cpOff | (delta._view.getUint8(at) << 24));
|
|
71493
|
+
at = at + 1;
|
|
71494
|
+
}
|
|
71495
|
+
if ( (cmd & 16) != 0 ) {
|
|
71496
|
+
cpSize = delta._view.getUint8(at);
|
|
71497
|
+
at = at + 1;
|
|
71498
|
+
}
|
|
71499
|
+
if ( (cmd & 32) != 0 ) {
|
|
71500
|
+
cpSize = (cpSize | (delta._view.getUint8(at) << 8));
|
|
71501
|
+
at = at + 1;
|
|
71502
|
+
}
|
|
71503
|
+
if ( (cmd & 64) != 0 ) {
|
|
71504
|
+
cpSize = (cpSize | (delta._view.getUint8(at) << 16));
|
|
71505
|
+
at = at + 1;
|
|
71506
|
+
}
|
|
71507
|
+
if ( cpSize == 0 ) {
|
|
71508
|
+
cpSize = 65536;
|
|
71509
|
+
}
|
|
71510
|
+
(function(
|
|
71511
|
+
d,
|
|
71512
|
+
dOff,
|
|
71513
|
+
s,
|
|
71514
|
+
sOff,
|
|
71515
|
+
len
|
|
71516
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(out,o,src,cpOff,cpSize);
|
|
71517
|
+
o = o + cpSize;
|
|
71518
|
+
} else {
|
|
71519
|
+
if ( cmd == 0 ) {
|
|
71520
|
+
return out;
|
|
71521
|
+
}
|
|
71522
|
+
(function(
|
|
71523
|
+
d,
|
|
71524
|
+
dOff,
|
|
71525
|
+
s,
|
|
71526
|
+
sOff,
|
|
71527
|
+
len
|
|
71528
|
+
){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(out,o,delta,at,cmd);
|
|
71529
|
+
o = o + cmd;
|
|
71530
|
+
at = at + cmd;
|
|
71531
|
+
}
|
|
71532
|
+
};
|
|
71533
|
+
return out;
|
|
71534
|
+
};
|
|
71535
|
+
class GitPackIO {
|
|
71536
|
+
constructor() {
|
|
71537
|
+
}
|
|
71538
|
+
}
|
|
71539
|
+
GitPackIO.kindName = function(kind) {
|
|
71540
|
+
if ( kind == 1 ) {
|
|
71541
|
+
return "commit";
|
|
71542
|
+
}
|
|
71543
|
+
if ( kind == 2 ) {
|
|
71544
|
+
return "tree";
|
|
71545
|
+
}
|
|
71546
|
+
if ( kind == 3 ) {
|
|
71547
|
+
return "blob";
|
|
71548
|
+
}
|
|
71549
|
+
if ( kind == 4 ) {
|
|
71550
|
+
return "tag";
|
|
71551
|
+
}
|
|
71552
|
+
return "unknown";
|
|
71553
|
+
};
|
|
71554
|
+
GitPackIO.parse = function(data) {
|
|
71555
|
+
const pack = new GitPack();
|
|
71556
|
+
const n = data.byteLength;
|
|
71557
|
+
if ( n < 32 ) {
|
|
71558
|
+
pack.ok = false;
|
|
71559
|
+
pack.err = "pack too small";
|
|
71560
|
+
return pack;
|
|
71561
|
+
}
|
|
71562
|
+
const mag = GitSha1.ascii(data, 0, 4);
|
|
71563
|
+
if ( mag != "PACK" ) {
|
|
71564
|
+
pack.ok = false;
|
|
71565
|
+
pack.err = "not a pack (missing PACK magic)";
|
|
71566
|
+
return pack;
|
|
71567
|
+
}
|
|
71568
|
+
pack.version = GitSha1.u32be(data, 4);
|
|
71569
|
+
pack.count = GitSha1.u32be(data, 8);
|
|
71570
|
+
if ( pack.version != 2 ) {
|
|
71571
|
+
pack.ok = false;
|
|
71572
|
+
pack.err = "unsupported pack version " + (pack.version.toString());
|
|
71573
|
+
return pack;
|
|
71574
|
+
}
|
|
71575
|
+
const z = new GitZlib();
|
|
71576
|
+
let at = 12;
|
|
71577
|
+
let i = 0;
|
|
71578
|
+
while (i < pack.count) {
|
|
71579
|
+
if ( at >= n - 20 ) {
|
|
71580
|
+
pack.ok = false;
|
|
71581
|
+
pack.err = "truncated pack at object " + (i.toString());
|
|
71582
|
+
return pack;
|
|
71583
|
+
}
|
|
71584
|
+
const obj = new GitObj();
|
|
71585
|
+
obj.packOff = at;
|
|
71586
|
+
let c = data._view.getUint8(at);
|
|
71587
|
+
at = at + 1;
|
|
71588
|
+
obj.kind = ((c >>> 4) & 7);
|
|
71589
|
+
let size = (c & 15);
|
|
71590
|
+
let shift = 4;
|
|
71591
|
+
while ((c & 128) != 0) {
|
|
71592
|
+
if ( at >= n ) {
|
|
71593
|
+
pack.ok = false;
|
|
71594
|
+
pack.err = "truncated size encoding";
|
|
71595
|
+
return pack;
|
|
71596
|
+
}
|
|
71597
|
+
c = data._view.getUint8(at);
|
|
71598
|
+
at = at + 1;
|
|
71599
|
+
size = (size | ((c & 127) << shift));
|
|
71600
|
+
shift = shift + 7;
|
|
71601
|
+
};
|
|
71602
|
+
if ( obj.kind == 6 ) {
|
|
71603
|
+
let oc = data._view.getUint8(at);
|
|
71604
|
+
at = at + 1;
|
|
71605
|
+
let offv = (oc & 127);
|
|
71606
|
+
while ((oc & 128) != 0) {
|
|
71607
|
+
oc = data._view.getUint8(at);
|
|
71608
|
+
at = at + 1;
|
|
71609
|
+
offv = offv + 1;
|
|
71610
|
+
offv = offv * 128 + (oc & 127);
|
|
71611
|
+
};
|
|
71612
|
+
obj.delta = true;
|
|
71613
|
+
obj.baseOff = obj.packOff - offv;
|
|
71614
|
+
}
|
|
71615
|
+
if ( obj.kind == 7 ) {
|
|
71616
|
+
obj.delta = true;
|
|
71617
|
+
obj.baseSha = GitSha1.toHex(GitSha1.copyRange(
|
|
71618
|
+
data,
|
|
71619
|
+
at,
|
|
71620
|
+
20
|
|
71621
|
+
));
|
|
71622
|
+
at = at + 20;
|
|
71623
|
+
}
|
|
71624
|
+
const inflated = z.inflateAt(data, at);
|
|
71625
|
+
if ( z.ok == false ) {
|
|
71626
|
+
pack.ok = false;
|
|
71627
|
+
pack.err = (("inflate object " + (i.toString())) + ": ") + z.err;
|
|
71628
|
+
return pack;
|
|
71629
|
+
}
|
|
71630
|
+
at = z.nextPos;
|
|
71631
|
+
obj.data = inflated;
|
|
71632
|
+
if ( obj.delta ) {
|
|
71633
|
+
obj.resolved = false;
|
|
71634
|
+
} else {
|
|
71635
|
+
obj.resolved = true;
|
|
71636
|
+
obj.sha = GitSha1.objectId(GitPackIO.kindName(obj.kind), inflated);
|
|
71637
|
+
pack.bySha[obj.sha] = obj;
|
|
71638
|
+
}
|
|
71639
|
+
pack.byOff[obj.packOff] = obj;
|
|
71640
|
+
pack.objects.push(obj);
|
|
71641
|
+
i = i + 1;
|
|
71642
|
+
};
|
|
71643
|
+
GitPackIO.resolveDeltas(pack);
|
|
71644
|
+
return pack;
|
|
71645
|
+
};
|
|
71646
|
+
GitPackIO.resolveDeltas = function(pack) {
|
|
71647
|
+
let guard = 0;
|
|
71648
|
+
let progress = true;
|
|
71649
|
+
while (progress) {
|
|
71650
|
+
if ( guard > 64 ) {
|
|
71651
|
+
pack.ok = false;
|
|
71652
|
+
pack.err = "delta chain too deep";
|
|
71653
|
+
return;
|
|
71654
|
+
}
|
|
71655
|
+
progress = false;
|
|
71656
|
+
let i = 0;
|
|
71657
|
+
while (i < pack.objects.length) {
|
|
71658
|
+
const obj = pack.objects[i];
|
|
71659
|
+
if ( obj.resolved == false ) {
|
|
71660
|
+
let base;
|
|
71661
|
+
if ( obj.kind == 6 ) {
|
|
71662
|
+
if ( ( typeof(pack.byOff[obj.baseOff] ) != "undefined" && Object.prototype.hasOwnProperty.call(pack.byOff, obj.baseOff) ) ) {
|
|
71663
|
+
base = ( Object.prototype.hasOwnProperty.call(pack.byOff, obj.baseOff) ? pack.byOff[obj.baseOff] : undefined );
|
|
71664
|
+
}
|
|
71665
|
+
}
|
|
71666
|
+
if ( obj.kind == 7 ) {
|
|
71667
|
+
if ( ( typeof(pack.bySha[obj.baseSha] ) != "undefined" && Object.prototype.hasOwnProperty.call(pack.bySha, obj.baseSha) ) ) {
|
|
71668
|
+
base = ( Object.prototype.hasOwnProperty.call(pack.bySha, obj.baseSha) ? pack.bySha[obj.baseSha] : undefined );
|
|
71669
|
+
}
|
|
71670
|
+
}
|
|
71671
|
+
if ( typeof(base) === "undefined" ) {
|
|
71672
|
+
} else {
|
|
71673
|
+
const b = base;
|
|
71674
|
+
if ( b.resolved ) {
|
|
71675
|
+
const out = GitDelta.apply(b.data, obj.data);
|
|
71676
|
+
obj.data = out;
|
|
71677
|
+
obj.kind = b.kind;
|
|
71678
|
+
obj.delta = false;
|
|
71679
|
+
obj.resolved = true;
|
|
71680
|
+
obj.sha = GitSha1.objectId(GitPackIO.kindName(obj.kind), out);
|
|
71681
|
+
pack.bySha[obj.sha] = obj;
|
|
71682
|
+
progress = true;
|
|
71683
|
+
}
|
|
71684
|
+
}
|
|
71685
|
+
}
|
|
71686
|
+
i = i + 1;
|
|
71687
|
+
};
|
|
71688
|
+
guard = guard + 1;
|
|
71689
|
+
};
|
|
71690
|
+
let j = 0;
|
|
71691
|
+
while (j < pack.objects.length) {
|
|
71692
|
+
const o2 = pack.objects[j];
|
|
71693
|
+
if ( o2.resolved == false ) {
|
|
71694
|
+
pack.ok = false;
|
|
71695
|
+
pack.err = "unresolved delta in pack";
|
|
71696
|
+
return;
|
|
71697
|
+
}
|
|
71698
|
+
j = j + 1;
|
|
71699
|
+
};
|
|
71700
|
+
};
|
|
71701
|
+
GitPackIO.lookup = function(pack, sha) {
|
|
71702
|
+
let res;
|
|
71703
|
+
if ( ( typeof(pack.bySha[sha] ) != "undefined" && Object.prototype.hasOwnProperty.call(pack.bySha, sha) ) ) {
|
|
71704
|
+
res = ( Object.prototype.hasOwnProperty.call(pack.bySha, sha) ? pack.bySha[sha] : undefined );
|
|
71705
|
+
}
|
|
71706
|
+
return res;
|
|
71707
|
+
};
|
|
71708
|
+
GitPackIO.merge = function(a, b) {
|
|
71709
|
+
const out = new GitPack();
|
|
71710
|
+
if ( a.ok == false ) {
|
|
71711
|
+
out.ok = false;
|
|
71712
|
+
out.err = a.err;
|
|
71713
|
+
return out;
|
|
71714
|
+
}
|
|
71715
|
+
if ( b.ok == false ) {
|
|
71716
|
+
out.ok = false;
|
|
71717
|
+
out.err = b.err;
|
|
71718
|
+
return out;
|
|
71719
|
+
}
|
|
71720
|
+
let i = 0;
|
|
71721
|
+
while (i < a.objects.length) {
|
|
71722
|
+
const o = a.objects[i];
|
|
71723
|
+
out.objects.push(o);
|
|
71724
|
+
out.bySha[o.sha] = o;
|
|
71725
|
+
i = i + 1;
|
|
71726
|
+
};
|
|
71727
|
+
i = 0;
|
|
71728
|
+
while (i < b.objects.length) {
|
|
71729
|
+
const o2 = b.objects[i];
|
|
71730
|
+
if ( ( typeof(out.bySha[o2.sha] ) != "undefined" && Object.prototype.hasOwnProperty.call(out.bySha, o2.sha) ) ) {
|
|
71731
|
+
} else {
|
|
71732
|
+
out.objects.push(o2);
|
|
71733
|
+
out.bySha[o2.sha] = o2;
|
|
71734
|
+
}
|
|
71735
|
+
i = i + 1;
|
|
71736
|
+
};
|
|
71737
|
+
out.count = out.objects.length;
|
|
71738
|
+
out.ok = true;
|
|
71739
|
+
return out;
|
|
71740
|
+
};
|
|
71741
|
+
class GitEntry {
|
|
71742
|
+
constructor() {
|
|
71743
|
+
this.name = "";
|
|
71744
|
+
this.sha = "";
|
|
71745
|
+
this.isTree = false;
|
|
71746
|
+
this.mode = "";
|
|
71747
|
+
}
|
|
71748
|
+
}
|
|
71749
|
+
class GitFile {
|
|
71750
|
+
constructor() {
|
|
71751
|
+
this.path = "";
|
|
71752
|
+
this.data = (function(){ var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
|
|
71753
|
+
}
|
|
71754
|
+
}
|
|
71755
|
+
class GitTree {
|
|
71756
|
+
constructor() {
|
|
71757
|
+
this.sha = ""; /* note: unused */
|
|
71758
|
+
this.entries = [];
|
|
71759
|
+
}
|
|
71760
|
+
}
|
|
71761
|
+
class GitMem {
|
|
71762
|
+
constructor() {
|
|
71763
|
+
this.files = [];
|
|
71764
|
+
this.paths = [];
|
|
71765
|
+
this.byPath = {};
|
|
71766
|
+
}
|
|
71767
|
+
}
|
|
71768
|
+
class GitStore {
|
|
71769
|
+
constructor(p) {
|
|
71770
|
+
this.pack = new GitPack();
|
|
71771
|
+
this.ok = true;
|
|
71772
|
+
this.err = "";
|
|
71773
|
+
this.pack = p;
|
|
71774
|
+
this.ok = p.ok;
|
|
71775
|
+
this.err = p.err;
|
|
71776
|
+
}
|
|
71777
|
+
takeObj (sha) {
|
|
71778
|
+
return GitPackIO.lookup(this.pack, sha);
|
|
71779
|
+
};
|
|
71780
|
+
parseTree (payload) {
|
|
71781
|
+
const t = new GitTree();
|
|
71782
|
+
const n = payload.byteLength;
|
|
71783
|
+
let at = 0;
|
|
71784
|
+
while (at < n) {
|
|
71785
|
+
const modeStart = at;
|
|
71786
|
+
while (at < n) {
|
|
71787
|
+
if ( payload._view.getUint8(at) == 32 ) {
|
|
71788
|
+
break;
|
|
71789
|
+
}
|
|
71790
|
+
at = at + 1;
|
|
71791
|
+
};
|
|
71792
|
+
const mode = GitSha1.ascii(
|
|
71793
|
+
payload,
|
|
71794
|
+
modeStart,
|
|
71795
|
+
(at - modeStart)
|
|
71796
|
+
);
|
|
71797
|
+
at = at + 1;
|
|
71798
|
+
const nameStart = at;
|
|
71799
|
+
while (at < n) {
|
|
71800
|
+
if ( payload._view.getUint8(at) == 0 ) {
|
|
71801
|
+
break;
|
|
71802
|
+
}
|
|
71803
|
+
at = at + 1;
|
|
71804
|
+
};
|
|
71805
|
+
const name = GitSha1.ascii(
|
|
71806
|
+
payload,
|
|
71807
|
+
nameStart,
|
|
71808
|
+
(at - nameStart)
|
|
71809
|
+
);
|
|
71810
|
+
at = at + 1;
|
|
71811
|
+
if ( at + 20 > n ) {
|
|
71812
|
+
break;
|
|
71813
|
+
}
|
|
71814
|
+
const sha = GitSha1.toHex(GitSha1.copyRange(
|
|
71815
|
+
payload,
|
|
71816
|
+
at,
|
|
71817
|
+
20
|
|
71818
|
+
));
|
|
71819
|
+
at = at + 20;
|
|
71820
|
+
const e = new GitEntry();
|
|
71821
|
+
e.name = name;
|
|
71822
|
+
e.sha = sha;
|
|
71823
|
+
e.mode = mode;
|
|
71824
|
+
if ( mode.length > 0 ) {
|
|
71825
|
+
if ( mode.substring(0, 1 ) == "4" ) {
|
|
71826
|
+
e.isTree = true;
|
|
71827
|
+
}
|
|
71828
|
+
}
|
|
71829
|
+
t.entries.push(e);
|
|
71830
|
+
};
|
|
71831
|
+
return t;
|
|
71832
|
+
};
|
|
71833
|
+
commitTree (payload) {
|
|
71834
|
+
const text = (function(b){ var v = (b instanceof Uint8Array) ? b : new Uint8Array(b); var s = ""; var i = 0; var n = v.length; var c = 32768; while (i < n) { var e = i + c; if (e > n) { e = n; } s += String.fromCharCode.apply(null, v.subarray(i, e)); i = e; } return s; })(payload);
|
|
71835
|
+
if ( text.length < 46 ) {
|
|
71836
|
+
return "";
|
|
71837
|
+
}
|
|
71838
|
+
if ( text.substring(0, 5 ) != "tree " ) {
|
|
71839
|
+
return "";
|
|
71840
|
+
}
|
|
71841
|
+
return text.substring(5, 45 );
|
|
71842
|
+
};
|
|
71843
|
+
checkout (sha, subdir) {
|
|
71844
|
+
const mem = new GitMem();
|
|
71845
|
+
const obj = this.takeObj(sha);
|
|
71846
|
+
if ( typeof(obj) === "undefined" ) {
|
|
71847
|
+
this.ok = false;
|
|
71848
|
+
this.err = "object not in pack: " + sha;
|
|
71849
|
+
return mem;
|
|
71850
|
+
}
|
|
71851
|
+
const o = obj;
|
|
71852
|
+
let treeSha = sha;
|
|
71853
|
+
if ( o.kind == 1 ) {
|
|
71854
|
+
treeSha = this.commitTree(o.data);
|
|
71855
|
+
}
|
|
71856
|
+
if ( o.kind == 4 ) {
|
|
71857
|
+
const tagText = (function(b){ var v = (b instanceof Uint8Array) ? b : new Uint8Array(b); var s = ""; var i = 0; var n = v.length; var c = 32768; while (i < n) { var e = i + c; if (e > n) { e = n; } s += String.fromCharCode.apply(null, v.subarray(i, e)); i = e; } return s; })(o.data);
|
|
71858
|
+
if ( tagText.length >= 48 ) {
|
|
71859
|
+
if ( tagText.substring(0, 7 ) == "object " ) {
|
|
71860
|
+
treeSha = tagText.substring(7, 47 );
|
|
71861
|
+
const inner = this.takeObj(treeSha);
|
|
71862
|
+
if ( typeof(inner) === "undefined" ) {
|
|
71863
|
+
this.ok = false;
|
|
71864
|
+
this.err = "tag target missing: " + treeSha;
|
|
71865
|
+
return mem;
|
|
71866
|
+
}
|
|
71867
|
+
const inn = inner;
|
|
71868
|
+
if ( inn.kind == 1 ) {
|
|
71869
|
+
treeSha = this.commitTree(inn.data);
|
|
71870
|
+
}
|
|
71871
|
+
}
|
|
71872
|
+
}
|
|
71873
|
+
}
|
|
71874
|
+
this.walk(mem, treeSha, "", subdir);
|
|
71875
|
+
return mem;
|
|
71876
|
+
};
|
|
71877
|
+
walk (mem, treeSha, prefix, want) {
|
|
71878
|
+
const obj = this.takeObj(treeSha);
|
|
71879
|
+
if ( typeof(obj) === "undefined" ) {
|
|
71880
|
+
this.ok = false;
|
|
71881
|
+
this.err = "tree missing: " + treeSha;
|
|
71882
|
+
return;
|
|
71883
|
+
}
|
|
71884
|
+
const o = obj;
|
|
71885
|
+
const tree = this.parseTree(o.data);
|
|
71886
|
+
let i = 0;
|
|
71887
|
+
while (i < tree.entries.length) {
|
|
71888
|
+
const e = tree.entries[i];
|
|
71889
|
+
let path = e.name;
|
|
71890
|
+
if ( prefix.length > 0 ) {
|
|
71891
|
+
path = (prefix + "/") + e.name;
|
|
71892
|
+
}
|
|
71893
|
+
if ( e.isTree ) {
|
|
71894
|
+
if ( this.mayEnter(path, want) ) {
|
|
71895
|
+
this.walk(mem, e.sha, path, want);
|
|
71896
|
+
}
|
|
71897
|
+
} else {
|
|
71898
|
+
if ( this.underSubdir(path, want) ) {
|
|
71899
|
+
const blob = this.takeObj(e.sha);
|
|
71900
|
+
if ( typeof(blob) === "undefined" ) {
|
|
71901
|
+
this.ok = false;
|
|
71902
|
+
this.err = "blob missing: " + e.sha;
|
|
71903
|
+
} else {
|
|
71904
|
+
const b = blob;
|
|
71905
|
+
const rel = this.stripSubdir(path, want);
|
|
71906
|
+
const f = new GitFile();
|
|
71907
|
+
f.path = rel;
|
|
71908
|
+
f.data = b.data;
|
|
71909
|
+
mem.files.push(f);
|
|
71910
|
+
mem.paths.push(rel);
|
|
71911
|
+
mem.byPath[rel] = f;
|
|
71912
|
+
}
|
|
71913
|
+
}
|
|
71914
|
+
}
|
|
71915
|
+
i = i + 1;
|
|
71916
|
+
};
|
|
71917
|
+
};
|
|
71918
|
+
mayEnter (path, want) {
|
|
71919
|
+
if ( want.length == 0 ) {
|
|
71920
|
+
return true;
|
|
71921
|
+
}
|
|
71922
|
+
if ( this.underSubdir(path, want) ) {
|
|
71923
|
+
return true;
|
|
71924
|
+
}
|
|
71925
|
+
const pn = path.length;
|
|
71926
|
+
const wn = want.length;
|
|
71927
|
+
if ( wn > pn ) {
|
|
71928
|
+
if ( want.substring(0, pn ) == path ) {
|
|
71929
|
+
if ( want.charCodeAt(pn ) == 47 ) {
|
|
71930
|
+
return true;
|
|
71931
|
+
}
|
|
71932
|
+
}
|
|
71933
|
+
}
|
|
71934
|
+
return path == want;
|
|
71935
|
+
};
|
|
71936
|
+
splitSegs (path) {
|
|
71937
|
+
let parts = [];
|
|
71938
|
+
const n = path.length;
|
|
71939
|
+
let start = 0;
|
|
71940
|
+
let i = 0;
|
|
71941
|
+
while (i <= n) {
|
|
71942
|
+
if ( i == n || path.charCodeAt(i ) == 47 ) {
|
|
71943
|
+
const piece = path.substring(start, i );
|
|
71944
|
+
if ( piece.length > 0 ) {
|
|
71945
|
+
parts.push(piece);
|
|
71946
|
+
}
|
|
71947
|
+
start = i + 1;
|
|
71948
|
+
}
|
|
71949
|
+
i = i + 1;
|
|
71950
|
+
};
|
|
71951
|
+
return parts;
|
|
71952
|
+
};
|
|
71953
|
+
asTreeSha (sha) {
|
|
71954
|
+
const obj = this.takeObj(sha);
|
|
71955
|
+
if ( typeof(obj) === "undefined" ) {
|
|
71956
|
+
this.ok = false;
|
|
71957
|
+
this.err = "object not in pack: " + sha;
|
|
71958
|
+
return "";
|
|
71959
|
+
}
|
|
71960
|
+
const o = obj;
|
|
71961
|
+
if ( o.kind == 2 ) {
|
|
71962
|
+
return sha;
|
|
71963
|
+
}
|
|
71964
|
+
if ( o.kind == 1 ) {
|
|
71965
|
+
return this.commitTree(o.data);
|
|
71966
|
+
}
|
|
71967
|
+
if ( o.kind == 4 ) {
|
|
71968
|
+
const tagText = (function(b){ var v = (b instanceof Uint8Array) ? b : new Uint8Array(b); var s = ""; var i = 0; var n = v.length; var c = 32768; while (i < n) { var e = i + c; if (e > n) { e = n; } s += String.fromCharCode.apply(null, v.subarray(i, e)); i = e; } return s; })(o.data);
|
|
71969
|
+
if ( tagText.length >= 48 ) {
|
|
71970
|
+
if ( tagText.substring(0, 7 ) == "object " ) {
|
|
71971
|
+
const inner = tagText.substring(7, 47 );
|
|
71972
|
+
const inn = this.takeObj(inner);
|
|
71973
|
+
if ( typeof(inn) === "undefined" ) {
|
|
71974
|
+
return inner;
|
|
71975
|
+
}
|
|
71976
|
+
const io = inn;
|
|
71977
|
+
if ( io.kind == 1 ) {
|
|
71978
|
+
return this.commitTree(io.data);
|
|
71979
|
+
}
|
|
71980
|
+
if ( io.kind == 2 ) {
|
|
71981
|
+
return inner;
|
|
71982
|
+
}
|
|
71983
|
+
}
|
|
71984
|
+
}
|
|
71985
|
+
}
|
|
71986
|
+
return sha;
|
|
71987
|
+
};
|
|
71988
|
+
treeAt (sha, subdir) {
|
|
71989
|
+
let cur = this.asTreeSha(sha);
|
|
71990
|
+
if ( cur.length == 0 ) {
|
|
71991
|
+
return "";
|
|
71992
|
+
}
|
|
71993
|
+
if ( subdir.length == 0 ) {
|
|
71994
|
+
return cur;
|
|
71995
|
+
}
|
|
71996
|
+
const segs = this.splitSegs(subdir);
|
|
71997
|
+
let s = 0;
|
|
71998
|
+
while (s < segs.length) {
|
|
71999
|
+
const part = segs[s];
|
|
72000
|
+
const obj = this.takeObj(cur);
|
|
72001
|
+
if ( typeof(obj) === "undefined" ) {
|
|
72002
|
+
this.ok = false;
|
|
72003
|
+
this.err = "tree missing: " + cur;
|
|
72004
|
+
return "";
|
|
72005
|
+
}
|
|
72006
|
+
const o = obj;
|
|
72007
|
+
const tree = this.parseTree(o.data);
|
|
72008
|
+
let found = "";
|
|
72009
|
+
let i = 0;
|
|
72010
|
+
while (i < tree.entries.length) {
|
|
72011
|
+
const e = tree.entries[i];
|
|
72012
|
+
if ( e.name == part ) {
|
|
72013
|
+
if ( e.isTree ) {
|
|
72014
|
+
found = e.sha;
|
|
72015
|
+
}
|
|
72016
|
+
}
|
|
72017
|
+
i = i + 1;
|
|
72018
|
+
};
|
|
72019
|
+
if ( found.length == 0 ) {
|
|
72020
|
+
this.ok = false;
|
|
72021
|
+
this.err = (("no subtree " + part) + " in ") + subdir;
|
|
72022
|
+
return "";
|
|
72023
|
+
}
|
|
72024
|
+
cur = found;
|
|
72025
|
+
s = s + 1;
|
|
72026
|
+
};
|
|
72027
|
+
return cur;
|
|
72028
|
+
};
|
|
72029
|
+
underSubdir (path, want) {
|
|
72030
|
+
if ( want.length == 0 ) {
|
|
72031
|
+
return true;
|
|
72032
|
+
}
|
|
72033
|
+
if ( path == want ) {
|
|
72034
|
+
return true;
|
|
72035
|
+
}
|
|
72036
|
+
const prefix = want + "/";
|
|
72037
|
+
const n = prefix.length;
|
|
72038
|
+
if ( path.length < n ) {
|
|
72039
|
+
return false;
|
|
72040
|
+
}
|
|
72041
|
+
return path.substring(0, n ) == prefix;
|
|
72042
|
+
};
|
|
72043
|
+
stripSubdir (path, want) {
|
|
72044
|
+
if ( want.length == 0 ) {
|
|
72045
|
+
return path;
|
|
72046
|
+
}
|
|
72047
|
+
if ( path == want ) {
|
|
72048
|
+
return this.baseName(path);
|
|
72049
|
+
}
|
|
72050
|
+
const prefix = want + "/";
|
|
72051
|
+
const n = prefix.length;
|
|
72052
|
+
if ( path.length >= n ) {
|
|
72053
|
+
if ( path.substring(0, n ) == prefix ) {
|
|
72054
|
+
return path.substring(n, path.length );
|
|
72055
|
+
}
|
|
72056
|
+
}
|
|
72057
|
+
return path;
|
|
72058
|
+
};
|
|
72059
|
+
baseName (path) {
|
|
72060
|
+
const n = path.length;
|
|
72061
|
+
let i = n - 1;
|
|
72062
|
+
while (i >= 0) {
|
|
72063
|
+
if ( path.charCodeAt(i ) == 47 ) {
|
|
72064
|
+
return path.substring((i + 1), n );
|
|
72065
|
+
}
|
|
72066
|
+
i = i - 1;
|
|
72067
|
+
};
|
|
72068
|
+
return path;
|
|
72069
|
+
};
|
|
72070
|
+
writeDisk (mem, root) {
|
|
72071
|
+
let i = 0;
|
|
72072
|
+
while (i < mem.files.length) {
|
|
72073
|
+
const f = mem.files[i];
|
|
72074
|
+
const dir = this.dirOf(((root + "/") + f.path));
|
|
72075
|
+
require("fs").mkdirSync( dir, { recursive: true });
|
|
72076
|
+
const parts = this.splitPath(((root + "/") + f.path));
|
|
72077
|
+
require('fs').writeFileSync(parts[0] + '/' + parts[1], Buffer.from(f.data));
|
|
72078
|
+
i = i + 1;
|
|
72079
|
+
};
|
|
72080
|
+
};
|
|
72081
|
+
dirOf (path) {
|
|
72082
|
+
const n = path.length;
|
|
72083
|
+
let i = n - 1;
|
|
72084
|
+
while (i >= 0) {
|
|
72085
|
+
if ( path.charCodeAt(i ) == 47 ) {
|
|
72086
|
+
return path.substring(0, i );
|
|
72087
|
+
}
|
|
72088
|
+
i = i - 1;
|
|
72089
|
+
};
|
|
72090
|
+
return ".";
|
|
72091
|
+
};
|
|
72092
|
+
splitPath (path) {
|
|
72093
|
+
let dir = ".";
|
|
72094
|
+
let name = path;
|
|
72095
|
+
const n = path.length;
|
|
72096
|
+
let i = n - 1;
|
|
72097
|
+
while (i >= 0) {
|
|
72098
|
+
if ( path.charCodeAt(i ) == 47 ) {
|
|
72099
|
+
dir = path.substring(0, i );
|
|
72100
|
+
name = path.substring((i + 1), n );
|
|
72101
|
+
i = 0 - 1;
|
|
72102
|
+
} else {
|
|
72103
|
+
i = i - 1;
|
|
72104
|
+
}
|
|
72105
|
+
};
|
|
72106
|
+
let parts = [];
|
|
72107
|
+
parts.push(dir);
|
|
72108
|
+
parts.push(name);
|
|
72109
|
+
return parts;
|
|
72110
|
+
};
|
|
72111
|
+
fileText (mem, path) {
|
|
72112
|
+
if ( ( typeof(mem.byPath[path] ) != "undefined" && Object.prototype.hasOwnProperty.call(mem.byPath, path) ) ) {
|
|
72113
|
+
const f = ( Object.prototype.hasOwnProperty.call(mem.byPath, path) ? mem.byPath[path] : undefined );
|
|
72114
|
+
return (function(b){ var v = (b instanceof Uint8Array) ? b : new Uint8Array(b); var s = ""; var i = 0; var n = v.length; var c = 32768; while (i < n) { var e = i + c; if (e > n) { e = n; } s += String.fromCharCode.apply(null, v.subarray(i, e)); i = e; } return s; })(f.data);
|
|
72115
|
+
}
|
|
72116
|
+
return "";
|
|
72117
|
+
};
|
|
72118
|
+
}
|
|
72119
|
+
class PkgVal {
|
|
72120
|
+
constructor() {
|
|
72121
|
+
this.kind = "null";
|
|
72122
|
+
this.str = "";
|
|
72123
|
+
this.num = 0;
|
|
72124
|
+
this.flag = false;
|
|
72125
|
+
this.keys = [];
|
|
72126
|
+
this.vals = [];
|
|
72127
|
+
}
|
|
72128
|
+
}
|
|
72129
|
+
class PkgJson {
|
|
72130
|
+
constructor() {
|
|
72131
|
+
this.text = "";
|
|
72132
|
+
this.i = 0;
|
|
72133
|
+
this.n = 0;
|
|
72134
|
+
this.ok = true;
|
|
72135
|
+
this.err = "";
|
|
72136
|
+
}
|
|
72137
|
+
parse (src) {
|
|
72138
|
+
this.text = src;
|
|
72139
|
+
this.i = 0;
|
|
72140
|
+
this.n = src.length;
|
|
72141
|
+
this.ok = true;
|
|
72142
|
+
this.err = "";
|
|
72143
|
+
this.skip();
|
|
72144
|
+
const v = this.value();
|
|
72145
|
+
return v;
|
|
72146
|
+
};
|
|
72147
|
+
skip () {
|
|
72148
|
+
while (this.i < this.n) {
|
|
72149
|
+
const c = this.text.charCodeAt(this.i );
|
|
72150
|
+
if ( c <= 32 ) {
|
|
72151
|
+
this.i = this.i + 1;
|
|
72152
|
+
} else {
|
|
72153
|
+
return;
|
|
72154
|
+
}
|
|
72155
|
+
};
|
|
72156
|
+
};
|
|
72157
|
+
value () {
|
|
72158
|
+
this.skip();
|
|
72159
|
+
const v = new PkgVal();
|
|
72160
|
+
if ( this.i >= this.n ) {
|
|
72161
|
+
this.ok = false;
|
|
72162
|
+
this.err = "unexpected end of JSON";
|
|
72163
|
+
return v;
|
|
72164
|
+
}
|
|
72165
|
+
const c = this.text.charCodeAt(this.i );
|
|
72166
|
+
if ( c == 123 ) {
|
|
72167
|
+
return this.object();
|
|
72168
|
+
}
|
|
72169
|
+
if ( c == 34 ) {
|
|
72170
|
+
v.kind = "str";
|
|
72171
|
+
v.str = this.str();
|
|
72172
|
+
return v;
|
|
72173
|
+
}
|
|
72174
|
+
if ( c == 116 ) {
|
|
72175
|
+
v.kind = "bool";
|
|
72176
|
+
v.flag = true;
|
|
72177
|
+
this.i = this.i + 4;
|
|
72178
|
+
return v;
|
|
72179
|
+
}
|
|
72180
|
+
if ( c == 102 ) {
|
|
72181
|
+
v.kind = "bool";
|
|
72182
|
+
v.flag = false;
|
|
72183
|
+
this.i = this.i + 5;
|
|
72184
|
+
return v;
|
|
72185
|
+
}
|
|
72186
|
+
if ( c == 110 ) {
|
|
72187
|
+
v.kind = "null";
|
|
72188
|
+
this.i = this.i + 4;
|
|
72189
|
+
return v;
|
|
72190
|
+
}
|
|
72191
|
+
v.kind = "int";
|
|
72192
|
+
v.num = this.num();
|
|
72193
|
+
return v;
|
|
72194
|
+
};
|
|
72195
|
+
object () {
|
|
72196
|
+
const v = new PkgVal();
|
|
72197
|
+
v.kind = "obj";
|
|
72198
|
+
this.i = this.i + 1;
|
|
72199
|
+
this.skip();
|
|
72200
|
+
while (this.i < this.n) {
|
|
72201
|
+
const c = this.text.charCodeAt(this.i );
|
|
72202
|
+
if ( c == 125 ) {
|
|
72203
|
+
this.i = this.i + 1;
|
|
72204
|
+
return v;
|
|
72205
|
+
}
|
|
72206
|
+
if ( c == 44 ) {
|
|
72207
|
+
this.i = this.i + 1;
|
|
72208
|
+
this.skip();
|
|
72209
|
+
} else {
|
|
72210
|
+
const key = this.str();
|
|
72211
|
+
this.skip();
|
|
72212
|
+
if ( this.i < this.n ) {
|
|
72213
|
+
if ( this.text.charCodeAt(this.i ) == 58 ) {
|
|
72214
|
+
this.i = this.i + 1;
|
|
72215
|
+
}
|
|
72216
|
+
}
|
|
72217
|
+
const child = this.value();
|
|
72218
|
+
v.keys.push(key);
|
|
72219
|
+
v.vals.push(child);
|
|
72220
|
+
this.skip();
|
|
72221
|
+
}
|
|
72222
|
+
};
|
|
72223
|
+
this.ok = false;
|
|
72224
|
+
this.err = "unterminated object";
|
|
72225
|
+
return v;
|
|
72226
|
+
};
|
|
72227
|
+
str () {
|
|
72228
|
+
this.skip();
|
|
72229
|
+
if ( this.i >= this.n ) {
|
|
72230
|
+
return "";
|
|
72231
|
+
}
|
|
72232
|
+
if ( this.text.charCodeAt(this.i ) != 34 ) {
|
|
72233
|
+
this.ok = false;
|
|
72234
|
+
this.err = "expected string";
|
|
72235
|
+
return "";
|
|
72236
|
+
}
|
|
72237
|
+
this.i = this.i + 1;
|
|
72238
|
+
let s = "";
|
|
72239
|
+
while (this.i < this.n) {
|
|
72240
|
+
const c = this.text.charCodeAt(this.i );
|
|
72241
|
+
if ( c == 34 ) {
|
|
72242
|
+
this.i = this.i + 1;
|
|
72243
|
+
return s;
|
|
72244
|
+
}
|
|
72245
|
+
if ( c == 92 ) {
|
|
72246
|
+
this.i = this.i + 1;
|
|
72247
|
+
if ( this.i < this.n ) {
|
|
72248
|
+
const e = this.text.charCodeAt(this.i );
|
|
72249
|
+
if ( e == 110 ) {
|
|
72250
|
+
s = s + String.fromCharCode(10);
|
|
72251
|
+
} else {
|
|
72252
|
+
if ( e == 116 ) {
|
|
72253
|
+
s = s + String.fromCharCode(9);
|
|
72254
|
+
} else {
|
|
72255
|
+
if ( e == 114 ) {
|
|
72256
|
+
s = s + String.fromCharCode(13);
|
|
72257
|
+
} else {
|
|
72258
|
+
s = s + String.fromCharCode(e);
|
|
72259
|
+
}
|
|
72260
|
+
}
|
|
72261
|
+
}
|
|
72262
|
+
this.i = this.i + 1;
|
|
72263
|
+
}
|
|
72264
|
+
} else {
|
|
72265
|
+
s = s + String.fromCharCode(c);
|
|
72266
|
+
this.i = this.i + 1;
|
|
72267
|
+
}
|
|
72268
|
+
};
|
|
72269
|
+
this.ok = false;
|
|
72270
|
+
this.err = "unterminated string";
|
|
72271
|
+
return s;
|
|
72272
|
+
};
|
|
72273
|
+
num () {
|
|
72274
|
+
let sign = 1;
|
|
72275
|
+
if ( this.i < this.n ) {
|
|
72276
|
+
if ( this.text.charCodeAt(this.i ) == 45 ) {
|
|
72277
|
+
sign = 0 - 1;
|
|
72278
|
+
this.i = this.i + 1;
|
|
72279
|
+
}
|
|
72280
|
+
}
|
|
72281
|
+
let v = 0;
|
|
72282
|
+
while (this.i < this.n) {
|
|
72283
|
+
const c = this.text.charCodeAt(this.i );
|
|
72284
|
+
if ( c >= 48 && c <= 57 ) {
|
|
72285
|
+
v = v * 10 + (c - 48);
|
|
72286
|
+
this.i = this.i + 1;
|
|
72287
|
+
} else {
|
|
72288
|
+
return v * sign;
|
|
72289
|
+
}
|
|
72290
|
+
};
|
|
72291
|
+
return v * sign;
|
|
72292
|
+
};
|
|
72293
|
+
}
|
|
72294
|
+
PkgJson.child = function(obj, key) {
|
|
72295
|
+
let res;
|
|
72296
|
+
let i = 0;
|
|
72297
|
+
while (i < obj.keys.length) {
|
|
72298
|
+
if ( obj.keys[i] == key ) {
|
|
72299
|
+
res = obj.vals[i];
|
|
72300
|
+
return res;
|
|
72301
|
+
}
|
|
72302
|
+
i = i + 1;
|
|
72303
|
+
};
|
|
72304
|
+
return res;
|
|
72305
|
+
};
|
|
72306
|
+
PkgJson.strOf = function(obj, key) {
|
|
72307
|
+
const hit = PkgJson.child(obj, key);
|
|
72308
|
+
if ( typeof(hit) === "undefined" ) {
|
|
72309
|
+
return "";
|
|
72310
|
+
}
|
|
72311
|
+
const v = hit;
|
|
72312
|
+
if ( v.kind == "str" ) {
|
|
72313
|
+
return v.str;
|
|
72314
|
+
}
|
|
72315
|
+
if ( v.kind == "int" ) {
|
|
72316
|
+
return (v.num.toString());
|
|
72317
|
+
}
|
|
72318
|
+
return "";
|
|
72319
|
+
};
|
|
72320
|
+
PkgJson.intOf = function(obj, key) {
|
|
72321
|
+
const hit = PkgJson.child(obj, key);
|
|
72322
|
+
if ( typeof(hit) === "undefined" ) {
|
|
72323
|
+
return 0;
|
|
72324
|
+
}
|
|
72325
|
+
const v = hit;
|
|
72326
|
+
if ( v.kind == "int" ) {
|
|
72327
|
+
return v.num;
|
|
72328
|
+
}
|
|
72329
|
+
return 0;
|
|
72330
|
+
};
|
|
72331
|
+
class PkgDep {
|
|
72332
|
+
constructor() {
|
|
72333
|
+
this.name = "";
|
|
72334
|
+
this.path = "";
|
|
72335
|
+
this.git = "";
|
|
72336
|
+
this.rev = "";
|
|
72337
|
+
this.tag = "";
|
|
72338
|
+
this.subdir = "";
|
|
72339
|
+
}
|
|
72340
|
+
}
|
|
72341
|
+
class PkgManifest {
|
|
72342
|
+
constructor() {
|
|
72343
|
+
this.name = "";
|
|
72344
|
+
this.version = "";
|
|
72345
|
+
this.entry = "";
|
|
72346
|
+
this.license = "";
|
|
72347
|
+
this.deps = [];
|
|
72348
|
+
this.ok = true;
|
|
72349
|
+
this.err = "";
|
|
72350
|
+
}
|
|
72351
|
+
}
|
|
72352
|
+
class PkgLockEnt {
|
|
72353
|
+
constructor() {
|
|
72354
|
+
this.name = "";
|
|
72355
|
+
this.path = "";
|
|
72356
|
+
this.git = "";
|
|
72357
|
+
this.rev = "";
|
|
72358
|
+
this.subdir = "";
|
|
72359
|
+
this.sha256 = "";
|
|
72360
|
+
}
|
|
72361
|
+
}
|
|
72362
|
+
class PkgLock {
|
|
72363
|
+
constructor() {
|
|
72364
|
+
this.lockVersion = 1;
|
|
72365
|
+
this.packages = [];
|
|
72366
|
+
this.ok = true;
|
|
72367
|
+
this.err = "";
|
|
72368
|
+
}
|
|
72369
|
+
}
|
|
72370
|
+
class PkgManifestIO {
|
|
72371
|
+
constructor() {
|
|
72372
|
+
}
|
|
72373
|
+
}
|
|
72374
|
+
PkgManifestIO.load = function(src) {
|
|
72375
|
+
const m = new PkgManifest();
|
|
72376
|
+
const p = new PkgJson();
|
|
72377
|
+
const root = p.parse(src);
|
|
72378
|
+
if ( p.ok == false ) {
|
|
72379
|
+
m.ok = false;
|
|
72380
|
+
m.err = p.err;
|
|
72381
|
+
return m;
|
|
72382
|
+
}
|
|
72383
|
+
m.name = PkgJson.strOf(root, "name");
|
|
72384
|
+
m.version = PkgJson.strOf(root, "version");
|
|
72385
|
+
m.entry = PkgJson.strOf(root, "entry");
|
|
72386
|
+
m.license = PkgJson.strOf(root, "license");
|
|
72387
|
+
const deps = PkgJson.child(root, "dependencies");
|
|
72388
|
+
if ( typeof(deps) === "undefined" ) {
|
|
72389
|
+
return m;
|
|
72390
|
+
}
|
|
72391
|
+
const d = deps;
|
|
72392
|
+
let i = 0;
|
|
72393
|
+
while (i < d.keys.length) {
|
|
72394
|
+
const dep = new PkgDep();
|
|
72395
|
+
dep.name = d.keys[i];
|
|
72396
|
+
const spec = d.vals[i];
|
|
72397
|
+
dep.path = PkgJson.strOf(spec, "path");
|
|
72398
|
+
dep.git = PkgJson.strOf(spec, "git");
|
|
72399
|
+
dep.rev = PkgJson.strOf(spec, "rev");
|
|
72400
|
+
dep.tag = PkgJson.strOf(spec, "tag");
|
|
72401
|
+
dep.subdir = PkgJson.strOf(spec, "subdir");
|
|
72402
|
+
m.deps.push(dep);
|
|
72403
|
+
i = i + 1;
|
|
72404
|
+
};
|
|
72405
|
+
return m;
|
|
72406
|
+
};
|
|
72407
|
+
PkgManifestIO.loadLock = function(src) {
|
|
72408
|
+
const lock = new PkgLock();
|
|
72409
|
+
const p = new PkgJson();
|
|
72410
|
+
const root = p.parse(src);
|
|
72411
|
+
if ( p.ok == false ) {
|
|
72412
|
+
lock.ok = false;
|
|
72413
|
+
lock.err = p.err;
|
|
72414
|
+
return lock;
|
|
72415
|
+
}
|
|
72416
|
+
lock.lockVersion = PkgJson.intOf(root, "lockVersion");
|
|
72417
|
+
if ( lock.lockVersion == 0 ) {
|
|
72418
|
+
lock.lockVersion = 1;
|
|
72419
|
+
}
|
|
72420
|
+
const pkgs = PkgJson.child(root, "packages");
|
|
72421
|
+
if ( typeof(pkgs) === "undefined" ) {
|
|
72422
|
+
return lock;
|
|
72423
|
+
}
|
|
72424
|
+
const o = pkgs;
|
|
72425
|
+
let i = 0;
|
|
72426
|
+
while (i < o.keys.length) {
|
|
72427
|
+
const e = new PkgLockEnt();
|
|
72428
|
+
e.name = o.keys[i];
|
|
72429
|
+
const spec = o.vals[i];
|
|
72430
|
+
e.path = PkgJson.strOf(spec, "path");
|
|
72431
|
+
e.git = PkgJson.strOf(spec, "git");
|
|
72432
|
+
e.rev = PkgJson.strOf(spec, "rev");
|
|
72433
|
+
e.subdir = PkgJson.strOf(spec, "subdir");
|
|
72434
|
+
e.sha256 = PkgJson.strOf(spec, "sha256");
|
|
72435
|
+
lock.packages.push(e);
|
|
72436
|
+
i = i + 1;
|
|
72437
|
+
};
|
|
72438
|
+
return lock;
|
|
72439
|
+
};
|
|
72440
|
+
PkgManifestIO.escape = function(s) {
|
|
72441
|
+
let out = "";
|
|
72442
|
+
const n = s.length;
|
|
72443
|
+
let i = 0;
|
|
72444
|
+
while (i < n) {
|
|
72445
|
+
const c = s.charCodeAt(i );
|
|
72446
|
+
if ( c == 34 ) {
|
|
72447
|
+
out = out + "\\\"";
|
|
72448
|
+
} else {
|
|
72449
|
+
if ( c == 92 ) {
|
|
72450
|
+
out = out + "\\\\";
|
|
72451
|
+
} else {
|
|
72452
|
+
if ( c == 10 ) {
|
|
72453
|
+
out = out + "\\n";
|
|
72454
|
+
} else {
|
|
72455
|
+
out = out + String.fromCharCode(c);
|
|
72456
|
+
}
|
|
72457
|
+
}
|
|
72458
|
+
}
|
|
72459
|
+
i = i + 1;
|
|
72460
|
+
};
|
|
72461
|
+
return out;
|
|
72462
|
+
};
|
|
72463
|
+
PkgManifestIO.dumpLock = function(lock) {
|
|
72464
|
+
let s = ("{\n \"lockVersion\": " + (lock.lockVersion.toString())) + ",\n \"packages\": {\n";
|
|
72465
|
+
let i = 0;
|
|
72466
|
+
const n = lock.packages.length;
|
|
72467
|
+
while (i < n) {
|
|
72468
|
+
const e = lock.packages[i];
|
|
72469
|
+
s = ((s + " \"") + PkgManifestIO.escape(e.name)) + "\": {\n";
|
|
72470
|
+
if ( e.path.length > 0 ) {
|
|
72471
|
+
s = ((s + " \"path\": \"") + PkgManifestIO.escape(e.path)) + "\"";
|
|
72472
|
+
}
|
|
72473
|
+
if ( e.git.length > 0 ) {
|
|
72474
|
+
if ( e.path.length > 0 ) {
|
|
72475
|
+
s = s + ",\n";
|
|
72476
|
+
}
|
|
72477
|
+
s = ((s + " \"git\": \"") + PkgManifestIO.escape(e.git)) + "\"";
|
|
72478
|
+
}
|
|
72479
|
+
if ( e.rev.length > 0 ) {
|
|
72480
|
+
s = ((s + ",\n \"rev\": \"") + PkgManifestIO.escape(e.rev)) + "\"";
|
|
72481
|
+
}
|
|
72482
|
+
if ( e.subdir.length > 0 ) {
|
|
72483
|
+
s = ((s + ",\n \"subdir\": \"") + PkgManifestIO.escape(e.subdir)) + "\"";
|
|
72484
|
+
}
|
|
72485
|
+
if ( e.sha256.length > 0 ) {
|
|
72486
|
+
s = ((s + ",\n \"sha256\": \"") + PkgManifestIO.escape(e.sha256)) + "\"";
|
|
72487
|
+
}
|
|
72488
|
+
s = s + "\n }";
|
|
72489
|
+
if ( i < n - 1 ) {
|
|
72490
|
+
s = s + ",";
|
|
72491
|
+
}
|
|
72492
|
+
s = s + "\n";
|
|
72493
|
+
i = i + 1;
|
|
72494
|
+
};
|
|
72495
|
+
s = s + " }\n}\n";
|
|
72496
|
+
return s;
|
|
72497
|
+
};
|
|
72498
|
+
PkgManifestIO.dumpManifest = function(m) {
|
|
72499
|
+
let s = ("{\n \"name\": \"" + PkgManifestIO.escape(m.name)) + "\",\n";
|
|
72500
|
+
s = ((s + " \"version\": \"") + PkgManifestIO.escape(m.version)) + "\",\n";
|
|
72501
|
+
s = ((s + " \"entry\": \"") + PkgManifestIO.escape(m.entry)) + "\"";
|
|
72502
|
+
if ( m.license.length > 0 ) {
|
|
72503
|
+
s = ((s + ",\n \"license\": \"") + PkgManifestIO.escape(m.license)) + "\"";
|
|
72504
|
+
}
|
|
72505
|
+
if ( m.deps.length > 0 ) {
|
|
72506
|
+
s = s + ",\n \"dependencies\": {\n";
|
|
72507
|
+
let i = 0;
|
|
72508
|
+
const n = m.deps.length;
|
|
72509
|
+
while (i < n) {
|
|
72510
|
+
const d = m.deps[i];
|
|
72511
|
+
s = ((s + " \"") + PkgManifestIO.escape(d.name)) + "\": {";
|
|
72512
|
+
let first = true;
|
|
72513
|
+
if ( d.path.length > 0 ) {
|
|
72514
|
+
s = ((s + " \"path\": \"") + PkgManifestIO.escape(d.path)) + "\"";
|
|
72515
|
+
first = false;
|
|
72516
|
+
}
|
|
72517
|
+
if ( d.git.length > 0 ) {
|
|
72518
|
+
if ( first ) {
|
|
72519
|
+
} else {
|
|
72520
|
+
s = s + ",";
|
|
72521
|
+
}
|
|
72522
|
+
s = ((s + " \"git\": \"") + PkgManifestIO.escape(d.git)) + "\"";
|
|
72523
|
+
first = false;
|
|
72524
|
+
}
|
|
72525
|
+
if ( d.rev.length > 0 ) {
|
|
72526
|
+
s = ((s + ", \"rev\": \"") + PkgManifestIO.escape(d.rev)) + "\"";
|
|
72527
|
+
}
|
|
72528
|
+
if ( d.tag.length > 0 ) {
|
|
72529
|
+
s = ((s + ", \"tag\": \"") + PkgManifestIO.escape(d.tag)) + "\"";
|
|
72530
|
+
}
|
|
72531
|
+
if ( d.subdir.length > 0 ) {
|
|
72532
|
+
s = ((s + ", \"subdir\": \"") + PkgManifestIO.escape(d.subdir)) + "\"";
|
|
72533
|
+
}
|
|
72534
|
+
s = s + " }";
|
|
72535
|
+
if ( i < n - 1 ) {
|
|
72536
|
+
s = s + ",";
|
|
72537
|
+
}
|
|
72538
|
+
s = s + "\n";
|
|
72539
|
+
i = i + 1;
|
|
72540
|
+
};
|
|
72541
|
+
s = s + " }";
|
|
72542
|
+
}
|
|
72543
|
+
s = s + "\n}\n";
|
|
72544
|
+
return s;
|
|
72545
|
+
};
|
|
72546
|
+
class PkgCache {
|
|
72547
|
+
constructor() {
|
|
72548
|
+
}
|
|
72549
|
+
}
|
|
72550
|
+
PkgCache.lessStr = function(a, b) {
|
|
72551
|
+
const na = a.length;
|
|
72552
|
+
const nb = b.length;
|
|
72553
|
+
let n = na;
|
|
72554
|
+
if ( nb < na ) {
|
|
72555
|
+
n = nb;
|
|
72556
|
+
}
|
|
72557
|
+
let i = 0;
|
|
72558
|
+
while (i < n) {
|
|
72559
|
+
const ca = a.charCodeAt(i );
|
|
72560
|
+
const cb = b.charCodeAt(i );
|
|
72561
|
+
if ( ca < cb ) {
|
|
72562
|
+
return true;
|
|
72563
|
+
}
|
|
72564
|
+
if ( cb < ca ) {
|
|
72565
|
+
return false;
|
|
72566
|
+
}
|
|
72567
|
+
i = i + 1;
|
|
72568
|
+
};
|
|
72569
|
+
return na < nb;
|
|
72570
|
+
};
|
|
72571
|
+
PkgCache.hashMem = function(mem) {
|
|
72572
|
+
let names = [];
|
|
72573
|
+
let i = 0;
|
|
72574
|
+
while (i < mem.paths.length) {
|
|
72575
|
+
names.push(mem.paths[i]);
|
|
72576
|
+
i = i + 1;
|
|
72577
|
+
};
|
|
72578
|
+
const n = names.length;
|
|
72579
|
+
let a = 0;
|
|
72580
|
+
while (a < n) {
|
|
72581
|
+
let b = a + 1;
|
|
72582
|
+
while (b < n) {
|
|
72583
|
+
const sa = names[a];
|
|
72584
|
+
const sb = names[b];
|
|
72585
|
+
if ( PkgCache.lessStr(sb, sa) ) {
|
|
72586
|
+
names[a] = sb;
|
|
72587
|
+
names[b] = sa;
|
|
72588
|
+
}
|
|
72589
|
+
b = b + 1;
|
|
72590
|
+
};
|
|
72591
|
+
a = a + 1;
|
|
72592
|
+
};
|
|
72593
|
+
let acc = "";
|
|
72594
|
+
i = 0;
|
|
72595
|
+
while (i < n) {
|
|
72596
|
+
const p = names[i];
|
|
72597
|
+
acc = (acc + p) + "\n";
|
|
72598
|
+
if ( ( typeof(mem.byPath[p] ) != "undefined" && Object.prototype.hasOwnProperty.call(mem.byPath, p) ) ) {
|
|
72599
|
+
const f = ( Object.prototype.hasOwnProperty.call(mem.byPath, p) ? mem.byPath[p] : undefined );
|
|
72600
|
+
acc = (acc + ((function(b){ var v = (b instanceof Uint8Array) ? b : new Uint8Array(b); var s = ""; var i = 0; var n = v.length; var c = 32768; while (i < n) { var e = i + c; if (e > n) { e = n; } s += String.fromCharCode.apply(null, v.subarray(i, e)); i = e; } return s; })(f.data))) + "\n";
|
|
72601
|
+
}
|
|
72602
|
+
i = i + 1;
|
|
72603
|
+
};
|
|
72604
|
+
if ( acc.length == 0 ) {
|
|
72605
|
+
return "";
|
|
72606
|
+
}
|
|
72607
|
+
return require('crypto')
|
|
72608
|
+
.createHash('sha256')
|
|
72609
|
+
.update(acc)
|
|
72610
|
+
.digest('hex');
|
|
72611
|
+
};
|
|
72612
|
+
PkgCache.put = function(mem, cacheRoot) {
|
|
72613
|
+
const hash = PkgCache.hashMem(mem);
|
|
72614
|
+
if ( hash.length == 0 ) {
|
|
72615
|
+
return "";
|
|
72616
|
+
}
|
|
72617
|
+
const dest = (cacheRoot + "/") + hash;
|
|
72618
|
+
require("fs").mkdirSync( dest, { recursive: true });
|
|
72619
|
+
const store = new GitStore(new GitPack());
|
|
72620
|
+
store.writeDisk(mem, dest);
|
|
72621
|
+
return hash;
|
|
72622
|
+
};
|
|
72623
|
+
PkgCache.lockFor = function(name, git, rev, subdir, hash) {
|
|
72624
|
+
const e = new PkgLockEnt();
|
|
72625
|
+
e.name = name;
|
|
72626
|
+
e.git = git;
|
|
72627
|
+
e.rev = rev;
|
|
72628
|
+
e.subdir = subdir;
|
|
72629
|
+
e.sha256 = hash;
|
|
72630
|
+
return e;
|
|
72631
|
+
};
|
|
72632
|
+
class PkgFetchWork {
|
|
72633
|
+
constructor() {
|
|
72634
|
+
this.dir = "";
|
|
72635
|
+
this.man = new PkgManifest();
|
|
72636
|
+
this.git = "";
|
|
72637
|
+
this.rev = "";
|
|
72638
|
+
this.subdir = "";
|
|
72639
|
+
this.fromGit = false;
|
|
72640
|
+
}
|
|
72641
|
+
}
|
|
72642
|
+
class PkgFetch {
|
|
72643
|
+
constructor() {
|
|
72644
|
+
this.ok = true;
|
|
72645
|
+
this.err = "";
|
|
72646
|
+
this.cacheRoot = "";
|
|
72647
|
+
this.cacheOverride = "";
|
|
72648
|
+
this.rootDir = "";
|
|
72649
|
+
this.tmpRoot = "";
|
|
72650
|
+
this.httpTool = "";
|
|
72651
|
+
this.vendor = false;
|
|
72652
|
+
this.frozen = false;
|
|
72653
|
+
this.force = false;
|
|
72654
|
+
this.lock = new PkgLock();
|
|
72655
|
+
this.previous = new PkgLock();
|
|
72656
|
+
this.seen = {};
|
|
72657
|
+
this.lastRev = "";
|
|
72658
|
+
this.lastMem = new GitMem();
|
|
72659
|
+
}
|
|
72660
|
+
runHttp (args) {
|
|
72661
|
+
let argv = [];
|
|
72662
|
+
argv.push(this.httpTool);
|
|
72663
|
+
let i = 0;
|
|
72664
|
+
while (i < args.length) {
|
|
72665
|
+
argv.push(args[i]);
|
|
72666
|
+
i = i + 1;
|
|
72667
|
+
};
|
|
72668
|
+
let noEnv = [];
|
|
72669
|
+
const out = r_process_result(
|
|
72670
|
+
"node",
|
|
72671
|
+
argv,
|
|
72672
|
+
"",
|
|
72673
|
+
true,
|
|
72674
|
+
noEnv
|
|
72675
|
+
);
|
|
72676
|
+
if ( out.length < 3 ) {
|
|
72677
|
+
this.err = "could not run node";
|
|
72678
|
+
return false;
|
|
72679
|
+
}
|
|
72680
|
+
if ( out[0] == "0" ) {
|
|
72681
|
+
return true;
|
|
72682
|
+
}
|
|
72683
|
+
this.err = out[2];
|
|
72684
|
+
return false;
|
|
72685
|
+
};
|
|
72686
|
+
advertise (url, dest) {
|
|
72687
|
+
let args = [];
|
|
72688
|
+
args.push("advertise");
|
|
72689
|
+
args.push(url);
|
|
72690
|
+
args.push(dest);
|
|
72691
|
+
return this.runHttp(args);
|
|
72692
|
+
};
|
|
72693
|
+
post (url, body, dest) {
|
|
72694
|
+
let args = [];
|
|
72695
|
+
args.push("post");
|
|
72696
|
+
args.push(url);
|
|
72697
|
+
args.push(body);
|
|
72698
|
+
args.push(dest);
|
|
72699
|
+
return this.runHttp(args);
|
|
72700
|
+
};
|
|
72701
|
+
fetchInto (name, url, wantRev, subdir) {
|
|
72702
|
+
this.lastRev = "";
|
|
72703
|
+
require("fs").mkdirSync( this.tmpRoot, { recursive: true });
|
|
72704
|
+
const adv = ((this.tmpRoot + "/") + name) + ".advertise.bin";
|
|
72705
|
+
if ( this.advertise(url, adv) == false ) {
|
|
72706
|
+
return "";
|
|
72707
|
+
}
|
|
72708
|
+
const advert = GitPktIO.parseAdvertisement(PkgFetch.readBytes(adv));
|
|
72709
|
+
if ( advert.ok == false ) {
|
|
72710
|
+
this.err = (("could not read the advertisement of " + url) + ": ") + advert.err;
|
|
72711
|
+
return "";
|
|
72712
|
+
}
|
|
72713
|
+
if ( subdir.length == 0 ) {
|
|
72714
|
+
const commitSha = GitPktIO.findRef(advert, wantRev);
|
|
72715
|
+
if ( commitSha.length == 0 ) {
|
|
72716
|
+
this.err = (url + " has no ") + wantRev;
|
|
72717
|
+
return "";
|
|
72718
|
+
}
|
|
72719
|
+
let extras = [];
|
|
72720
|
+
const wholeWant = GitPktIO.buildWantFetch(
|
|
72721
|
+
commitSha,
|
|
72722
|
+
1,
|
|
72723
|
+
"",
|
|
72724
|
+
extras
|
|
72725
|
+
);
|
|
72726
|
+
if ( wholeWant.ok == false ) {
|
|
72727
|
+
this.err = wholeWant.err;
|
|
72728
|
+
return "";
|
|
72729
|
+
}
|
|
72730
|
+
const wantPath = ((this.tmpRoot + "/") + name) + ".want.bin";
|
|
72731
|
+
const packPath = ((this.tmpRoot + "/") + name) + ".pack.bin";
|
|
72732
|
+
PkgFetch.writeBytes(wantPath, wholeWant.body);
|
|
72733
|
+
if ( this.post(url, wantPath, packPath) == false ) {
|
|
72734
|
+
return "";
|
|
72735
|
+
}
|
|
72736
|
+
const whole = PkgFetch.loadPack(packPath);
|
|
72737
|
+
if ( whole.ok == false ) {
|
|
72738
|
+
this.err = whole.err;
|
|
72739
|
+
return "";
|
|
72740
|
+
}
|
|
72741
|
+
const wholeStore = new GitStore(whole);
|
|
72742
|
+
const wholeMem = wholeStore.checkout(commitSha, "");
|
|
72743
|
+
if ( wholeStore.ok == false ) {
|
|
72744
|
+
this.err = wholeStore.err;
|
|
72745
|
+
return "";
|
|
72746
|
+
}
|
|
72747
|
+
this.lastRev = commitSha;
|
|
72748
|
+
return this.storeMem(wholeMem);
|
|
72749
|
+
}
|
|
72750
|
+
const treeWant = GitPktIO.buildWantTrees(advert, wantRev);
|
|
72751
|
+
if ( treeWant.ok == false ) {
|
|
72752
|
+
this.err = treeWant.err;
|
|
72753
|
+
return "";
|
|
72754
|
+
}
|
|
72755
|
+
const commit = treeWant.sha;
|
|
72756
|
+
const twPath = ((this.tmpRoot + "/") + name) + ".want-trees.bin";
|
|
72757
|
+
const treesPath = ((this.tmpRoot + "/") + name) + ".trees.bin";
|
|
72758
|
+
PkgFetch.writeBytes(twPath, treeWant.body);
|
|
72759
|
+
if ( this.post(url, twPath, treesPath) == false ) {
|
|
72760
|
+
return "";
|
|
72761
|
+
}
|
|
72762
|
+
const trees = PkgFetch.loadPack(treesPath);
|
|
72763
|
+
if ( trees.ok == false ) {
|
|
72764
|
+
this.err = trees.err;
|
|
72765
|
+
return "";
|
|
72766
|
+
}
|
|
72767
|
+
const treeStore = new GitStore(trees);
|
|
72768
|
+
const treeSha = treeStore.treeAt(commit, subdir);
|
|
72769
|
+
if ( treeStore.ok == false ) {
|
|
72770
|
+
this.err = (((((url + " has no ") + subdir) + " at ") + commit) + ": ") + treeStore.err;
|
|
72771
|
+
return "";
|
|
72772
|
+
}
|
|
72773
|
+
const blobWant = GitPktIO.buildWantSha(treeSha);
|
|
72774
|
+
if ( blobWant.ok == false ) {
|
|
72775
|
+
this.err = blobWant.err;
|
|
72776
|
+
return "";
|
|
72777
|
+
}
|
|
72778
|
+
const bwPath = ((this.tmpRoot + "/") + name) + ".want-blobs.bin";
|
|
72779
|
+
const blobsPath = ((this.tmpRoot + "/") + name) + ".blobs.bin";
|
|
72780
|
+
PkgFetch.writeBytes(bwPath, blobWant.body);
|
|
72781
|
+
if ( this.post(url, bwPath, blobsPath) == false ) {
|
|
72782
|
+
return "";
|
|
72783
|
+
}
|
|
72784
|
+
const blobs = PkgFetch.loadPack(blobsPath);
|
|
72785
|
+
if ( blobs.ok == false ) {
|
|
72786
|
+
this.err = blobs.err;
|
|
72787
|
+
return "";
|
|
72788
|
+
}
|
|
72789
|
+
const merged = GitPackIO.merge(trees, blobs);
|
|
72790
|
+
if ( merged.ok == false ) {
|
|
72791
|
+
this.err = merged.err;
|
|
72792
|
+
return "";
|
|
72793
|
+
}
|
|
72794
|
+
const store = new GitStore(merged);
|
|
72795
|
+
const mem = store.checkout(commit, subdir);
|
|
72796
|
+
if ( store.ok == false ) {
|
|
72797
|
+
this.err = store.err;
|
|
72798
|
+
return "";
|
|
72799
|
+
}
|
|
72800
|
+
this.lastRev = commit;
|
|
72801
|
+
return this.storeMem(mem);
|
|
72802
|
+
};
|
|
72803
|
+
storeMem (mem) {
|
|
72804
|
+
this.lastMem = mem;
|
|
72805
|
+
require("fs").mkdirSync( this.cacheRoot, { recursive: true });
|
|
72806
|
+
const hash = PkgCache.put(mem, this.cacheRoot);
|
|
72807
|
+
if ( hash.length == 0 ) {
|
|
72808
|
+
this.err = "the checkout was empty";
|
|
72809
|
+
return "";
|
|
72810
|
+
}
|
|
72811
|
+
return hash;
|
|
72812
|
+
};
|
|
72813
|
+
cachedFor (env, name, git, rev, subdir) {
|
|
72814
|
+
if ( this.force ) {
|
|
72815
|
+
return "";
|
|
72816
|
+
}
|
|
72817
|
+
let i = 0;
|
|
72818
|
+
while (i < this.previous.packages.length) {
|
|
72819
|
+
const e = this.previous.packages[i];
|
|
72820
|
+
i = i + 1;
|
|
72821
|
+
if ( e.name == name ) {
|
|
72822
|
+
if ( e.sha256.length == 0 ) {
|
|
72823
|
+
return "";
|
|
72824
|
+
}
|
|
72825
|
+
if ( e.git != git ) {
|
|
72826
|
+
return "";
|
|
72827
|
+
}
|
|
72828
|
+
if ( rev.length > 0 ) {
|
|
72829
|
+
if ( e.rev != rev ) {
|
|
72830
|
+
return "";
|
|
72831
|
+
}
|
|
72832
|
+
}
|
|
72833
|
+
if ( e.subdir != subdir ) {
|
|
72834
|
+
return "";
|
|
72835
|
+
}
|
|
72836
|
+
const dir = PkgImport.joinPath(this.cacheRoot, e.sha256);
|
|
72837
|
+
if ( operatorsOf_8.filec95exists_9(env, dir, "ranger.json") ) {
|
|
72838
|
+
this.lastRev = e.rev;
|
|
72839
|
+
return e.sha256;
|
|
72840
|
+
}
|
|
72841
|
+
return "";
|
|
72842
|
+
}
|
|
72843
|
+
};
|
|
72844
|
+
return "";
|
|
72845
|
+
};
|
|
72846
|
+
async install (env, manDir) {
|
|
72847
|
+
this.ok = true;
|
|
72848
|
+
this.err = "";
|
|
72849
|
+
this.cacheRoot = PkgImport.cacheRoot();
|
|
72850
|
+
if ( this.cacheOverride.length > 0 ) {
|
|
72851
|
+
this.cacheRoot = this.cacheOverride;
|
|
72852
|
+
}
|
|
72853
|
+
this.tmpRoot = PkgImport.joinPath(this.cacheRoot, ".fetch");
|
|
72854
|
+
this.httpTool = PkgFetch.findHttpTool(env);
|
|
72855
|
+
if ( this.httpTool.length == 0 ) {
|
|
72856
|
+
this.err = "git-http.mjs is not beside rgrc";
|
|
72857
|
+
return false;
|
|
72858
|
+
}
|
|
72859
|
+
this.rootDir = manDir;
|
|
72860
|
+
const rootText = await PkgImport.readText(
|
|
72861
|
+
env,
|
|
72862
|
+
manDir,
|
|
72863
|
+
"ranger.json"
|
|
72864
|
+
);
|
|
72865
|
+
if ( rootText.length == 0 ) {
|
|
72866
|
+
this.err = manDir + "/ranger.json is empty or unreadable";
|
|
72867
|
+
return false;
|
|
72868
|
+
}
|
|
72869
|
+
const rootMan = PkgManifestIO.load(rootText);
|
|
72870
|
+
if ( rootMan.ok == false ) {
|
|
72871
|
+
this.err = (manDir + "/ranger.json: ") + rootMan.err;
|
|
72872
|
+
return false;
|
|
72873
|
+
}
|
|
72874
|
+
const lockText = await PkgImport.readText(
|
|
72875
|
+
env,
|
|
72876
|
+
manDir,
|
|
72877
|
+
"ranger.lock"
|
|
72878
|
+
);
|
|
72879
|
+
if ( lockText.length > 0 ) {
|
|
72880
|
+
this.previous = PkgManifestIO.loadLock(lockText);
|
|
72881
|
+
}
|
|
72882
|
+
let pending = [];
|
|
72883
|
+
const first = new PkgFetchWork();
|
|
72884
|
+
first.dir = manDir;
|
|
72885
|
+
first.man = rootMan;
|
|
72886
|
+
pending.push(first);
|
|
72887
|
+
let qi = 0;
|
|
72888
|
+
while (qi < pending.length) {
|
|
72889
|
+
const w = pending[qi];
|
|
72890
|
+
qi = qi + 1;
|
|
72891
|
+
let di = 0;
|
|
72892
|
+
while (di < w.man.deps.length) {
|
|
72893
|
+
const d = w.man.deps[di];
|
|
72894
|
+
di = di + 1;
|
|
72895
|
+
if ( ( typeof(this.seen[d.name] ) != "undefined" && Object.prototype.hasOwnProperty.call(this.seen, d.name) ) ) {
|
|
72896
|
+
} else {
|
|
72897
|
+
this.seen[d.name] = true;
|
|
72898
|
+
if ( await this.oneDep(env, pending, w, d) == false ) {
|
|
72899
|
+
return false;
|
|
72900
|
+
}
|
|
72901
|
+
}
|
|
72902
|
+
};
|
|
72903
|
+
};
|
|
72904
|
+
const out = PkgManifestIO.dumpLock(this.lock);
|
|
72905
|
+
require('fs').writeFileSync(manDir + '/' + "ranger.lock", Buffer.from((function(s){ var b = new ArrayBuffer(s.length); var v = new Uint8Array(b); for(var i=0;i<s.length;i++)v[i]=s.charCodeAt(i); b._view = new DataView(b); return b; })(out)));
|
|
72906
|
+
console.log(("wrote " + manDir) + "/ranger.lock");
|
|
72907
|
+
return true;
|
|
72908
|
+
};
|
|
72909
|
+
async oneDep (env, pending, w, d) {
|
|
72910
|
+
let git = d.git;
|
|
72911
|
+
let rev = d.rev;
|
|
72912
|
+
let subdir = d.subdir;
|
|
72913
|
+
if ( rev.length == 0 ) {
|
|
72914
|
+
rev = d.tag;
|
|
72915
|
+
}
|
|
72916
|
+
let localPath = d.path;
|
|
72917
|
+
if ( localPath.length > 0 ) {
|
|
72918
|
+
if ( w.fromGit ) {
|
|
72919
|
+
git = w.git;
|
|
72920
|
+
rev = w.rev;
|
|
72921
|
+
subdir = PkgImport.foldPath(PkgImport.joinPath(w.subdir, localPath));
|
|
72922
|
+
localPath = "";
|
|
72923
|
+
if ( subdir.length == 0 ) {
|
|
72924
|
+
this.err = (((d.name + ": ") + d.path) + " climbs out of ") + w.git;
|
|
72925
|
+
return false;
|
|
72926
|
+
}
|
|
72927
|
+
}
|
|
72928
|
+
}
|
|
72929
|
+
const entry = new PkgLockEnt();
|
|
72930
|
+
entry.name = d.name;
|
|
72931
|
+
let pkgDir = "";
|
|
72932
|
+
let childFromGit = false;
|
|
72933
|
+
if ( localPath.length > 0 ) {
|
|
72934
|
+
pkgDir = PkgImport.foldPath(PkgImport.joinPath(w.dir, localPath));
|
|
72935
|
+
if ( operatorsOf_8.filec95exists_9(env, pkgDir, "ranger.json") == false ) {
|
|
72936
|
+
this.err = (d.name + ": no ranger.json under ") + localPath;
|
|
72937
|
+
return false;
|
|
72938
|
+
}
|
|
72939
|
+
entry.path = localPath;
|
|
72940
|
+
console.log((d.name + " path ") + localPath);
|
|
72941
|
+
} else {
|
|
72942
|
+
if ( git.length == 0 ) {
|
|
72943
|
+
this.err = d.name + ": the dependency has neither \"path\" nor \"git\"";
|
|
72944
|
+
return false;
|
|
72945
|
+
}
|
|
72946
|
+
if ( rev.length == 0 ) {
|
|
72947
|
+
rev = "HEAD";
|
|
72948
|
+
}
|
|
72949
|
+
let hash = this.cachedFor(
|
|
72950
|
+
env,
|
|
72951
|
+
d.name,
|
|
72952
|
+
git,
|
|
72953
|
+
rev,
|
|
72954
|
+
subdir
|
|
72955
|
+
);
|
|
72956
|
+
let reused = hash.length > 0;
|
|
72957
|
+
if ( reused ) {
|
|
72958
|
+
if ( this.vendor ) {
|
|
72959
|
+
const already = PkgImport.joinPath(this.rootDir, ("vendor/ranger/" + d.name));
|
|
72960
|
+
if ( operatorsOf_8.filec95exists_9(env, already, "ranger.json") == false ) {
|
|
72961
|
+
reused = false;
|
|
72962
|
+
hash = "";
|
|
72963
|
+
}
|
|
72964
|
+
}
|
|
72965
|
+
}
|
|
72966
|
+
if ( reused == false ) {
|
|
72967
|
+
if ( this.frozen ) {
|
|
72968
|
+
this.err = d.name + ": ranger.lock does not cover it at this revision, and -frozen was asked for";
|
|
72969
|
+
return false;
|
|
72970
|
+
}
|
|
72971
|
+
hash = this.fetchInto(d.name, git, rev, subdir);
|
|
72972
|
+
if ( hash.length == 0 ) {
|
|
72973
|
+
if ( this.err.length == 0 ) {
|
|
72974
|
+
this.err = (d.name + ": could not fetch ") + git;
|
|
72975
|
+
}
|
|
72976
|
+
return false;
|
|
72977
|
+
}
|
|
72978
|
+
}
|
|
72979
|
+
pkgDir = PkgImport.joinPath(this.cacheRoot, hash);
|
|
72980
|
+
entry.git = git;
|
|
72981
|
+
entry.rev = this.lastRev;
|
|
72982
|
+
entry.subdir = subdir;
|
|
72983
|
+
entry.sha256 = hash;
|
|
72984
|
+
childFromGit = true;
|
|
72985
|
+
let note = "";
|
|
72986
|
+
if ( reused ) {
|
|
72987
|
+
note = " (cached)";
|
|
72988
|
+
}
|
|
72989
|
+
console.log(((((d.name + " ") + this.lastRev) + " -> ") + pkgDir) + note);
|
|
72990
|
+
if ( this.vendor ) {
|
|
72991
|
+
if ( reused == false ) {
|
|
72992
|
+
const vdir = PkgImport.joinPath(this.rootDir, ("vendor/ranger/" + d.name));
|
|
72993
|
+
require("fs").mkdirSync( vdir, { recursive: true });
|
|
72994
|
+
const writer = new GitStore(new GitPack());
|
|
72995
|
+
writer.writeDisk(this.lastMem, vdir);
|
|
72996
|
+
console.log((d.name + " vendored -> vendor/ranger/") + d.name);
|
|
72997
|
+
}
|
|
72998
|
+
}
|
|
72999
|
+
}
|
|
73000
|
+
this.lock.packages.push(entry);
|
|
73001
|
+
const childText = await PkgImport.readText(
|
|
73002
|
+
env,
|
|
73003
|
+
pkgDir,
|
|
73004
|
+
"ranger.json"
|
|
73005
|
+
);
|
|
73006
|
+
if ( childText.length > 0 ) {
|
|
73007
|
+
const childMan = PkgManifestIO.load(childText);
|
|
73008
|
+
if ( childMan.ok ) {
|
|
73009
|
+
const next = new PkgFetchWork();
|
|
73010
|
+
next.dir = pkgDir;
|
|
73011
|
+
next.man = childMan;
|
|
73012
|
+
next.git = entry.git;
|
|
73013
|
+
next.rev = entry.rev;
|
|
73014
|
+
next.subdir = entry.subdir;
|
|
73015
|
+
next.fromGit = childFromGit;
|
|
73016
|
+
pending.push(next);
|
|
73017
|
+
}
|
|
73018
|
+
}
|
|
73019
|
+
return true;
|
|
73020
|
+
};
|
|
73021
|
+
}
|
|
73022
|
+
PkgFetch.findHttpTool = function(env) {
|
|
73023
|
+
const idir = __dirname;
|
|
73024
|
+
if ( operatorsOf_8.filec95exists_9(env, idir, "git-http.mjs") ) {
|
|
73025
|
+
return idir + "/git-http.mjs";
|
|
73026
|
+
}
|
|
73027
|
+
const up = PkgImport.joinPath(PkgImport.parentDir(idir), "bin");
|
|
73028
|
+
if ( operatorsOf_8.filec95exists_9(env, up, "git-http.mjs") ) {
|
|
73029
|
+
return up + "/git-http.mjs";
|
|
73030
|
+
}
|
|
73031
|
+
return "";
|
|
73032
|
+
};
|
|
73033
|
+
PkgFetch.splitPath = function(path) {
|
|
73034
|
+
let parts = [];
|
|
73035
|
+
parts.push(PkgImport.parentDir(path));
|
|
73036
|
+
const d = parts[0];
|
|
73037
|
+
const n = path.length;
|
|
73038
|
+
let cut = d.length + 1;
|
|
73039
|
+
if ( d.length == 0 ) {
|
|
73040
|
+
parts[0] = ".";
|
|
73041
|
+
cut = 0;
|
|
73042
|
+
}
|
|
73043
|
+
parts.push(path.substring(cut, n ));
|
|
73044
|
+
return parts;
|
|
73045
|
+
};
|
|
73046
|
+
PkgFetch.readBytes = function(path) {
|
|
73047
|
+
const parts = PkgFetch.splitPath(path);
|
|
73048
|
+
return (function(){ var b = require('fs').readFileSync(parts[0] + '/' + parts[1]); var ab = new ArrayBuffer(b.length); var v = new Uint8Array(ab); for(var i=0;i<b.length;i++)v[i]=b[i]; ab._view = new DataView(ab); return ab; })();
|
|
73049
|
+
};
|
|
73050
|
+
PkgFetch.writeBytes = function(path, data) {
|
|
73051
|
+
const parts = PkgFetch.splitPath(path);
|
|
73052
|
+
require('fs').writeFileSync(parts[0] + '/' + parts[1], Buffer.from(data));
|
|
73053
|
+
};
|
|
73054
|
+
PkgFetch.loadPack = function(path) {
|
|
73055
|
+
const data = PkgFetch.readBytes(path);
|
|
73056
|
+
const sb = GitPktIO.demux(data);
|
|
73057
|
+
let raw = data;
|
|
73058
|
+
if ( sb.ok ) {
|
|
73059
|
+
if ( sb.pack.byteLength > 0 ) {
|
|
73060
|
+
raw = sb.pack;
|
|
73061
|
+
}
|
|
73062
|
+
}
|
|
73063
|
+
return GitPackIO.parse(raw);
|
|
73064
|
+
};
|
|
69650
73065
|
class RangerDocGenerator {
|
|
69651
73066
|
constructor() {
|
|
69652
73067
|
}
|
|
@@ -73379,6 +76794,28 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
73379
76794
|
const ext = filename.substring((lastDot + 1), filename.length );
|
|
73380
76795
|
return ext == "ts";
|
|
73381
76796
|
};
|
|
76797
|
+
async runInstall (env, params, cli) {
|
|
76798
|
+
const start = operatorsOf_8.currentc95directory_51(env);
|
|
76799
|
+
const manDir = PkgImport.walkUp(env, start);
|
|
76800
|
+
if ( manDir.length == 0 ) {
|
|
76801
|
+
console.log(cli.error((("no ranger.json in " + start) + " or above it")));
|
|
76802
|
+
return false;
|
|
76803
|
+
}
|
|
76804
|
+
const fetch = new PkgFetch();
|
|
76805
|
+
fetch.vendor = ( typeof(params.flags["vendor"] ) != "undefined" && Object.prototype.hasOwnProperty.call(params.flags, "vendor") );
|
|
76806
|
+
fetch.frozen = ( typeof(params.flags["frozen"] ) != "undefined" && Object.prototype.hasOwnProperty.call(params.flags, "frozen") ) || ( typeof(params.flags["frozen-lockfile"] ) != "undefined" && Object.prototype.hasOwnProperty.call(params.flags, "frozen-lockfile") );
|
|
76807
|
+
fetch.force = ( typeof(params.flags["force"] ) != "undefined" && Object.prototype.hasOwnProperty.call(params.flags, "force") );
|
|
76808
|
+
const cacheOpt = params.getParam("cache");
|
|
76809
|
+
if ( (typeof(cacheOpt) !== "undefined" && cacheOpt != null ) ) {
|
|
76810
|
+
fetch.cacheOverride = cacheOpt;
|
|
76811
|
+
}
|
|
76812
|
+
const done = await fetch.install(env, manDir);
|
|
76813
|
+
if ( done ) {
|
|
76814
|
+
return true;
|
|
76815
|
+
}
|
|
76816
|
+
console.log(cli.error(fetch.err));
|
|
76817
|
+
return false;
|
|
76818
|
+
};
|
|
73382
76819
|
async run (env) {
|
|
73383
76820
|
const res = new CompilerResults();
|
|
73384
76821
|
this.envObj = env;
|
|
@@ -73388,6 +76825,15 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
73388
76825
|
if ( ( typeof(params.flags["no-color"] ) != "undefined" && Object.prototype.hasOwnProperty.call(params.flags, "no-color") ) ) {
|
|
73389
76826
|
cli.setUseColors(false);
|
|
73390
76827
|
}
|
|
76828
|
+
if ( params.values.length > 0 ) {
|
|
76829
|
+
if ( params.values[0] == "install" ) {
|
|
76830
|
+
if ( await this.runInstall(env, params, cli) ) {
|
|
76831
|
+
return res;
|
|
76832
|
+
}
|
|
76833
|
+
res.hasErrors = true;
|
|
76834
|
+
return res;
|
|
76835
|
+
}
|
|
76836
|
+
}
|
|
73391
76837
|
let the_file = "";
|
|
73392
76838
|
let plugins_only = false;
|
|
73393
76839
|
const valid_options = ["l", "Selected language, one of " + allowed_languages.join(", "), "d", "output directory, default directory is \"bin/\"", "o", "output file, default is \"output.<language>\"", "classdoc", "write class documentation .md file", "operatordoc", "write operator documention into .md file", "apidoc", "write the API documentation artifacts into this subdirectory", "apiformat", "which API artifacts to write: json, markdown, report (default json,markdown)", "format", "Output formatting: \"ranger\" (the default) drops parentheses a target does not need and breaks a long method chain onto one line per call; \"none\" emits exactly what the writers emit", "width", "Line width the formatter aims at, when -format is not none. Defaults to the target ecosystems own: 80 on JavaScript, Dart and C++, 100 elsewhere", "csnamespace", "C# namespace for the generated types", "ktpackage", "Kotlin package for the generated types"];
|
|
@@ -73401,6 +76847,13 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
73401
76847
|
} else {
|
|
73402
76848
|
if ( params.values.length < 1 ) {
|
|
73403
76849
|
cli.printHelpHeader();
|
|
76850
|
+
cli.printSection("Commands:");
|
|
76851
|
+
console.log((" " + cli.bold("install")) + " fetch the packages the nearest ranger.json names into the");
|
|
76852
|
+
console.log(" package cache and write ranger.lock.");
|
|
76853
|
+
console.log(cli.gray(" -vendor also write vendor/ranger/<name>"));
|
|
76854
|
+
console.log(cli.gray(" -frozen fail rather than fetch what the lock does not cover"));
|
|
76855
|
+
console.log(cli.gray(" -force refetch even when the locked checkout is cached"));
|
|
76856
|
+
console.log(cli.gray(" -cache=<dir> instead of RANGER_PKG_CACHE"));
|
|
73404
76857
|
cli.printSection("Options:");
|
|
73405
76858
|
let optCnt = 0;
|
|
73406
76859
|
while (optCnt < valid_options.length) {
|
|
@@ -73576,7 +77029,12 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
73576
77029
|
comp_attrs["o"] = the_target;
|
|
73577
77030
|
const dirParam = params.getParam("d");
|
|
73578
77031
|
if ( (typeof(dirParam) !== "undefined" && dirParam != null ) ) {
|
|
73579
|
-
|
|
77032
|
+
const dirGiven = dirParam;
|
|
77033
|
+
if ( dirGiven.length > 0 && dirGiven.charCodeAt(0 ) == 47 ) {
|
|
77034
|
+
the_target_dir = dirGiven;
|
|
77035
|
+
} else {
|
|
77036
|
+
the_target_dir = (operatorsOf_8.currentc95directory_51(env) + "/") + dirGiven;
|
|
77037
|
+
}
|
|
73580
77038
|
}
|
|
73581
77039
|
the_target_dir = require("path").normalize(the_target_dir);
|
|
73582
77040
|
comp_attrs["d"] = the_target_dir;
|
|
@@ -74532,9 +77990,9 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
74532
77990
|
};
|
|
74533
77991
|
operatorsOf.filter_52 = function(__self, cb) {
|
|
74534
77992
|
let res_13 = [];
|
|
74535
|
-
for ( let
|
|
74536
|
-
var it_19 = __self[
|
|
74537
|
-
if ( cb(it_19,
|
|
77993
|
+
for ( let i_29 = 0; i_29 < __self.length; i_29++) {
|
|
77994
|
+
var it_19 = __self[i_29];
|
|
77995
|
+
if ( cb(it_19, i_29) ) {
|
|
74538
77996
|
res_13.push(it_19);
|
|
74539
77997
|
}
|
|
74540
77998
|
};
|
|
@@ -74543,8 +78001,8 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
74543
78001
|
operatorsOf.groupBy_53 = function(__self, cb) {
|
|
74544
78002
|
let res_14 = [];
|
|
74545
78003
|
let mapper = {};
|
|
74546
|
-
for ( let
|
|
74547
|
-
var it_20 = __self[
|
|
78004
|
+
for ( let i_30 = 0; i_30 < __self.length; i_30++) {
|
|
78005
|
+
var it_20 = __self[i_30];
|
|
74548
78006
|
const key = cb(it_20);
|
|
74549
78007
|
if ( false == ( typeof(mapper[key] ) != "undefined" && Object.prototype.hasOwnProperty.call(mapper, key) ) ) {
|
|
74550
78008
|
res_14.push(it_20);
|
|
@@ -74555,8 +78013,8 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
74555
78013
|
};
|
|
74556
78014
|
operatorsOf.clone_56 = function(__self) {
|
|
74557
78015
|
let res_15 = [];
|
|
74558
|
-
for ( let
|
|
74559
|
-
var it_21 = __self[
|
|
78016
|
+
for ( let i_32 = 0; i_32 < __self.length; i_32++) {
|
|
78017
|
+
var it_21 = __self[i_32];
|
|
74560
78018
|
res_15.push(it_21);
|
|
74561
78019
|
};
|
|
74562
78020
|
return res_15;
|
|
@@ -74822,8 +78280,8 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
74822
78280
|
};
|
|
74823
78281
|
operatorsOf_13.forEach_55 = function(__self, cb) {
|
|
74824
78282
|
const list_7 = Object.keys(__self);
|
|
74825
|
-
for ( let
|
|
74826
|
-
var kk_7 = list_7[
|
|
78283
|
+
for ( let i_31 = 0; i_31 < list_7.length; i_31++) {
|
|
78284
|
+
var kk_7 = list_7[i_31];
|
|
74827
78285
|
const value_7 = ( Object.prototype.hasOwnProperty.call(__self, kk_7) ? __self[kk_7] : undefined );
|
|
74828
78286
|
cb(value_7, kk_7);
|
|
74829
78287
|
};
|
|
@@ -75517,6 +78975,32 @@ RangerProcessProcSend.collectProcessClasses = function(ctx) {
|
|
|
75517
78975
|
wr
|
|
75518
78976
|
);
|
|
75519
78977
|
};
|
|
78978
|
+
|
|
78979
|
+
// Running another command line program. spawnSync resolves a bare name on
|
|
78980
|
+
// PATH and passes the arguments as a vector, so nothing inside an argument is
|
|
78981
|
+
// re-read as a redirection or a glob.
|
|
78982
|
+
function r_process_env(pairs) {
|
|
78983
|
+
var e = {};
|
|
78984
|
+
for (var k in process.env) { e[k] = process.env[k]; }
|
|
78985
|
+
for (var i = 0; i < pairs.length; i++) {
|
|
78986
|
+
var at = pairs[i].indexOf("=");
|
|
78987
|
+
if (at > 0) { e[pairs[i].substring(0, at)] = pairs[i].substring(at + 1); }
|
|
78988
|
+
}
|
|
78989
|
+
return e;
|
|
78990
|
+
}
|
|
78991
|
+
function r_process_result(program, args, cwd, capture, env) {
|
|
78992
|
+
var opt = { maxBuffer: 268435456 };
|
|
78993
|
+
opt.stdio = capture ? "pipe" : "inherit";
|
|
78994
|
+
if (capture) { opt.encoding = "utf8"; }
|
|
78995
|
+
if (cwd && cwd.length > 0) { opt.cwd = cwd; }
|
|
78996
|
+
if (env && env.length > 0) { opt.env = r_process_env(env); }
|
|
78997
|
+
var res = require("child_process").spawnSync(program, args, opt);
|
|
78998
|
+
if (res.error) { return ["-1", "", String(res.error.message)]; }
|
|
78999
|
+
var code = (typeof res.status === "number") ? res.status : -1;
|
|
79000
|
+
if (!capture) { return [String(code), "", ""]; }
|
|
79001
|
+
return [String(code), res.stdout || "", res.stderr || ""];
|
|
79002
|
+
}
|
|
79003
|
+
|
|
75520
79004
|
/* static JavaSript main routine at the end of the JS file */
|
|
75521
79005
|
async function __js_main() {
|
|
75522
79006
|
const env = CompilerInterface.create_env();
|