-
Notifications
You must be signed in to change notification settings - Fork 0
/
dead-files.ts
23 lines (17 loc) · 872 Bytes
/
dead-files.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { getFileModHistories, FileModificationHistory, Mod, MOD } from "./file-history";
import { log } from "./util";
export function listDeadFilesSince(sinceCommittish: string): string[] {
const historyMods = getFileModHistories({ sinceCommittish });
const fileModHistories: FileModificationHistory[] = [...historyMods.file2modsMap];
log({ fileModHistories, renames: [...historyMods.rename2LatestFileMap] });
const deadFiles: string[] = [];
for (const [file, modPairs] of fileModHistories) {
const mods: Mod[] = modPairs.map(([mod]) => mod);
if (isFileDead(mods)) deadFiles.push(file);
}
return deadFiles;
}
export function isFileDead(mods: Mod[]): boolean {
return (mods[0] === MOD.delete && mods[mods.length - 1] === MOD.add)
&& mods.filter(x => x === MOD.add).length < 2 /** TODO handle partially-dead (if earlier add + delete pairs exist). */;
}