Skip to content

Commit 48f2d44

Browse files
fix: remove es-git and use node.js streams (#2)
1 parent f18bd0f commit 48f2d44

52 files changed

Lines changed: 12879 additions & 599 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,7 @@ snowpack-cache
9393
app/tailwind.css.br
9494

9595
bundle-cache
96-
package-entry-points.json
96+
package-entry-points.json
97+
98+
secrets/
99+
packages/packfile/samples/output.pack

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dependencies": {
1010
"@babel/runtime": "^7.12.5",
1111
"@forbeslindesay/tsconfig": "^2.0.0",
12+
"@github-graph/api": "^2.2.1",
1213
"@rollup/plugin-commonjs": "^17.0.0",
1314
"@rollup/plugin-node-resolve": "^11.0.0",
1415
"@sucrase/jest-plugin": "^2.0.0",
@@ -17,6 +18,7 @@
1718
"@types/react-dom": "^17.0.0",
1819
"copy-dir": "^1.3.0",
1920
"husky": "^4.2.5",
21+
"interrogator": "^1.1.0",
2022
"is-builtin-module": "^3.0.0",
2123
"jest": "^26.0.1",
2224
"lint-staged": "^10.1.3",
@@ -34,6 +36,7 @@
3436
"scripts": {
3537
"http": "yarn workspace @rollingversions/git-http",
3638
"objects": "yarn workspace @rollingversions/git-objects",
39+
"packfile": "yarn workspace @rollingversions/git-packfile",
3740
"protocol": "yarn workspace @rollingversions/git-protocol",
3841
"streams": "yarn workspace @rollingversions/git-streams",
3942
"build": "yarn build:links && yarn build:ts && yarn build:rollup",

packages/core/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @rollingversions/git-core
2+
3+
Forked from https://github.com/mariusGundersen/es-git

packages/core/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@rollingversions/git-core",
3+
"version": "0.0.0",
4+
"main": "dist/index.cjs",
5+
"module": "dist/index.mjs",
6+
"types": "lib/index.d.ts",
7+
"exports": {
8+
".": {
9+
"import": "./dist/index.mjs",
10+
"default": "./dist/index.cjs"
11+
},
12+
"./package.json": "./package.json"
13+
},
14+
"files": [
15+
"dist/",
16+
"lib/"
17+
],
18+
"scripts": {
19+
"build": "tsc"
20+
},
21+
"dependencies": {},
22+
"devDependencies": {},
23+
"peerDependencies": {},
24+
"engines": {
25+
"node": ">=14.0.0"
26+
},
27+
"publishConfig": {
28+
"access": "public"
29+
},
30+
"license": "MIT"
31+
}

packages/core/rollup.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports = 'named'

packages/core/src/index.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
export {
2+
decode,
3+
encode,
4+
concat,
5+
fromDec,
6+
fromHex,
7+
fromOct,
8+
fromDecChar,
9+
fromHexChar,
10+
toHexChar,
11+
NEWLINE,
12+
} from './utils';
13+
14+
export enum Mask {
15+
mask = 0o100000,
16+
blob = 0o140000,
17+
file = 0o160000,
18+
}
19+
20+
export enum Mode {
21+
tree = 0o040000,
22+
blob = 0o100644,
23+
file = 0o100644,
24+
exec = 0o100755,
25+
sym = 0o120000,
26+
commit = 0o160000,
27+
}
28+
29+
export enum Type {
30+
unknown = 'unknown',
31+
commit = 'commit',
32+
tree = 'tree',
33+
blob = 'blob',
34+
tag = 'tag',
35+
}
36+
37+
export function isBlob(mode: number) {
38+
return (mode & Mask.blob) === Mask.mask;
39+
}
40+
41+
export function isFile(mode: number) {
42+
return (mode & Mask.file) === Mask.mask;
43+
}
44+
45+
export function toType(mode: number) {
46+
if (mode === Mode.commit) return Type.commit;
47+
if (mode === Mode.tree) return Type.tree;
48+
if ((mode & Mask.blob) === Mask.mask) return Type.blob;
49+
return Type.unknown;
50+
}
51+
52+
export type Hash = string;

packages/core/src/utils.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {toHexChar} from './utils';
2+
3+
for (const [num, hexChar] of [
4+
[0, '0'],
5+
[1, '1'],
6+
[9, '9'],
7+
[10, 'a'],
8+
[15, 'f'],
9+
] as const) {
10+
test(`toHexChar(${num}) => ${hexChar}`, () => {
11+
expect(String.fromCharCode(toHexChar(num))).toBe(hexChar);
12+
});
13+
}

packages/core/src/utils.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const encoder = new TextEncoder();
2+
const decoder = new TextDecoder();
3+
4+
export const NEWLINE = '\n'.charCodeAt(0);
5+
6+
export function encode(text: string) {
7+
return encoder.encode(text);
8+
}
9+
10+
export function decode(binary: Uint8Array, start = 0, end = binary.length) {
11+
if (start !== 0 || end !== binary.length) {
12+
return decoder.decode(binary.subarray(start, end));
13+
} else {
14+
return decoder.decode(binary);
15+
}
16+
}
17+
18+
export function concat(...arrays: (Uint8Array | number[])[]): Uint8Array {
19+
const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
20+
const result = new Uint8Array(totalLength);
21+
let offset = 0;
22+
for (const arr of arrays) {
23+
result.set(arr, offset);
24+
offset += arr.length;
25+
}
26+
return result;
27+
}
28+
29+
export function fromHex(binary: Uint8Array) {
30+
let size = 0;
31+
for (let i = 0; i < 4; i++) {
32+
size = (size << 4) | fromHexChar(binary[i]);
33+
}
34+
return size;
35+
}
36+
37+
export function fromHexChar(val: number) {
38+
return val < 0x57 ? val - 0x30 : val - 0x57;
39+
}
40+
41+
export function fromDec(buffer: Uint8Array, start: number, end: number) {
42+
let val = 0;
43+
while (start < end) {
44+
val = val * 10 + fromDecChar(buffer[start++]);
45+
}
46+
return val;
47+
}
48+
49+
export function fromDecChar(val: number) {
50+
return val - 0x30;
51+
}
52+
53+
export function fromOct(
54+
buffer: Uint8Array,
55+
start: number,
56+
end: number,
57+
): number {
58+
let val = 0;
59+
while (start < end) {
60+
val = (val << 3) + fromDecChar(buffer[start++]);
61+
}
62+
return val;
63+
}
64+
65+
export function toHexChar(val: number) {
66+
return val < 10 ? val + 0x30 : val + 0x57;
67+
}

packages/core/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "@forbeslindesay/tsconfig",
3+
"compilerOptions": {
4+
"outDir": "lib",
5+
"module": "ES2020",
6+
"incremental": true,
7+
"composite": true,
8+
"rootDir": "src",
9+
"tsBuildInfoFile": "lib/.tsbuildinfo",
10+
"lib": ["DOM", "ES2020"]
11+
},
12+
"include": ["src"],
13+
"references": [],
14+
}

packages/http/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
},
2121
"dependencies": {
2222
"@rollingversions/git-protocol": "^0.0.0",
23-
"@rollingversions/git-streams": "^0.0.0",
2423
"cross-fetch": "^3.0.6",
24+
"http-basic": "^8.1.3",
2525
"https-proxy-agent": "^5.0.0"
2626
},
2727
"devDependencies": {},

0 commit comments

Comments
 (0)