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 /);
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: '' };
});
});