@catmint-fs/git 0.0.0-prealpha.3 → 0.0.0-prealpha.5
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/dist/index.js +19 -6
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -127,6 +127,11 @@ function inflateWithConsumed(data, pos) {
|
|
|
127
127
|
const rawConsumed = strm?.total_in ?? data.length - pos - 6;
|
|
128
128
|
return [result, 2 + rawConsumed + 4];
|
|
129
129
|
}
|
|
130
|
+
async function computeObjectOid(type, content) {
|
|
131
|
+
const header = encode(`${type} ${content.length}\0`);
|
|
132
|
+
const store = concat(header, content);
|
|
133
|
+
return sha1(store);
|
|
134
|
+
}
|
|
130
135
|
function readUint32(data, offset) {
|
|
131
136
|
return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
|
|
132
137
|
}
|
|
@@ -165,7 +170,8 @@ var init_read = __esm({
|
|
|
165
170
|
/**
|
|
166
171
|
* Extract all objects from the packfile without requiring an index.
|
|
167
172
|
* Parses the pack header to get the object count, then reads each object
|
|
168
|
-
* sequentially.
|
|
173
|
+
* sequentially. Builds an OID map on-the-fly so REF_DELTA objects can
|
|
174
|
+
* resolve their bases even without a pre-built pack index.
|
|
169
175
|
*/
|
|
170
176
|
async extractAll() {
|
|
171
177
|
if (!this.packData) {
|
|
@@ -173,6 +179,8 @@ var init_read = __esm({
|
|
|
173
179
|
}
|
|
174
180
|
const data = this.packData;
|
|
175
181
|
const objects = [];
|
|
182
|
+
const oidMap = /* @__PURE__ */ new Map();
|
|
183
|
+
const offsetToOid = /* @__PURE__ */ new Map();
|
|
176
184
|
if (data.length < 12) {
|
|
177
185
|
throw new Error("Pack data too short");
|
|
178
186
|
}
|
|
@@ -190,6 +198,7 @@ var init_read = __esm({
|
|
|
190
198
|
size |= (byte & 127) << shift;
|
|
191
199
|
shift += 7;
|
|
192
200
|
}
|
|
201
|
+
let obj;
|
|
193
202
|
if (type === OBJ_OFS_DELTA) {
|
|
194
203
|
byte = data[pos++];
|
|
195
204
|
let negOffset = byte & 127;
|
|
@@ -202,12 +211,12 @@ var init_read = __esm({
|
|
|
202
211
|
const [deltaData, consumed] = inflateWithConsumed(data, pos);
|
|
203
212
|
pos += consumed;
|
|
204
213
|
const result = applyDelta(base.content, deltaData);
|
|
205
|
-
|
|
214
|
+
obj = { type: base.type, content: result };
|
|
206
215
|
} else if (type === OBJ_REF_DELTA) {
|
|
207
216
|
const baseSha = bytesToHex(data.subarray(pos, pos + 20));
|
|
208
217
|
pos += 20;
|
|
209
|
-
let baseObj;
|
|
210
|
-
if (this.index) {
|
|
218
|
+
let baseObj = oidMap.get(baseSha);
|
|
219
|
+
if (!baseObj && this.index) {
|
|
211
220
|
const baseOffset = this.index.offsets.get(baseSha);
|
|
212
221
|
if (baseOffset !== void 0) {
|
|
213
222
|
baseObj = this.readObjectAtOffset(baseOffset);
|
|
@@ -219,7 +228,7 @@ var init_read = __esm({
|
|
|
219
228
|
const [deltaData, consumed] = inflateWithConsumed(data, pos);
|
|
220
229
|
pos += consumed;
|
|
221
230
|
const result = applyDelta(baseObj.content, deltaData);
|
|
222
|
-
|
|
231
|
+
obj = { type: baseObj.type, content: result };
|
|
223
232
|
} else {
|
|
224
233
|
const typeName = TYPE_MAP[type];
|
|
225
234
|
if (!typeName) {
|
|
@@ -227,8 +236,12 @@ var init_read = __esm({
|
|
|
227
236
|
}
|
|
228
237
|
const [content, consumed] = inflateWithConsumed(data, pos);
|
|
229
238
|
pos += consumed;
|
|
230
|
-
|
|
239
|
+
obj = { type: typeName, content };
|
|
231
240
|
}
|
|
241
|
+
const oid = await computeObjectOid(obj.type, obj.content);
|
|
242
|
+
oidMap.set(oid, obj);
|
|
243
|
+
offsetToOid.set(startPos, oid);
|
|
244
|
+
objects.push(obj);
|
|
232
245
|
}
|
|
233
246
|
return objects;
|
|
234
247
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catmint-fs/git",
|
|
3
|
-
"version": "0.0.0-prealpha.
|
|
3
|
+
"version": "0.0.0-prealpha.5",
|
|
4
4
|
"description": "Programmatic git operations built on @catmint-fs/core layers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"pako": "^2.1.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@catmint-fs/core": "0.0.0-prealpha.
|
|
38
|
+
"@catmint-fs/core": "0.0.0-prealpha.5"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/pako": "^2.0.0",
|
|
42
|
-
"@catmint-fs/
|
|
43
|
-
"@catmint-fs/
|
|
42
|
+
"@catmint-fs/core": "0.0.0-prealpha.5",
|
|
43
|
+
"@catmint-fs/sqlite-adapter": "0.0.0-prealpha.5"
|
|
44
44
|
},
|
|
45
45
|
"tsup": {
|
|
46
46
|
"entry": [
|