-
-
Notifications
You must be signed in to change notification settings - Fork 320
/
count-objects.ts
51 lines (47 loc) · 1.27 KB
/
count-objects.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { SimpleGitApi } from '../simple-git-api';
import type { SimpleGit } from '../../../typings';
import { asCamelCase, asNumber, LineParser, parseStringResponse } from '../utils';
export interface CountObjectsResult {
count: number;
size: number;
inPack: number;
packs: number;
sizePack: number;
prunePackable: number;
garbage: number;
sizeGarbage: number;
}
function countObjectsResponse(): CountObjectsResult {
return {
count: 0,
garbage: 0,
inPack: 0,
packs: 0,
prunePackable: 0,
size: 0,
sizeGarbage: 0,
sizePack: 0,
};
}
const parser: LineParser<CountObjectsResult> = new LineParser(
/([a-z-]+): (\d+)$/,
(result, [key, value]) => {
const property = asCamelCase(key);
if (result.hasOwnProperty(property)) {
result[property as keyof typeof result] = asNumber(value);
}
}
);
export default function (): Pick<SimpleGit, 'countObjects'> {
return {
countObjects(this: SimpleGitApi) {
return this._runTask({
commands: ['count-objects', '--verbose'],
format: 'utf-8',
parser(stdOut: string) {
return parseStringResponse(countObjectsResponse(), [parser], stdOut);
},
});
},
};
}