Branch

operations.js

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
ac0345 Tucker McKnight
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import util from 'util';
import childProcess from 'child_process';
const exec = util.promisify(childProcess.exec);
import { getDarcsDiffsFromPatchText } from "../../helpers.js";
export const getFileList = (repoName, branchName, repoLocation) => __awaiter(void 0, void 0, void 0, function* () {
    const command = "darcs show files";
    const result = yield exec(`(cd ${repoLocation} && ${command})`);
    const files = result.stdout.split("\n").filter(item => item.length > 0 && item != ".");
    return files;
});
export const getBranchInfo = (repoName, branchName, repoLocation) => __awaiter(void 0, void 0, void 0, function* () {
    const patches = new Map();
    const totalPatchesCountRes = yield exec(`(cd ${repoLocation} && darcs log --count)`);
    const totalPatchesCount = parseInt(totalPatchesCountRes.stdout);
    let hunkRegex = RegExp(/^ *hunk /);
    // Get 100 patches at a time and parse those
    for (let i = 1; i <= totalPatchesCount; i = i + 100) {
        let patchesSubsetRes = yield exec(`(cd ${repoLocation} && darcs log --index=${i}-${i + 100} -v)`);
        let patchesSubset = patchesSubsetRes.stdout.split("\n");
        do {
            const nextPatchStart = patchesSubset.findIndex((line, index) => {
                return (index > 0 && line.startsWith("patch ")) || index === patchesSubset.length - 1;
            });
            const isEndOfFile = nextPatchStart === patchesSubset.length - 1;
            const currentPatch = patchesSubset.slice(0, isEndOfFile ? nextPatchStart : nextPatchStart - 1);
            patchesSubset = patchesSubset.slice(nextPatchStart);
            const hash = currentPatch[0].replace("patch ", "").trim();
            const author = currentPatch[1].replace("Author: ", "").trim();
            const date = currentPatch[2].replace("Date: ", "").trim();
            const name = currentPatch[3].replace("  * ", "").trim();
            const diffStart = currentPatch.findIndex((line) => {
                return line.match(hunkRegex);
            });
            const description = currentPatch.slice(5, diffStart).map(str => str.replace("  ", "")).join("\n").trim();
            const diffs = getDarcsDiffsFromPatchText(currentPatch.slice(diffStart).map(str => str.trimStart()).join("\n"));
            patches.set(hash, {
                name,
                description,
                author,
                date,
                hash,
                diffs,
            });
        } while (patchesSubset.length > 1);
    }
    return Array.from(patches.values());
});
export const getFileLastTouchInfo = (repoName, branchName, filename, repoLocation) => __awaiter(void 0, void 0, void 0, function* () {
    const command = `darcs annotate --machine-readable ${filename}`;
    const res = yield exec(`(cd ${repoLocation} && ${command})`);
    const output = res.stdout;
    const outputLines = output.split("\n").map((line) => {
        return line.split(' ')[0];
    });
    return outputLines.map((line) => {
        return { sha: line, author: '' };
    });
});