refactor: split out readPointerInfo() function
This commit is contained in:
parent
65e7ac524c
commit
dd28da28dd
1 changed files with 22 additions and 17 deletions
|
@ -20,14 +20,8 @@ function isValidPointerInfo(val: Record<string, any>): val is PointerInfo {
|
|||
return val.oid.trim !== undefined && typeof val.size === 'number';
|
||||
}
|
||||
|
||||
interface PointerRequest {
|
||||
dir: string;
|
||||
gitdir?: string;
|
||||
content: Buffer;
|
||||
}
|
||||
|
||||
|
||||
export function readPointer({ dir, gitdir = path.join(dir, '.git'), content }: PointerRequest): Pointer {
|
||||
function readPointerInfo(content: Buffer): PointerInfo {
|
||||
const info = content.toString().trim().split('\n').reduce((accum, line) => {
|
||||
const [k, v] = line.split(' ', 2);
|
||||
if (k === 'oid') {
|
||||
|
@ -39,17 +33,28 @@ export function readPointer({ dir, gitdir = path.join(dir, '.git'), content }: P
|
|||
}, {} as Record<string, any>);
|
||||
|
||||
if (isValidPointerInfo(info)) {
|
||||
const objectPath = path.join(
|
||||
gitdir,
|
||||
'lfs',
|
||||
'objects',
|
||||
info.oid.substr(0, 2),
|
||||
info.oid.substr(2, 2),
|
||||
info.oid);
|
||||
|
||||
return { info, objectPath };
|
||||
|
||||
return info;
|
||||
} else {
|
||||
throw new Error("LFS pointer is incomplete or cannot be read");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface PointerRequest {
|
||||
dir: string;
|
||||
gitdir?: string;
|
||||
content: Buffer;
|
||||
}
|
||||
export function readPointer({ dir, gitdir = path.join(dir, '.git'), content }: PointerRequest): Pointer {
|
||||
const info = readPointerInfo(content);
|
||||
|
||||
const objectPath = path.join(
|
||||
gitdir,
|
||||
'lfs',
|
||||
'objects',
|
||||
info.oid.substr(0, 2),
|
||||
info.oid.substr(2, 2),
|
||||
info.oid);
|
||||
|
||||
return { info, objectPath };
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue