@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
42 lines • 2.24 kB
JavaScript
import { loadMailmap, mappedIdentity } from "./mailmap.js";
import { IOResult } from "../../../../io/types.js";
import { compareCodePoints } from "../../../../utils/sort.js";
import { FlagView } from "../../../spec/flag_view.js";
import { ShortlogOptionError } from "./errors.js";
import { subject } from "./format.js";
import { parseFlags, refCommits, select, walkEnds, walkOperands } from "./history.js";
import { opened } from "./session.js";
import { optionOperand, verbUsage } from "./util.js";
/** Summarize repository history by author. */
export async function shortlog(_accessor, paths, texts, ctx) {
const fl = new FlagView(ctx.flags);
const word = optionOperand(ctx, texts);
if (word !== null)
throw new ShortlogOptionError(word, verbUsage(ctx));
const repo = await opened(ctx, fl);
const mailmap = await loadMailmap(repo.vfs, repo.location);
const [revisions, pathspecs, dashed] = await walkOperands(ctx, fl, repo, texts);
const flags = { ...parseFlags(fl, null, ctx.signal), pathspecs };
const [starts, hidden] = await walkEnds(repo, revisions.length ? revisions : flags.allRefs ? [] : ['HEAD'], dashed);
if (flags.allRefs)
for (const item of await refCommits(repo))
starts.push(item);
const groups = new Map();
for (const commit of (await select(repo, starts, flags, hidden)).reverse()) {
const identity = mappedIdentity(`${commit.authorName} <${commit.authorEmail}>`, mailmap);
const name = fl.asBool('email') ? identity : identity.slice(0, identity.lastIndexOf(' <'));
const messages = groups.get(name) ?? [];
messages.push(subject(commit));
groups.set(name, messages);
}
const entries = [...groups].sort(([a, x], [b, y]) => (fl.asBool('numbered') ? y.length - x.length : 0) || compareCodePoints(a, b));
const text = entries
.map(([name, messages]) => fl.asBool('summary')
? `${String(messages.length).padStart(6)}\t${name}\n`
: `${name} (${String(messages.length)}):\n` +
messages.map((message) => ` ${message}\n`).join('') +
'\n')
.join('');
return [new TextEncoder().encode(text), new IOResult()];
}
//# sourceMappingURL=shortlog.js.map