M4.6: Git log and file history
- crates/vcs log.rs: Repo::log (topological, all refs, paging, literal message/author filters, a path's history with --follow), show_commit (message and files against the first parent, renames) and show_at (a file at any commit); parsers property-tested. - Engine git.log, git.showCommit, git.showAt in cmd/git_log.rs through the step-1 hook. - Log tab in the bottom panel: graph lanes carried across pages, ref badges, filters, lazy paging, keyboard; commit details whose files open a read-only diff at that commit in M4.3's viewer. - vcs.showLog and vcs.showHistory (menu, tree context menu, active editor tab), no default shortcuts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b814c49733
commit
a8531825a3
27 changed files with 3349 additions and 16 deletions
|
|
@ -41,6 +41,8 @@ export const UI_COMMANDS: readonly UiCommandSpec[] = [
|
|||
{ id: "vcs.newBranch", labelKey: "command.vcs.newBranch", menuPath: "Git/New Branch…" },
|
||||
{ id: "vcs.openChanges", labelKey: "command.vcs.openChanges", menuPath: "Git/Changes", defaultShortcut: "Mod+Alt+Shift+G" },
|
||||
{ id: "vcs.refresh", labelKey: "command.vcs.refresh", menuPath: "Git/Refresh Changes" },
|
||||
{ id: "vcs.showLog", labelKey: "command.vcs.showLog", menuPath: "Git/Log" },
|
||||
{ id: "vcs.showHistory", labelKey: "command.vcs.showHistory", menuPath: "Git/Show History" },
|
||||
{ id: "vcs.showDiff", labelKey: "command.vcs.showDiff", menuPath: "Git/Show Diff", defaultShortcut: "Mod+Alt+Shift+D" },
|
||||
{ id: "vcs.nextChange", labelKey: "command.vcs.nextChange", menuPath: "Git/Next Change", defaultShortcut: "Alt+Shift+]" },
|
||||
{ id: "vcs.previousChange", labelKey: "command.vcs.previousChange", menuPath: "Git/Previous Change", defaultShortcut: "Alt+Shift+[" },
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ import { X } from "@lucide/vue";
|
|||
import { t } from "../../i18n";
|
||||
import { useEditorStore } from "../../stores/editor";
|
||||
import { useVcsStatusStore } from "../../stores/vcsStatus";
|
||||
import { useDiffStore } from "../vcs/diff/diff";
|
||||
import { SHORT_HASH } from "../vcs/changes/changes";
|
||||
import { useDiffStore, type DiffTab } from "../vcs/diff/diff";
|
||||
|
||||
const editor = useEditorStore();
|
||||
const vcs = useVcsStatusStore();
|
||||
|
|
@ -38,6 +39,19 @@ function activateTab(id: number): void {
|
|||
editor.activate(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* The title of a diff tab: the file name, marked for the staged view or
|
||||
* with the short hash of a commit tab.
|
||||
*
|
||||
* @param tab - the diff tab.
|
||||
*/
|
||||
function diffTitle(tab: DiffTab): string {
|
||||
if (tab.commit) {
|
||||
return t("vcs.diff.tabTitleCommit", { name: tab.name, hash: tab.commit.hash.slice(0, SHORT_HASH) });
|
||||
}
|
||||
return tab.staged ? t("vcs.diff.tabTitleStaged", { name: tab.name }) : t("vcs.diff.tabTitle", { name: tab.name });
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a diff tab on a middle click.
|
||||
*
|
||||
|
|
@ -143,7 +157,7 @@ function onKeydown(event: KeyboardEvent): void {
|
|||
@mousedown.middle.prevent
|
||||
@auxclick="onDiffAuxClick($event, tab.key)"
|
||||
>
|
||||
<span class="tabs__name">{{ tab.staged ? t("vcs.diff.tabTitleStaged", { name: tab.name }) : t("vcs.diff.tabTitle", { name: tab.name }) }}</span>
|
||||
<span class="tabs__name">{{ diffTitle(tab) }}</span>
|
||||
<button
|
||||
class="tabs__close"
|
||||
type="button"
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@
|
|||
* (`Mod+Alt+Shift+G`) and `vcs.commit` (`Mod+Alt+Shift+M`, which also
|
||||
* focuses the commit message box); `vcs.refresh` re-reads the Git status.
|
||||
* Its store reads the status from the start, so it is current when the
|
||||
* tab opens.
|
||||
* tab opens. The Log tab (M4.6) appears with `vcs.showLog` and with
|
||||
* `vcs.showHistory {path?}` (the history of a file or folder; without a
|
||||
* path, of the active editor tab's file); neither has a default shortcut.
|
||||
*
|
||||
* A slim header bar along the top (M3.9) holds the app menu
|
||||
* ({@link AppMenu}); its `header` slot can replace it.
|
||||
|
|
@ -49,6 +51,10 @@ import ReferencesToolWindow from "../editor/nav/ReferencesToolWindow.vue";
|
|||
import { useNavStore } from "../editor/nav/nav";
|
||||
import ChangesToolWindow from "../vcs/changes/ChangesToolWindow.vue";
|
||||
import { useChangesStore } from "../vcs/changes/changes";
|
||||
import LogToolWindow from "../vcs/log/LogToolWindow.vue";
|
||||
import { SHOW_HISTORY_COMMAND, SHOW_LOG_COMMAND, useLogStore } from "../vcs/log/log";
|
||||
import { useEditorStore } from "../../stores/editor";
|
||||
import { useProjectStore } from "../../stores/project";
|
||||
import ProjectToolWindow from "../project/ProjectToolWindow.vue";
|
||||
import StatusBar from "../StatusBar.vue";
|
||||
import StructureToolWindow from "../structure/StructureToolWindow.vue";
|
||||
|
|
@ -96,9 +102,12 @@ const terminal = useTerminalStore();
|
|||
const problems = useProblemsStore();
|
||||
const nav = useNavStore();
|
||||
const changes = useChangesStore();
|
||||
const vcsLog = useLogStore();
|
||||
const editor = useEditorStore();
|
||||
const project = useProjectStore();
|
||||
|
||||
/** Tool windows of the bottom panel. */
|
||||
type BottomTool = "find" | "terminal" | "problems" | "references" | "changes";
|
||||
type BottomTool = "find" | "terminal" | "problems" | "references" | "changes" | "log";
|
||||
/** The bottom tool window last chosen. */
|
||||
const bottomTool = ref<BottomTool>("find");
|
||||
/** Bottom tool windows that are shown, in tab order. */
|
||||
|
|
@ -109,6 +118,7 @@ const bottomTools = computed(() => {
|
|||
if (problems.visible) tools.push({ id: "problems", title: t("problems.toolWindow.title") });
|
||||
if (nav.visible) tools.push({ id: "references", title: t("nav.references.title") });
|
||||
if (changes.visible) tools.push({ id: "changes", title: t("vcs.changes.toolWindow.title") });
|
||||
if (vcsLog.visible) tools.push({ id: "log", title: t("vcs.log.toolWindow.title") });
|
||||
return tools;
|
||||
});
|
||||
/** The active bottom tool window: the chosen one if shown, else the first. */
|
||||
|
|
@ -126,7 +136,9 @@ const bottomStore = computed(() =>
|
|||
? nav
|
||||
: bottomActive.value === "changes"
|
||||
? changes
|
||||
: find,
|
||||
: bottomActive.value === "log"
|
||||
? vcsLog
|
||||
: find,
|
||||
);
|
||||
/** Expansion of the panel, kept per tool window by its store. */
|
||||
const bottomOpen = computed({
|
||||
|
|
@ -142,7 +154,7 @@ const bottomOpen = computed({
|
|||
* @param id - the tool window id from the panel.
|
||||
*/
|
||||
function chooseBottom(id: string): void {
|
||||
if (id === "find" || id === "terminal" || id === "problems" || id === "references" || id === "changes") {
|
||||
if (id === "find" || id === "terminal" || id === "problems" || id === "references" || id === "changes" || id === "log") {
|
||||
bottomTool.value = id;
|
||||
}
|
||||
}
|
||||
|
|
@ -160,6 +172,7 @@ onMounted(() => {
|
|||
terminal.start();
|
||||
problems.start();
|
||||
changes.start();
|
||||
vcsLog.start();
|
||||
withdraw = [
|
||||
commands.provide("view.toggleProjectTree", {
|
||||
run: () => {
|
||||
|
|
@ -201,6 +214,20 @@ onMounted(() => {
|
|||
run: () => changes.refresh(),
|
||||
enabled: () => commands.isEnabled("git.status"),
|
||||
}),
|
||||
commands.provide(SHOW_LOG_COMMAND, {
|
||||
run: () => {
|
||||
bottomTool.value = "log";
|
||||
return vcsLog.open();
|
||||
},
|
||||
enabled: () => project.root !== null,
|
||||
}),
|
||||
commands.provide(SHOW_HISTORY_COMMAND, {
|
||||
run: (params) => {
|
||||
bottomTool.value = "log";
|
||||
return vcsLog.runShowHistory(params, editor.activeTab?.path ?? null);
|
||||
},
|
||||
enabled: () => project.root !== null,
|
||||
}),
|
||||
commands.provide("view.toggleStructure", {
|
||||
run: () => {
|
||||
toggleLeft("structure");
|
||||
|
|
@ -218,6 +245,7 @@ onBeforeUnmount(() => {
|
|||
terminal.stop();
|
||||
problems.stop();
|
||||
changes.stop();
|
||||
vcsLog.stop();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -292,6 +320,10 @@ onBeforeUnmount(() => {
|
|||
<ProblemsToolWindow v-show="bottomActive === 'problems'" />
|
||||
<ReferencesToolWindow v-show="bottomActive === 'references'" />
|
||||
<ChangesToolWindow v-show="bottomActive === 'changes'" />
|
||||
<LogToolWindow
|
||||
v-if="vcsLog.visible"
|
||||
v-show="bottomActive === 'log'"
|
||||
/>
|
||||
</BottomPanel>
|
||||
<StatusBar />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* The project tree's context menu for a file (M4.3): Open and Show Diff
|
||||
* (`vcs.showDiff {path}`, dimmed while the command is disabled).
|
||||
* The project tree's context menu for a file (M4.3): Open, Show Diff
|
||||
* (`vcs.showDiff {path}`) and Show History (`vcs.showHistory {path}`,
|
||||
* M4.6), the Git items dimmed while their command is disabled.
|
||||
*
|
||||
* Follows the WAI-ARIA menu pattern: it takes the focus when it opens,
|
||||
* Up/Down move between items (wrapping), Enter or Space runs one, Escape,
|
||||
|
|
@ -13,6 +14,7 @@ import { useCommandsStore } from "../../commands/store";
|
|||
import { t } from "../../i18n";
|
||||
import { useEditorStore } from "../../stores/editor";
|
||||
import { SHOW_DIFF_COMMAND } from "../vcs/diff/diff";
|
||||
import { SHOW_HISTORY_COMMAND } from "../vcs/log/log";
|
||||
|
||||
const props = defineProps<{
|
||||
/** Project-relative path of the file. */
|
||||
|
|
@ -66,6 +68,12 @@ const items = computed<MenuItem[]>(() => [
|
|||
enabled: commands.isEnabled(SHOW_DIFF_COMMAND),
|
||||
run: () => commands.execute(SHOW_DIFF_COMMAND, { path: props.path }),
|
||||
},
|
||||
{
|
||||
id: "showHistory",
|
||||
label: t("project.tree.menu.showHistory"),
|
||||
enabled: commands.isEnabled(SHOW_HISTORY_COMMAND),
|
||||
run: () => commands.execute(SHOW_HISTORY_COMMAND, { path: props.path }),
|
||||
},
|
||||
]);
|
||||
|
||||
/** The menu's position, kept inside the window. */
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
* from disk, an agent's edit) come back through `bufferChanged`: once the
|
||||
* sync has taken them over, the difference is applied to the right
|
||||
* editor outside its undo history.
|
||||
* - **Commit tabs (M4.6):** both sides are read-only texts from the store:
|
||||
* the file at the commit's parent (left) and at the commit (right).
|
||||
* - **Left side:** replaced in place when the store re-reads it
|
||||
* (`gitChanged` after staging).
|
||||
* - **Colours:** only `--lt-*` tokens; changed lines are tinted with
|
||||
|
|
@ -32,6 +34,7 @@ import type { BufferSync } from "../../editor/bufferSync";
|
|||
import { diffDocs } from "../../editor/engineText";
|
||||
import { editorExtensions, lutraEditorTheme } from "../../editor/extensions";
|
||||
import { languageExtensions } from "../../editor/language";
|
||||
import { SHORT_HASH } from "../changes/changes";
|
||||
import { refFor, useDiffStore } from "./diff";
|
||||
import { setNavigator } from "./navigation";
|
||||
|
||||
|
|
@ -89,6 +92,9 @@ const caption = computed(() => {
|
|||
if (!tab) {
|
||||
return "";
|
||||
}
|
||||
if (tab.commit) {
|
||||
return t("vcs.diff.captionCommit", { path: tab.path, hash: tab.commit.hash.slice(0, SHORT_HASH) });
|
||||
}
|
||||
return refFor(tab.staged) === "HEAD"
|
||||
? t("vcs.diff.captionHead", { path: tab.path })
|
||||
: t("vcs.diff.captionIndex", { path: tab.path });
|
||||
|
|
@ -181,7 +187,7 @@ function build(): void {
|
|||
: [basicSetup, lutraEditorTheme, languageExtensions(tab.path), diffTheme, readOnly];
|
||||
merge = new MergeView({
|
||||
a: { doc: content.left, extensions: [basicSetup, lutraEditorTheme, languageExtensions(tab.path), diffTheme, readOnly] },
|
||||
b: sync ? { doc: sync.state.doc, selection: sync.state.selection, extensions: right } : { doc: "", extensions: right },
|
||||
b: sync ? { doc: sync.state.doc, selection: sync.state.selection, extensions: right } : { doc: content.right ?? "", extensions: right },
|
||||
parent: host.value,
|
||||
gutter: true,
|
||||
highlightChanges: true,
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@
|
|||
* - **Refresh:** `gitChanged` re-reads the left side of every text tab
|
||||
* (staging changes the index). A project open or close drops every tab;
|
||||
* closing the working copy's buffer closes its diff tabs.
|
||||
* - **Commit tabs (M4.6):** {@link openAtCommit} compares a file at a commit
|
||||
* (right, `git.showAt {path, rev: hash}`) with its first parent (left, the
|
||||
* old path of a rename). Both sides are read-only texts; nothing is
|
||||
* re-read on `gitChanged` (commits do not change).
|
||||
* - **Untrusted input:** `git.show` results are checked field by field.
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
|
|
@ -55,6 +59,18 @@ export interface ShowDiffParams {
|
|||
staged: boolean;
|
||||
}
|
||||
|
||||
/** The commit a commit tab shows (M4.6). */
|
||||
export interface DiffCommit {
|
||||
/** The commit's full hash (the right side). */
|
||||
hash: string;
|
||||
/** Its first parent (the left side); null for a root commit. */
|
||||
parent: string | null;
|
||||
/** The file's path in the parent when it was renamed or copied. */
|
||||
origPath: string | null;
|
||||
/** The file was deleted by the commit (no right side). */
|
||||
deleted: boolean;
|
||||
}
|
||||
|
||||
/** One diff tab. */
|
||||
export interface DiffTab {
|
||||
/** Stable key: side and path. */
|
||||
|
|
@ -65,6 +81,8 @@ export interface DiffTab {
|
|||
staged: boolean;
|
||||
/** File name shown on the tab. */
|
||||
name: string;
|
||||
/** For a commit tab: what it compares; absent for working-copy diffs. */
|
||||
commit?: DiffCommit;
|
||||
}
|
||||
|
||||
/** What a diff tab shows. */
|
||||
|
|
@ -82,6 +100,9 @@ export interface DiffContent {
|
|||
bufferId: number | null;
|
||||
/** Error text, or why the working copy is missing; null if none. */
|
||||
message: string | null;
|
||||
/** A commit tab's right text with `
|
||||
` breaks (absent otherwise). */
|
||||
right?: string;
|
||||
}
|
||||
|
||||
/** A `git.show` result, checked. */
|
||||
|
|
@ -122,6 +143,16 @@ export function diffKey(path: string, staged: boolean): string {
|
|||
return `${staged ? "staged" : "work"}:${path}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The key of a commit tab.
|
||||
*
|
||||
* @param path - project-relative path.
|
||||
* @param hash - the commit.
|
||||
*/
|
||||
export function commitDiffKey(path: string, hash: string): string {
|
||||
return `commit:${hash}:${path}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the params of `vcs.showDiff`; null when malformed.
|
||||
*
|
||||
|
|
@ -292,6 +323,55 @@ export const useDiffStore = defineStore("diff", () => {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a file at a revision with `git.showAt`.
|
||||
*
|
||||
* @param path - project-relative path.
|
||||
* @param rev - the commit.
|
||||
* @returns the checked result, or the error text.
|
||||
*/
|
||||
async function readAt(path: string, rev: string): Promise<ShowResult | string> {
|
||||
const result = await runWaiting("git.showAt", { path, rev });
|
||||
if (!result.ok) {
|
||||
return result.error.message;
|
||||
}
|
||||
return toShowResult(result.value) ?? t("common.error.unexpectedResult", { command: "git.showAt" });
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads both sides of a commit tab.
|
||||
*
|
||||
* @param tab - the tab.
|
||||
* @param commit - what it compares.
|
||||
* @param current - whether this load is still the newest.
|
||||
*/
|
||||
async function loadCommit(tab: DiffTab, commit: DiffCommit, current: () => boolean): Promise<void> {
|
||||
const missing: ShowResult = { text: null, binary: false, tooLarge: false };
|
||||
const [left, right] = await Promise.all([
|
||||
commit.parent === null ? Promise.resolve(missing) : readAt(commit.origPath ?? tab.path, commit.parent),
|
||||
commit.deleted ? Promise.resolve(missing) : readAt(tab.path, commit.hash),
|
||||
]);
|
||||
if (!current()) {
|
||||
return;
|
||||
}
|
||||
if (typeof left === "string" || typeof right === "string") {
|
||||
setContent(tab.key, { ...LOADING, phase: "error", message: typeof left === "string" ? left : typeof right === "string" ? right : null });
|
||||
return;
|
||||
}
|
||||
if (left.binary || right.binary || left.tooLarge || right.tooLarge) {
|
||||
setContent(tab.key, { ...LOADING, phase: left.binary || right.binary ? "binary" : "tooLarge" });
|
||||
return;
|
||||
}
|
||||
setContent(tab.key, {
|
||||
phase: "ready",
|
||||
left: normaliseEol(left.text ?? ""),
|
||||
leftMissing: left.text === null,
|
||||
bufferId: null,
|
||||
message: null,
|
||||
right: normaliseEol(right.text ?? ""),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads both sides of a tab.
|
||||
*
|
||||
|
|
@ -302,6 +382,10 @@ export const useDiffStore = defineStore("diff", () => {
|
|||
generations.set(tab.key, generation);
|
||||
const current = (): boolean => generations.get(tab.key) === generation && tabs.value.some((t) => t.key === tab.key);
|
||||
setContent(tab.key, LOADING);
|
||||
if (tab.commit) {
|
||||
await loadCommit(tab, tab.commit, current);
|
||||
return;
|
||||
}
|
||||
const left = await readLeft(tab);
|
||||
if (!current()) {
|
||||
return;
|
||||
|
|
@ -344,6 +428,26 @@ export const useDiffStore = defineStore("diff", () => {
|
|||
await load(tab);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens (or activates) the diff of a file at a commit against the
|
||||
* commit's first parent.
|
||||
*
|
||||
* @param path - project-relative path at the commit.
|
||||
* @param commit - the commit, its parent and the file's old path.
|
||||
*/
|
||||
async function openAtCommit(path: string, commit: DiffCommit): Promise<void> {
|
||||
const key = commitDiffKey(path, commit.hash);
|
||||
let tab = tabs.value.find((t) => t.key === key);
|
||||
if (!tab) {
|
||||
tab = { key, path, staged: false, name: baseName(path), commit };
|
||||
tabs.value.push(tab);
|
||||
}
|
||||
activate(key);
|
||||
if (contents.value[key]?.phase !== "ready") {
|
||||
await load(tab);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-reads the left side of every loaded text tab; a changed text
|
||||
* replaces the left document (`gitChanged`).
|
||||
|
|
@ -352,7 +456,7 @@ export const useDiffStore = defineStore("diff", () => {
|
|||
await Promise.all(
|
||||
tabs.value.map(async (tab) => {
|
||||
const before = contents.value[tab.key];
|
||||
if (before?.phase !== "ready") {
|
||||
if (before?.phase !== "ready" || tab.commit) {
|
||||
return;
|
||||
}
|
||||
const generation = generations.get(tab.key);
|
||||
|
|
@ -464,6 +568,7 @@ export const useDiffStore = defineStore("diff", () => {
|
|||
activate,
|
||||
deactivate,
|
||||
open,
|
||||
openAtCommit,
|
||||
showDiff,
|
||||
refreshLeft,
|
||||
close,
|
||||
|
|
|
|||
730
ui/src/components/vcs/log/LogToolWindow.vue
Normal file
730
ui/src/components/vcs/log/LogToolWindow.vue
Normal file
|
|
@ -0,0 +1,730 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* The Log tool window (M4.6), a tab of the bottom panel: the commit list
|
||||
* with graph lanes on the left, the selected commit's details on the right.
|
||||
*
|
||||
* - **Toolbar:** a text filter (message) and an author filter, applied
|
||||
* 300 ms after the last keystroke or at once on Enter; a chip with the
|
||||
* path while a file's or folder's history shows (its button clears it);
|
||||
* a refresh button.
|
||||
* - **List:** graph, subject with ref badges, author, date. Up/Down,
|
||||
* Page Up/Down, Home and End move the selection; scrolling near the end
|
||||
* loads the next page.
|
||||
* - **Details:** hash, author, date, the full message and the changed
|
||||
* files; Enter or a double-click on a file opens its diff at that commit
|
||||
* in the editor area.
|
||||
* - **Colours:** lanes cycle through theme tokens only.
|
||||
*/
|
||||
import { RefreshCw, X } from "@lucide/vue";
|
||||
import { computed, nextTick, onBeforeUnmount, ref } from "vue";
|
||||
import { t } from "../../../i18n";
|
||||
import { useProjectStore } from "../../../stores/project";
|
||||
import { SHORT_HASH } from "../changes/changes";
|
||||
import { refBadges, useLogStore, type CommitFile, type CommitFileStatus } from "./log";
|
||||
import type { GraphRow } from "./graph";
|
||||
|
||||
const log = useLogStore();
|
||||
const project = useProjectStore();
|
||||
|
||||
/** Width of a lane in pixels. */
|
||||
const LANE = 12;
|
||||
/** Height of a row in pixels. */
|
||||
const ROW = 22;
|
||||
/** Rows from the end at which the next page loads. */
|
||||
const PRELOAD_ROWS = 30;
|
||||
/** Delay before a typed filter applies. */
|
||||
const FILTER_DELAY_MS = 300;
|
||||
|
||||
/** Lane colours, theme tokens only. */
|
||||
const LANE_COLOURS = [
|
||||
"var(--lt-accent)",
|
||||
"var(--lt-vcs-added)",
|
||||
"var(--lt-vcs-modified)",
|
||||
"var(--lt-syntax-keyword)",
|
||||
"var(--lt-syntax-string)",
|
||||
"var(--lt-syntax-function)",
|
||||
"var(--lt-syntax-type)",
|
||||
"var(--lt-syntax-number)",
|
||||
];
|
||||
|
||||
/** Labels of the file states, from the catalog. */
|
||||
const STATE_LABELS: Record<CommitFileStatus, () => string> = {
|
||||
added: () => t("vcs.state.added"),
|
||||
modified: () => t("vcs.state.modified"),
|
||||
deleted: () => t("vcs.state.deleted"),
|
||||
renamed: () => t("vcs.state.renamed"),
|
||||
copied: () => t("vcs.state.copied"),
|
||||
};
|
||||
|
||||
/** The list element. */
|
||||
const listEl = ref<HTMLElement | null>(null);
|
||||
/** The text filter as typed. */
|
||||
const query = ref(log.filters.query);
|
||||
/** The author filter as typed. */
|
||||
const author = ref(log.filters.author);
|
||||
/** Index of the focused file in the details. */
|
||||
const fileIndex = ref(0);
|
||||
/** Pending filter timer. */
|
||||
let timer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
/** Width of the graph column: the widest loaded row. */
|
||||
const graphWidth = computed(() => {
|
||||
if (!log.graphShown) {
|
||||
return LANE;
|
||||
}
|
||||
let lanes = 1;
|
||||
for (const row of log.rows) {
|
||||
lanes = Math.max(lanes, row.width);
|
||||
}
|
||||
return lanes * LANE + LANE / 2;
|
||||
});
|
||||
|
||||
/** The status line: loading, an error or an empty result; null otherwise. */
|
||||
const status = computed(() => {
|
||||
if (!project.root) {
|
||||
return t("vcs.log.noProject");
|
||||
}
|
||||
if (log.error !== null) {
|
||||
return t("vcs.log.failed", { reason: log.error });
|
||||
}
|
||||
if (log.commits.length === 0) {
|
||||
return log.loading || !log.loaded ? t("vcs.log.loading") : t("vcs.log.empty");
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
/**
|
||||
* Colour of a lane.
|
||||
*
|
||||
* @param lane - lane index.
|
||||
*/
|
||||
function laneColour(lane: number): string {
|
||||
return LANE_COLOURS[lane % LANE_COLOURS.length] ?? "var(--lt-accent)";
|
||||
}
|
||||
|
||||
/**
|
||||
* The x coordinate of a column's centre.
|
||||
*
|
||||
* @param column - column index.
|
||||
*/
|
||||
function x(column: number): number {
|
||||
return column * LANE + LANE / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* SVG path of a segment.
|
||||
*
|
||||
* @param from - column at the start.
|
||||
* @param to - column at the end.
|
||||
* @param top - whether it runs from the top edge to the middle.
|
||||
*/
|
||||
function segmentPath(from: number, to: number, top: boolean): string {
|
||||
const y0 = top ? 0 : ROW / 2;
|
||||
const y1 = top ? ROW / 2 : ROW;
|
||||
if (from === to) {
|
||||
return ["M", x(from), y0, "L", x(to), y1].join(" ");
|
||||
}
|
||||
const mid = (y0 + y1) / 2;
|
||||
return ["M", x(from), y0, "C", x(from), mid, x(to), mid, x(to), y1].join(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* The graph row of a commit, or null when the graph is hidden.
|
||||
*
|
||||
* @param index - row index.
|
||||
*/
|
||||
function rowAt(index: number): GraphRow | null {
|
||||
return log.graphShown ? (log.rows[index] ?? null) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A date for the list: the local date and time, short.
|
||||
*
|
||||
* @param iso - ISO 8601 date.
|
||||
*/
|
||||
function shortDate(iso: string): string {
|
||||
const date = new Date(iso);
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return iso;
|
||||
}
|
||||
return date.toLocaleString(undefined, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
|
||||
}
|
||||
|
||||
/** Applies the typed filters now. */
|
||||
function applyFilters(): void {
|
||||
if (timer !== null) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
if (query.value === log.filters.query && author.value === log.filters.author) {
|
||||
return;
|
||||
}
|
||||
void log.setFilters({ query: query.value, author: author.value });
|
||||
}
|
||||
|
||||
/** Applies the typed filters after {@link FILTER_DELAY_MS}. */
|
||||
function scheduleFilters(): void {
|
||||
if (timer !== null) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
timer = setTimeout(applyFilters, FILTER_DELAY_MS);
|
||||
}
|
||||
|
||||
/** Clears the path filter. */
|
||||
function clearPath(): void {
|
||||
void log.setFilters({ path: null });
|
||||
}
|
||||
|
||||
/** Loads the next page when the list is scrolled near its end. */
|
||||
function onScroll(): void {
|
||||
const el = listEl.value;
|
||||
if (el && el.scrollTop + el.clientHeight >= el.scrollHeight - PRELOAD_ROWS * ROW) {
|
||||
void log.loadMore();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the commit at an index and keeps it in view.
|
||||
*
|
||||
* @param index - row index (clamped).
|
||||
*/
|
||||
function selectAt(index: number): void {
|
||||
const count = log.commits.length;
|
||||
if (count === 0) {
|
||||
return;
|
||||
}
|
||||
const clamped = Math.max(0, Math.min(count - 1, index));
|
||||
fileIndex.value = 0;
|
||||
void log.select(log.commits[clamped]?.hash ?? null);
|
||||
void nextTick(() => {
|
||||
listEl.value?.querySelector(`[data-index="${String(clamped)}"]`)?.scrollIntoView({ block: "nearest" });
|
||||
});
|
||||
if (clamped >= count - PRELOAD_ROWS) {
|
||||
void log.loadMore();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Keyboard handling of the list.
|
||||
*
|
||||
* @param event - the key press.
|
||||
*/
|
||||
function onListKey(event: KeyboardEvent): void {
|
||||
const index = log.commits.findIndex((c) => c.hash === log.selected);
|
||||
const page = Math.max(1, Math.floor((listEl.value?.clientHeight ?? ROW * 10) / ROW) - 1);
|
||||
const moves: Record<string, number> = {
|
||||
ArrowDown: index + 1,
|
||||
ArrowUp: index - 1,
|
||||
PageDown: index + page,
|
||||
PageUp: index - page,
|
||||
Home: 0,
|
||||
End: log.commits.length - 1,
|
||||
};
|
||||
const target = moves[event.key];
|
||||
if (target === undefined) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
selectAt(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a file's diff at the selected commit.
|
||||
*
|
||||
* @param file - the file.
|
||||
*/
|
||||
function openFile(file: CommitFile): void {
|
||||
void log.openFile(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Keyboard handling of the file list.
|
||||
*
|
||||
* @param event - the key press.
|
||||
*/
|
||||
function onFilesKey(event: KeyboardEvent): void {
|
||||
const files = log.details?.files ?? [];
|
||||
if (files.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
fileIndex.value = Math.max(0, Math.min(files.length - 1, fileIndex.value + (event.key === "ArrowDown" ? 1 : -1)));
|
||||
} else if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
const file = files[fileIndex.value];
|
||||
if (file) {
|
||||
openFile(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (timer !== null) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="log"
|
||||
data-test="log-window"
|
||||
>
|
||||
<div class="log__toolbar">
|
||||
<input
|
||||
v-model="query"
|
||||
class="log__filter"
|
||||
type="search"
|
||||
:placeholder="t('vcs.log.filterText')"
|
||||
:aria-label="t('vcs.log.filterText')"
|
||||
data-test="log-filter-text"
|
||||
@input="scheduleFilters"
|
||||
@keydown.enter="applyFilters"
|
||||
>
|
||||
<input
|
||||
v-model="author"
|
||||
class="log__filter log__filter--author"
|
||||
type="search"
|
||||
:placeholder="t('vcs.log.filterAuthor')"
|
||||
:aria-label="t('vcs.log.filterAuthor')"
|
||||
data-test="log-filter-author"
|
||||
@input="scheduleFilters"
|
||||
@keydown.enter="applyFilters"
|
||||
>
|
||||
<span
|
||||
v-if="log.filters.path !== null"
|
||||
class="log__chip"
|
||||
data-test="log-path"
|
||||
>
|
||||
{{ t("vcs.log.historyOf", { path: log.filters.path }) }}
|
||||
<button
|
||||
type="button"
|
||||
class="log__icon-button"
|
||||
:aria-label="t('vcs.log.clearPath')"
|
||||
:title="t('vcs.log.clearPath')"
|
||||
data-test="log-path-clear"
|
||||
@click="clearPath"
|
||||
>
|
||||
<X :size="12" />
|
||||
</button>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="log__icon-button log__refresh"
|
||||
:aria-label="t('vcs.log.refresh')"
|
||||
:title="t('vcs.log.refresh')"
|
||||
data-test="log-refresh"
|
||||
@click="log.reload()"
|
||||
>
|
||||
<RefreshCw :size="14" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="log__body">
|
||||
<div
|
||||
ref="listEl"
|
||||
class="log__list"
|
||||
role="listbox"
|
||||
tabindex="0"
|
||||
:aria-label="t('vcs.log.listLabel')"
|
||||
:aria-activedescendant="log.selected ? `log-row-${log.selected}` : undefined"
|
||||
data-test="log-list"
|
||||
@scroll="onScroll"
|
||||
@keydown="onListKey"
|
||||
>
|
||||
<div
|
||||
v-if="status"
|
||||
class="log__status"
|
||||
data-test="log-status"
|
||||
>
|
||||
{{ status }}
|
||||
</div>
|
||||
<div
|
||||
v-for="(commit, index) in log.commits"
|
||||
:id="`log-row-${commit.hash}`"
|
||||
:key="commit.hash"
|
||||
class="log__row"
|
||||
:class="{ 'log__row--selected': commit.hash === log.selected }"
|
||||
role="option"
|
||||
:aria-selected="commit.hash === log.selected"
|
||||
:data-index="index"
|
||||
:data-hash="commit.hash"
|
||||
data-test="log-row"
|
||||
@click="selectAt(index)"
|
||||
>
|
||||
<svg
|
||||
class="log__graph"
|
||||
:width="graphWidth"
|
||||
:height="ROW"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<template v-if="rowAt(index)">
|
||||
<path
|
||||
v-for="(seg, i) in rowAt(index)?.up ?? []"
|
||||
:key="`u${i}`"
|
||||
:d="segmentPath(seg.from, seg.to, true)"
|
||||
:stroke="laneColour(seg.lane)"
|
||||
fill="none"
|
||||
stroke-width="1.5"
|
||||
/>
|
||||
<path
|
||||
v-for="(seg, i) in rowAt(index)?.down ?? []"
|
||||
:key="`d${i}`"
|
||||
:d="segmentPath(seg.from, seg.to, false)"
|
||||
:stroke="laneColour(seg.lane)"
|
||||
fill="none"
|
||||
stroke-width="1.5"
|
||||
/>
|
||||
</template>
|
||||
<circle
|
||||
:cx="x(rowAt(index)?.column ?? 0)"
|
||||
:cy="ROW / 2"
|
||||
:r="rowAt(index)?.merge ? 3 : 3.5"
|
||||
:fill="rowAt(index)?.merge ? 'var(--lt-bg)' : laneColour(rowAt(index)?.column ?? 0)"
|
||||
:stroke="laneColour(rowAt(index)?.column ?? 0)"
|
||||
stroke-width="1.5"
|
||||
data-test="log-dot"
|
||||
/>
|
||||
</svg>
|
||||
<span class="log__subject">
|
||||
<span
|
||||
v-for="badge in refBadges(commit.refs)"
|
||||
:key="`${badge.kind}:${badge.name}`"
|
||||
class="log__badge"
|
||||
:class="`log__badge--${badge.kind}`"
|
||||
data-test="log-badge"
|
||||
>{{ badge.name }}</span>
|
||||
{{ commit.subject }}
|
||||
</span>
|
||||
<span class="log__author">{{ commit.author }}</span>
|
||||
<span class="log__date">{{ shortDate(commit.date) }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="log.loading && log.commits.length > 0"
|
||||
class="log__status"
|
||||
>
|
||||
{{ t("vcs.log.loadingMore") }}
|
||||
</div>
|
||||
</div>
|
||||
<section
|
||||
class="log__details"
|
||||
:aria-label="t('vcs.log.details')"
|
||||
data-test="log-details"
|
||||
>
|
||||
<div
|
||||
v-if="log.detailsLoading"
|
||||
class="log__status"
|
||||
>
|
||||
{{ t("vcs.log.detailsLoading") }}
|
||||
</div>
|
||||
<div
|
||||
v-else-if="log.detailsError !== null"
|
||||
class="log__status log__status--error"
|
||||
>
|
||||
{{ t("vcs.log.detailsFailed", { reason: log.detailsError }) }}
|
||||
</div>
|
||||
<template v-else-if="log.details">
|
||||
<div
|
||||
class="log__meta"
|
||||
data-test="log-meta"
|
||||
>
|
||||
<span class="log__hash">{{ log.details.hash.slice(0, SHORT_HASH) }}</span>
|
||||
{{ t("vcs.log.byLine", { author: log.details.author, email: log.details.email, date: shortDate(log.details.date) }) }}
|
||||
</div>
|
||||
<pre
|
||||
class="log__message"
|
||||
data-test="log-message"
|
||||
>{{ log.details.message }}</pre>
|
||||
<div
|
||||
class="log__files"
|
||||
role="listbox"
|
||||
tabindex="0"
|
||||
:aria-label="t('vcs.log.files', { count: log.details.files.length })"
|
||||
data-test="log-files"
|
||||
@keydown="onFilesKey"
|
||||
>
|
||||
<div class="log__files-title">
|
||||
{{ t("vcs.log.files", { count: log.details.files.length }) }}
|
||||
</div>
|
||||
<div
|
||||
v-for="(file, i) in log.details.files"
|
||||
:key="file.path"
|
||||
class="log__file"
|
||||
:class="[`log__file--${file.status}`, { 'log__file--focused': i === fileIndex }]"
|
||||
role="option"
|
||||
:aria-selected="i === fileIndex"
|
||||
:title="t('vcs.log.openDiff')"
|
||||
data-test="log-file"
|
||||
@click="fileIndex = i"
|
||||
@dblclick="openFile(file)"
|
||||
>
|
||||
<span class="log__file-path">{{ file.path }}</span>
|
||||
<span
|
||||
v-if="file.origPath"
|
||||
class="log__file-from"
|
||||
>{{ t("vcs.changes.renamedFrom", { path: file.origPath }) }}</span>
|
||||
<span class="log__file-state">{{ STATE_LABELS[file.status]() }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="log.details.truncated"
|
||||
class="log__status"
|
||||
>
|
||||
{{ t("vcs.log.truncated") }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.log {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
color: var(--lt-fg);
|
||||
font-size: var(--lt-font-size-ui);
|
||||
}
|
||||
|
||||
.log__toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--lt-space-s, 4px);
|
||||
flex: none;
|
||||
padding: var(--lt-space-xs, 2px) var(--lt-space-s, 4px);
|
||||
border-bottom: 1px solid var(--lt-border);
|
||||
}
|
||||
|
||||
.log__filter {
|
||||
width: 220px;
|
||||
padding: 2px 6px;
|
||||
color: var(--lt-fg);
|
||||
background: var(--lt-editor-bg);
|
||||
border: 1px solid var(--lt-border);
|
||||
border-radius: var(--lt-radius, 4px);
|
||||
}
|
||||
|
||||
.log__filter--author {
|
||||
width: 140px;
|
||||
}
|
||||
|
||||
.log__filter:focus-visible {
|
||||
outline: 2px solid var(--lt-accent);
|
||||
}
|
||||
|
||||
.log__chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
padding: 0 2px 0 8px;
|
||||
color: var(--lt-fg);
|
||||
background: color-mix(in srgb, var(--lt-accent) 18%, transparent);
|
||||
border-radius: var(--lt-radius, 4px);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.log__icon-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px;
|
||||
color: var(--lt-fg-muted);
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: var(--lt-radius, 4px);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.log__icon-button:hover {
|
||||
color: var(--lt-fg);
|
||||
}
|
||||
|
||||
.log__icon-button:focus-visible {
|
||||
outline: 2px solid var(--lt-accent);
|
||||
}
|
||||
|
||||
.log__refresh {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.log__body {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.log__list {
|
||||
flex: 3;
|
||||
min-width: 0;
|
||||
overflow: auto;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.log__list:focus-visible {
|
||||
box-shadow: inset 0 0 0 1px var(--lt-accent);
|
||||
}
|
||||
|
||||
.log__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--lt-space-m, 8px);
|
||||
height: 22px;
|
||||
padding: 0 var(--lt-space-m, 8px) 0 var(--lt-space-s, 4px);
|
||||
white-space: nowrap;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.log__row:hover {
|
||||
background: color-mix(in srgb, var(--lt-fg) 6%, transparent);
|
||||
}
|
||||
|
||||
.log__row--selected,
|
||||
.log__row--selected:hover {
|
||||
background: var(--lt-editor-selection-bg);
|
||||
}
|
||||
|
||||
.log__graph {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.log__subject {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.log__badge {
|
||||
margin-right: 4px;
|
||||
padding: 0 4px;
|
||||
font-size: var(--lt-font-size-small);
|
||||
border: 1px solid var(--lt-border);
|
||||
border-radius: var(--lt-radius, 4px);
|
||||
}
|
||||
|
||||
.log__badge--head {
|
||||
color: var(--lt-accent);
|
||||
border-color: var(--lt-accent);
|
||||
}
|
||||
|
||||
.log__badge--branch {
|
||||
color: var(--lt-vcs-added);
|
||||
border-color: var(--lt-vcs-added);
|
||||
}
|
||||
|
||||
.log__badge--remote {
|
||||
color: var(--lt-vcs-modified);
|
||||
border-color: var(--lt-vcs-modified);
|
||||
}
|
||||
|
||||
.log__badge--tag {
|
||||
color: var(--lt-syntax-string);
|
||||
border-color: var(--lt-syntax-string);
|
||||
}
|
||||
|
||||
.log__author {
|
||||
flex: none;
|
||||
width: 140px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.log__date {
|
||||
flex: none;
|
||||
color: var(--lt-fg-muted);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.log__details {
|
||||
flex: 2;
|
||||
min-width: 0;
|
||||
overflow: auto;
|
||||
padding: var(--lt-space-s, 4px) var(--lt-space-m, 8px);
|
||||
border-left: 1px solid var(--lt-border);
|
||||
}
|
||||
|
||||
.log__status {
|
||||
padding: var(--lt-space-s, 4px) var(--lt-space-m, 8px);
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.log__status--error {
|
||||
color: var(--lt-error);
|
||||
}
|
||||
|
||||
.log__meta {
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.log__hash {
|
||||
margin-right: 6px;
|
||||
color: var(--lt-fg);
|
||||
font-family: var(--lt-font-mono);
|
||||
}
|
||||
|
||||
.log__message {
|
||||
margin: var(--lt-space-s, 4px) 0;
|
||||
font-family: var(--lt-font-mono);
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.log__files {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.log__files:focus-visible {
|
||||
box-shadow: inset 0 0 0 1px var(--lt-accent);
|
||||
}
|
||||
|
||||
.log__files-title {
|
||||
margin-top: var(--lt-space-s, 4px);
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.log__file {
|
||||
display: flex;
|
||||
gap: var(--lt-space-s, 4px);
|
||||
padding: 1px 4px;
|
||||
white-space: nowrap;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.log__file--focused {
|
||||
background: var(--lt-editor-selection-bg);
|
||||
}
|
||||
|
||||
.log__file-path {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.log__file--added .log__file-path {
|
||||
color: var(--lt-vcs-added);
|
||||
}
|
||||
|
||||
.log__file--modified .log__file-path,
|
||||
.log__file--renamed .log__file-path {
|
||||
color: var(--lt-vcs-modified);
|
||||
}
|
||||
|
||||
.log__file--copied .log__file-path {
|
||||
color: var(--lt-vcs-added);
|
||||
}
|
||||
|
||||
.log__file--deleted .log__file-path {
|
||||
color: var(--lt-vcs-deleted);
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.log__file-from,
|
||||
.log__file-state {
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.log__file-state {
|
||||
margin-left: auto;
|
||||
}
|
||||
</style>
|
||||
145
ui/src/components/vcs/log/graph.ts
Normal file
145
ui/src/components/vcs/log/graph.ts
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/**
|
||||
* Graph lanes of the Log (M4.6): which column each commit sits in and the
|
||||
* line segments drawn above and below its dot.
|
||||
*
|
||||
* Commits arrive newest first in topological order (`git.log`), so every
|
||||
* child comes before its parents. A lane is a column waiting for a commit:
|
||||
* - A commit takes the leftmost lane waiting for it (or the first free one)
|
||||
* and every other lane waiting for it joins it from above.
|
||||
* - Its first parent continues in its column, even when another lane
|
||||
* waits for that parent too (both join when the parent comes); further
|
||||
* parents (merges) join a lane already waiting for them, or take the
|
||||
* first free column.
|
||||
* - Lanes that pass by run straight down.
|
||||
*
|
||||
* Pages extend the layout: {@link layoutGraph} takes the lanes left by
|
||||
* the previous page, so loading more never redraws rows already shown.
|
||||
* Lanes are capped at {@link MAX_LANES}; commits beyond that share the
|
||||
* last column (rare, and only the picture suffers).
|
||||
*/
|
||||
|
||||
/** Most columns drawn. */
|
||||
export const MAX_LANES = 24;
|
||||
|
||||
/** The commit fields the layout needs. */
|
||||
export interface GraphCommit {
|
||||
/** Full hash. */
|
||||
hash: string;
|
||||
/** Parent hashes, first parent first. */
|
||||
parents: readonly string[];
|
||||
}
|
||||
|
||||
/** A line inside one row, from a column at one edge to a column at the dot's height. */
|
||||
export interface Segment {
|
||||
/** Column at the row's top (for `up`) or at the dot's height (for `down`). */
|
||||
from: number;
|
||||
/** Column at the dot's height (for `up`) or at the row's bottom (for `down`). */
|
||||
to: number;
|
||||
/** Colour index of the lane. */
|
||||
lane: number;
|
||||
}
|
||||
|
||||
/** The drawing of one row. */
|
||||
export interface GraphRow {
|
||||
/** Column of the commit's dot. */
|
||||
column: number;
|
||||
/** Lines from the top edge to the dot's height. */
|
||||
up: Segment[];
|
||||
/** Lines from the dot's height to the bottom edge. */
|
||||
down: Segment[];
|
||||
/** Columns used by the row (for its width). */
|
||||
width: number;
|
||||
/** The commit is a merge (more than one parent). */
|
||||
merge: boolean;
|
||||
}
|
||||
|
||||
/** Lanes waiting for commits, carried from one page to the next. */
|
||||
export type Lanes = (string | null)[];
|
||||
|
||||
/**
|
||||
* Lays out rows for a page of commits.
|
||||
*
|
||||
* @param commits - the page, newest first in topological order.
|
||||
* @param carried - lanes left by the previous page (not changed).
|
||||
* @returns the rows and the lanes for the next page.
|
||||
*/
|
||||
export function layoutGraph(commits: readonly GraphCommit[], carried: Lanes = []): { rows: GraphRow[]; lanes: Lanes } {
|
||||
const lanes: Lanes = carried.slice(0, MAX_LANES);
|
||||
const rows: GraphRow[] = [];
|
||||
for (const commit of commits) {
|
||||
const before = lanes.slice();
|
||||
let column = lanes.indexOf(commit.hash);
|
||||
if (column < 0) {
|
||||
column = freeColumn(lanes);
|
||||
}
|
||||
const up: Segment[] = [];
|
||||
before.forEach((waiting, i) => {
|
||||
if (waiting === null) {
|
||||
return;
|
||||
}
|
||||
if (waiting === commit.hash) {
|
||||
up.push({ from: i, to: column, lane: i });
|
||||
lanes[i] = null;
|
||||
} else {
|
||||
up.push({ from: i, to: i, lane: i });
|
||||
}
|
||||
});
|
||||
const targets: number[] = [];
|
||||
commit.parents.forEach((parent, k) => {
|
||||
if (k === 0 && lanes[column] === null) {
|
||||
lanes[column] = parent;
|
||||
targets.push(column);
|
||||
return;
|
||||
}
|
||||
const existing = lanes.indexOf(parent);
|
||||
if (existing >= 0) {
|
||||
targets.push(existing);
|
||||
return;
|
||||
}
|
||||
const slot = freeColumn(lanes);
|
||||
lanes[slot] = parent;
|
||||
targets.push(slot);
|
||||
});
|
||||
while (lanes.length > 0 && lanes[lanes.length - 1] === null) {
|
||||
lanes.pop();
|
||||
}
|
||||
const down: Segment[] = [];
|
||||
lanes.forEach((waiting, i) => {
|
||||
if (waiting === null) {
|
||||
return;
|
||||
}
|
||||
if (before[i] !== null && before[i] !== undefined && before[i] !== commit.hash) {
|
||||
down.push({ from: i, to: i, lane: i });
|
||||
}
|
||||
});
|
||||
for (const target of new Set(targets)) {
|
||||
down.push({ from: column, to: target, lane: target });
|
||||
}
|
||||
rows.push({
|
||||
column,
|
||||
up,
|
||||
down,
|
||||
width: Math.max(before.length, lanes.length, column + 1),
|
||||
merge: commit.parents.length > 1,
|
||||
});
|
||||
}
|
||||
return { rows, lanes };
|
||||
}
|
||||
|
||||
/**
|
||||
* The first free column, appending one when all are taken (up to
|
||||
* {@link MAX_LANES}; past it, the last column).
|
||||
*
|
||||
* @param lanes - the lanes; extended in place when a column is appended.
|
||||
*/
|
||||
function freeColumn(lanes: Lanes): number {
|
||||
const free = lanes.indexOf(null);
|
||||
if (free >= 0) {
|
||||
return free;
|
||||
}
|
||||
if (lanes.length < MAX_LANES) {
|
||||
lanes.push(null);
|
||||
return lanes.length - 1;
|
||||
}
|
||||
return MAX_LANES - 1;
|
||||
}
|
||||
556
ui/src/components/vcs/log/log.ts
Normal file
556
ui/src/components/vcs/log/log.ts
Normal file
|
|
@ -0,0 +1,556 @@
|
|||
/**
|
||||
* The Log tool window's state (M4.6): pages of `git.log`, the filters, the
|
||||
* selected commit and its details.
|
||||
*
|
||||
* - **Pages:** {@link PAGE_SIZE} commits per `git.log` call (a pending
|
||||
* outcome, so through `runWaiting`); {@link LogStore.loadMore} asks for
|
||||
* the next page when the list is scrolled near its end. A page shorter
|
||||
* than asked for ends the history. One load runs at a time; a filter
|
||||
* change or a refresh starts over (a generation counter drops answers
|
||||
* of older loads). At most {@link MAX_COMMITS} commits are kept.
|
||||
* - **Filters:** text in the message, author, and a path (a file's or
|
||||
* folder's history: `vcs.showHistory`). Text and author filters are
|
||||
* applied by git; the graph is drawn only without them, because the
|
||||
* filtered commits' parents are not in the list.
|
||||
* - **Details:** selecting a commit reads `git.showCommit`; a file of it
|
||||
* opens in the diff viewer at that commit (`useDiffStore().openAtCommit`).
|
||||
* - **Refresh:** `gitChanged` reloads the first page when the HEAD or the
|
||||
* branch moved (a commit, a checkout), not on every index change;
|
||||
* opening a project clears everything, closing one too.
|
||||
* - **Untrusted input:** results are checked field by field; malformed
|
||||
* commits and files are dropped.
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref, shallowRef } from "vue";
|
||||
import { t } from "../../../i18n";
|
||||
import { onEngineEvent, runWaiting, type EngineEventPayload, type JsonValue } from "../../../ipc";
|
||||
import { useNotificationsStore } from "../../../stores/notifications";
|
||||
import { useDiffStore } from "../diff/diff";
|
||||
import { layoutGraph, type GraphRow, type Lanes } from "./graph";
|
||||
|
||||
/** Commits per `git.log` page. */
|
||||
export const PAGE_SIZE = 100;
|
||||
|
||||
/** Most commits kept in the list. */
|
||||
export const MAX_COMMITS = 50_000;
|
||||
|
||||
/** Most files of a commit shown. */
|
||||
export const MAX_FILES = 10_000;
|
||||
|
||||
/** Command id that shows the Log tab. */
|
||||
export const SHOW_LOG_COMMAND = "vcs.showLog";
|
||||
|
||||
/** Command id that shows the history of a file or folder. */
|
||||
export const SHOW_HISTORY_COMMAND = "vcs.showHistory";
|
||||
|
||||
/** One commit of the list. */
|
||||
export interface LogCommit {
|
||||
/** Full hash. */
|
||||
hash: string;
|
||||
/** Parent hashes, first parent first. */
|
||||
parents: string[];
|
||||
/** Author name. */
|
||||
author: string;
|
||||
/** Author email. */
|
||||
email: string;
|
||||
/** Author date, ISO 8601. */
|
||||
date: string;
|
||||
/** Subject line. */
|
||||
subject: string;
|
||||
/** Decorations: `HEAD -> main`, `origin/main`, `tag: v1`. */
|
||||
refs: string[];
|
||||
}
|
||||
|
||||
/** How a file changed in a commit. */
|
||||
export type CommitFileStatus = "added" | "modified" | "deleted" | "renamed" | "copied";
|
||||
|
||||
/** A file changed by a commit. */
|
||||
export interface CommitFile {
|
||||
/** Project-relative path after the commit. */
|
||||
path: string;
|
||||
/** How it changed. */
|
||||
status: CommitFileStatus;
|
||||
/** Its path before a rename or copy. */
|
||||
origPath: string | null;
|
||||
}
|
||||
|
||||
/** A commit's details. */
|
||||
export interface CommitDetails {
|
||||
/** Full hash. */
|
||||
hash: string;
|
||||
/** Parent hashes. */
|
||||
parents: string[];
|
||||
/** Author name. */
|
||||
author: string;
|
||||
/** Author email. */
|
||||
email: string;
|
||||
/** Author date, ISO 8601. */
|
||||
date: string;
|
||||
/** The full message. */
|
||||
message: string;
|
||||
/** Changed files against the first parent. */
|
||||
files: CommitFile[];
|
||||
/** More files changed than listed. */
|
||||
truncated: boolean;
|
||||
}
|
||||
|
||||
/** The filters of the list. */
|
||||
export interface LogFilters {
|
||||
/** Text in the message. */
|
||||
query: string;
|
||||
/** Text in the author name or email. */
|
||||
author: string;
|
||||
/** A file or folder; null for the whole project. */
|
||||
path: string | null;
|
||||
}
|
||||
|
||||
/** The kind of a ref decoration, for its badge. */
|
||||
export type RefKind = "head" | "branch" | "remote" | "tag";
|
||||
|
||||
/** A decoration, split for display. */
|
||||
export interface RefBadge {
|
||||
/** The name shown. */
|
||||
name: string;
|
||||
/** Its kind. */
|
||||
kind: RefKind;
|
||||
}
|
||||
|
||||
/** Statuses `git.showCommit` may report. */
|
||||
const FILE_STATUSES: readonly CommitFileStatus[] = ["added", "modified", "deleted", "renamed", "copied"];
|
||||
|
||||
/**
|
||||
* Narrows to a plain object.
|
||||
*
|
||||
* @param raw - anything.
|
||||
*/
|
||||
function record(raw: unknown): Record<string, unknown> | null {
|
||||
return typeof raw === "object" && raw !== null && !Array.isArray(raw) ? (raw as Record<string, unknown>) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of strings, or null when it is not one.
|
||||
*
|
||||
* @param raw - untrusted.
|
||||
*/
|
||||
function strings(raw: unknown): string[] | null {
|
||||
return Array.isArray(raw) && raw.every((item) => typeof item === "string") ? raw : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads one commit of `git.log`; null when malformed.
|
||||
*
|
||||
* @param raw - untrusted.
|
||||
*/
|
||||
export function toCommit(raw: unknown): LogCommit | null {
|
||||
const r = record(raw);
|
||||
if (!r) {
|
||||
return null;
|
||||
}
|
||||
const parents = strings(r.parents);
|
||||
const refs = strings(r.refs);
|
||||
const { hash, author, email, date, subject } = r;
|
||||
if (
|
||||
typeof hash !== "string" ||
|
||||
hash === "" ||
|
||||
parents === null ||
|
||||
refs === null ||
|
||||
typeof author !== "string" ||
|
||||
typeof email !== "string" ||
|
||||
typeof date !== "string" ||
|
||||
typeof subject !== "string"
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return { hash, parents, author, email, date, subject, refs };
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a `git.log` result; null when malformed. Malformed commits are
|
||||
* dropped.
|
||||
*
|
||||
* @param raw - untrusted.
|
||||
*/
|
||||
export function toCommits(raw: unknown): LogCommit[] | null {
|
||||
const list = record(raw)?.commits;
|
||||
if (!Array.isArray(list)) {
|
||||
return null;
|
||||
}
|
||||
return list.map(toCommit).filter((c): c is LogCommit => c !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a `git.showCommit` result; null when malformed.
|
||||
*
|
||||
* @param raw - untrusted.
|
||||
*/
|
||||
export function toDetails(raw: unknown): CommitDetails | null {
|
||||
const r = record(raw);
|
||||
const parents = strings(r?.parents);
|
||||
if (!r || parents === null || !Array.isArray(r.files)) {
|
||||
return null;
|
||||
}
|
||||
const { hash, author, email, date, message } = r;
|
||||
if (typeof hash !== "string" || typeof author !== "string" || typeof date !== "string" || typeof message !== "string") {
|
||||
return null;
|
||||
}
|
||||
const files: CommitFile[] = [];
|
||||
for (const item of r.files.slice(0, MAX_FILES)) {
|
||||
const f = record(item);
|
||||
const status = FILE_STATUSES.find((s) => s === f?.status);
|
||||
if (!f || typeof f.path !== "string" || f.path === "" || status === undefined) {
|
||||
continue;
|
||||
}
|
||||
files.push({ path: f.path, status, origPath: typeof f.origPath === "string" ? f.origPath : null });
|
||||
}
|
||||
return {
|
||||
hash,
|
||||
parents,
|
||||
author,
|
||||
email: typeof email === "string" ? email : "",
|
||||
date,
|
||||
message,
|
||||
files,
|
||||
truncated: r.truncated === true || r.files.length > MAX_FILES,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits git's decorations into badges.
|
||||
*
|
||||
* @param refs - `HEAD -> main`, `origin/main`, `tag: v1`, `HEAD`; a name
|
||||
* with a `/` counts as a remote branch, `<remote>/HEAD` is left out.
|
||||
*/
|
||||
export function refBadges(refs: readonly string[]): RefBadge[] {
|
||||
const badges: RefBadge[] = [];
|
||||
for (const ref of refs) {
|
||||
if (ref.startsWith("HEAD -> ")) {
|
||||
badges.push({ name: "HEAD", kind: "head" }, { name: ref.slice("HEAD -> ".length), kind: "branch" });
|
||||
} else if (ref === "HEAD") {
|
||||
badges.push({ name: "HEAD", kind: "head" });
|
||||
} else if (ref.startsWith("tag: ")) {
|
||||
badges.push({ name: ref.slice("tag: ".length), kind: "tag" });
|
||||
} else if (ref.endsWith("/HEAD")) {
|
||||
continue;
|
||||
} else {
|
||||
badges.push({ name: ref, kind: ref.includes("/") ? "remote" : "branch" });
|
||||
}
|
||||
}
|
||||
return badges;
|
||||
}
|
||||
|
||||
/**
|
||||
* The `git.log` params of a page.
|
||||
*
|
||||
* @param filters - the filters.
|
||||
* @param skip - commits already loaded.
|
||||
*/
|
||||
export function logParams(filters: LogFilters, skip: number): Record<string, JsonValue> {
|
||||
const params: Record<string, JsonValue> = { skip, limit: PAGE_SIZE };
|
||||
if (filters.query.trim() !== "") {
|
||||
params.query = filters.query.trim();
|
||||
}
|
||||
if (filters.author.trim() !== "") {
|
||||
params.author = filters.author.trim();
|
||||
}
|
||||
if (filters.path !== null) {
|
||||
params.path = filters.path;
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
/** The Log store. */
|
||||
export const useLogStore = defineStore("log", () => {
|
||||
const notifications = useNotificationsStore();
|
||||
const diff = useDiffStore();
|
||||
|
||||
/** Whether the Log tab is shown. */
|
||||
const visible = ref(false);
|
||||
/** Whether the panel is expanded while the Log is shown. */
|
||||
const expanded = ref(true);
|
||||
/** The filters. */
|
||||
const filters = ref<LogFilters>({ query: "", author: "", path: null });
|
||||
/** Loaded commits, newest first. */
|
||||
const commits = shallowRef<LogCommit[]>([]);
|
||||
/** Graph rows, one per commit (empty while filtered by text or author). */
|
||||
const rows = shallowRef<GraphRow[]>([]);
|
||||
/** A page is loading. */
|
||||
const loading = ref(false);
|
||||
/** The history ended (the last page was short). */
|
||||
const complete = ref(false);
|
||||
/** The error of the last load; null if it worked. */
|
||||
const error = ref<string | null>(null);
|
||||
/** Hash of the selected commit. */
|
||||
const selected = ref<string | null>(null);
|
||||
/** The selected commit's details. */
|
||||
const details = shallowRef<CommitDetails | null>(null);
|
||||
/** The details are loading. */
|
||||
const detailsLoading = ref(false);
|
||||
/** Why the details could not be read; null if they could. */
|
||||
const detailsError = ref<string | null>(null);
|
||||
/** Something has been loaded since the last reset. */
|
||||
const loaded = ref(false);
|
||||
|
||||
/** Lanes left after the loaded commits. */
|
||||
let lanes: Lanes = [];
|
||||
/** Bumped on every reset; answers of older loads are dropped. */
|
||||
let generation = 0;
|
||||
/** Bumped on every selection; answers for older ones are dropped. */
|
||||
let detailsGeneration = 0;
|
||||
/** HEAD and branch of the last `gitChanged`, to reload only when they move. */
|
||||
let lastHead: string | null = null;
|
||||
|
||||
/** Whether the graph is drawn (no text or author filter). */
|
||||
const graphShown = computed(() => filters.value.query.trim() === "" && filters.value.author.trim() === "");
|
||||
|
||||
/** The selected commit, null when none or not loaded. */
|
||||
const selectedCommit = computed(() => commits.value.find((c) => c.hash === selected.value) ?? null);
|
||||
|
||||
/** Drops the list and starts over with the first page. */
|
||||
async function reload(): Promise<void> {
|
||||
generation += 1;
|
||||
commits.value = [];
|
||||
rows.value = [];
|
||||
lanes = [];
|
||||
complete.value = false;
|
||||
error.value = null;
|
||||
loading.value = false;
|
||||
loaded.value = false;
|
||||
await loadMore();
|
||||
}
|
||||
|
||||
/** Loads the next page, unless one is loading or the history ended. */
|
||||
async function loadMore(): Promise<void> {
|
||||
if (loading.value || complete.value || commits.value.length >= MAX_COMMITS) {
|
||||
return;
|
||||
}
|
||||
const mine = generation;
|
||||
loading.value = true;
|
||||
const result = await runWaiting("git.log", logParams(filters.value, commits.value.length));
|
||||
if (mine !== generation) {
|
||||
return;
|
||||
}
|
||||
loading.value = false;
|
||||
loaded.value = true;
|
||||
if (!result.ok) {
|
||||
error.value = result.error.message;
|
||||
complete.value = true;
|
||||
return;
|
||||
}
|
||||
const page = toCommits(result.value);
|
||||
if (page === null) {
|
||||
error.value = t("common.error.unexpectedResult", { command: "git.log" });
|
||||
complete.value = true;
|
||||
return;
|
||||
}
|
||||
error.value = null;
|
||||
if (graphShown.value) {
|
||||
const laid = layoutGraph(page, lanes);
|
||||
lanes = laid.lanes;
|
||||
rows.value = [...rows.value, ...laid.rows];
|
||||
}
|
||||
commits.value = [...commits.value, ...page];
|
||||
complete.value = page.length < PAGE_SIZE || commits.value.length >= MAX_COMMITS;
|
||||
if (selected.value === null && commits.value.length > 0) {
|
||||
void select(commits.value[0]?.hash ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects a commit and reads its details.
|
||||
*
|
||||
* @param hash - the commit, or null for none.
|
||||
*/
|
||||
async function select(hash: string | null): Promise<void> {
|
||||
if (hash === selected.value && (details.value?.hash === hash || detailsLoading.value)) {
|
||||
return;
|
||||
}
|
||||
selected.value = hash;
|
||||
detailsGeneration += 1;
|
||||
const mine = detailsGeneration;
|
||||
details.value = null;
|
||||
detailsError.value = null;
|
||||
if (hash === null) {
|
||||
detailsLoading.value = false;
|
||||
return;
|
||||
}
|
||||
detailsLoading.value = true;
|
||||
const result = await runWaiting("git.showCommit", { hash });
|
||||
if (mine !== detailsGeneration) {
|
||||
return;
|
||||
}
|
||||
detailsLoading.value = false;
|
||||
if (!result.ok) {
|
||||
detailsError.value = result.error.message;
|
||||
return;
|
||||
}
|
||||
const read = toDetails(result.value);
|
||||
if (read === null) {
|
||||
detailsError.value = t("common.error.unexpectedResult", { command: "git.showCommit" });
|
||||
return;
|
||||
}
|
||||
details.value = read;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a file of the selected commit in the diff viewer.
|
||||
*
|
||||
* @param file - a file of {@link details}.
|
||||
*/
|
||||
async function openFile(file: CommitFile): Promise<void> {
|
||||
const commit = details.value;
|
||||
if (!commit) {
|
||||
return;
|
||||
}
|
||||
await diff.openAtCommit(file.path, {
|
||||
hash: commit.hash,
|
||||
parent: commit.parents[0] ?? null,
|
||||
origPath: file.origPath,
|
||||
deleted: file.status === "deleted",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the filters and reloads.
|
||||
*
|
||||
* @param change - the filters to change.
|
||||
*/
|
||||
async function setFilters(change: Partial<LogFilters>): Promise<void> {
|
||||
filters.value = { ...filters.value, ...change };
|
||||
selected.value = null;
|
||||
details.value = null;
|
||||
await reload();
|
||||
}
|
||||
|
||||
/** Shows the tab (expanded) and loads the first page if nothing is loaded. */
|
||||
async function open(): Promise<void> {
|
||||
visible.value = true;
|
||||
expanded.value = true;
|
||||
if (!loaded.value && !loading.value) {
|
||||
await reload();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the history of a file or folder.
|
||||
*
|
||||
* @param path - project-relative path.
|
||||
*/
|
||||
async function showHistory(path: string): Promise<void> {
|
||||
visible.value = true;
|
||||
expanded.value = true;
|
||||
await setFilters({ path, query: "", author: "" });
|
||||
}
|
||||
|
||||
/** Hides the tab. */
|
||||
function hide(): void {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
/** Forgets everything (a project opened or closed). */
|
||||
function clear(): void {
|
||||
generation += 1;
|
||||
detailsGeneration += 1;
|
||||
commits.value = [];
|
||||
rows.value = [];
|
||||
lanes = [];
|
||||
loading.value = false;
|
||||
loaded.value = false;
|
||||
complete.value = false;
|
||||
error.value = null;
|
||||
selected.value = null;
|
||||
details.value = null;
|
||||
detailsLoading.value = false;
|
||||
detailsError.value = null;
|
||||
filters.value = { query: "", author: "", path: null };
|
||||
lastHead = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies one engine event.
|
||||
*
|
||||
* @param event - the event.
|
||||
*/
|
||||
function onEvent(event: EngineEventPayload): void {
|
||||
if (event.kind === "projectOpened" || event.kind === "projectClosed") {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
if (event.kind !== "gitChanged") {
|
||||
return;
|
||||
}
|
||||
const repo = record(event.repo);
|
||||
const text = (value: unknown): string => (typeof value === "string" ? value : "");
|
||||
const head = repo ? `${text(repo.head)}|${text(repo.branch)}` : null;
|
||||
const moved = head !== lastHead;
|
||||
lastHead = head;
|
||||
if (moved && loaded.value) {
|
||||
void reload();
|
||||
}
|
||||
}
|
||||
|
||||
/** Ends the event subscription; set while started. */
|
||||
let unsubscribe: (() => void) | null = null;
|
||||
|
||||
/** Subscribes to engine events; calling it again has no effect. */
|
||||
function start(): void {
|
||||
unsubscribe ??= onEngineEvent(onEvent);
|
||||
}
|
||||
|
||||
/** Ends the subscription. */
|
||||
function stop(): void {
|
||||
unsubscribe?.();
|
||||
unsubscribe = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs `vcs.showHistory {path?}`: the given path, else the active
|
||||
* editor tab's file.
|
||||
*
|
||||
* @param params - untrusted params.
|
||||
* @param fallback - the path to use without one (the active file);
|
||||
* with neither, a warning toast says so.
|
||||
*/
|
||||
async function runShowHistory(params: JsonValue, fallback: string | null): Promise<void> {
|
||||
const p = record(params) ?? {};
|
||||
const path = typeof p.path === "string" && p.path !== "" ? p.path : fallback;
|
||||
if (path === null) {
|
||||
notifications.notify({ level: "warning", messageKey: "notification.vcs.historyNoFile" });
|
||||
return;
|
||||
}
|
||||
await showHistory(path);
|
||||
}
|
||||
|
||||
return {
|
||||
visible,
|
||||
expanded,
|
||||
filters,
|
||||
commits,
|
||||
rows,
|
||||
loading,
|
||||
complete,
|
||||
error,
|
||||
loaded,
|
||||
selected,
|
||||
selectedCommit,
|
||||
details,
|
||||
detailsLoading,
|
||||
detailsError,
|
||||
graphShown,
|
||||
reload,
|
||||
loadMore,
|
||||
select,
|
||||
openFile,
|
||||
setFilters,
|
||||
open,
|
||||
showHistory,
|
||||
runShowHistory,
|
||||
hide,
|
||||
clear,
|
||||
onEvent,
|
||||
start,
|
||||
stop,
|
||||
};
|
||||
});
|
||||
|
||||
/** The Log store's type. */
|
||||
export type LogStore = ReturnType<typeof useLogStore>;
|
||||
|
|
@ -28,6 +28,8 @@
|
|||
"command.vcs.previousChange": "Previous Change",
|
||||
"command.vcs.refresh": "Refresh Changes",
|
||||
"command.vcs.showDiff": "Show Diff",
|
||||
"command.vcs.showHistory": "Show History",
|
||||
"command.vcs.showLog": "Log",
|
||||
"command.view.toggleProjectTree": "Show or Hide Project",
|
||||
"command.view.toggleStructure": "Show or Hide Structure",
|
||||
"common.cancel": "Cancel",
|
||||
|
|
@ -161,6 +163,7 @@
|
|||
"notification.vcs.checkoutNotSaved": "Checkout of {branch} cancelled: not every file could be saved first.",
|
||||
"notification.vcs.commitNotSaved": "Commit cancelled: not every file could be saved first.",
|
||||
"notification.vcs.committed": "Committed {hash}: {summary}",
|
||||
"notification.vcs.historyNoFile": "Open a file or pass a path to show its history",
|
||||
"notification.vcs.newBranchFailed": "Branch {branch} was not created: {reason}",
|
||||
"notification.vfs.pumpFailed": "Applying changes on disk failed: {reason}",
|
||||
"notification.watch.failed": "Lutra stopped watching the project for changes on disk: {reason}",
|
||||
|
|
@ -191,6 +194,7 @@
|
|||
"project.tree.menu.label": "Actions for {name}",
|
||||
"project.tree.menu.open": "Open",
|
||||
"project.tree.menu.showDiff": "Show Diff",
|
||||
"project.tree.menu.showHistory": "Show History",
|
||||
"project.tree.truncated": "Listing truncated: more entries than can be shown",
|
||||
"recovery.dialog.changedOnDisk": "The file changed on disk since then",
|
||||
"recovery.dialog.discard": "Discard",
|
||||
|
|
@ -323,6 +327,7 @@
|
|||
"vcs.commit.messageLabel": "Commit message",
|
||||
"vcs.commit.placeholder": "Commit message",
|
||||
"vcs.diff.binary": "Binary file: no text diff to show.",
|
||||
"vcs.diff.captionCommit": "{path}: before (left) and after (right) commit {hash}",
|
||||
"vcs.diff.captionHead": "{path}: last commit (left) and working copy (right)",
|
||||
"vcs.diff.captionIndex": "{path}: staged version (left) and working copy (right)",
|
||||
"vcs.diff.closeTab": "Close the diff of {name}",
|
||||
|
|
@ -331,9 +336,29 @@
|
|||
"vcs.diff.loading": "Reading the file from Git…",
|
||||
"vcs.diff.noFile": "Open a file or pass a path to show its diff",
|
||||
"vcs.diff.tabTitle": "Diff: {name}",
|
||||
"vcs.diff.tabTitleCommit": "Diff: {name} ({hash})",
|
||||
"vcs.diff.tabTitleStaged": "Diff: {name} (staged)",
|
||||
"vcs.diff.tooLarge": "The file is too large to compare.",
|
||||
"vcs.diff.workingCopyMissing": "The working copy cannot be opened ({reason}); it may have been deleted.",
|
||||
"vcs.log.byLine": "{author} <{email}>, {date}",
|
||||
"vcs.log.clearPath": "Show the whole project's history",
|
||||
"vcs.log.details": "Commit details",
|
||||
"vcs.log.detailsFailed": "The commit cannot be read: {reason}",
|
||||
"vcs.log.detailsLoading": "Reading the commit…",
|
||||
"vcs.log.empty": "No commits match",
|
||||
"vcs.log.failed": "The history cannot be read: {reason}",
|
||||
"vcs.log.files": "Changed files: {count}",
|
||||
"vcs.log.filterAuthor": "Author",
|
||||
"vcs.log.filterText": "Filter by message",
|
||||
"vcs.log.historyOf": "History of {path}",
|
||||
"vcs.log.listLabel": "Commits",
|
||||
"vcs.log.loading": "Reading the history…",
|
||||
"vcs.log.loadingMore": "Reading more commits…",
|
||||
"vcs.log.noProject": "Open a project to see its history",
|
||||
"vcs.log.openDiff": "Double-click or press Enter to open the diff at this commit",
|
||||
"vcs.log.refresh": "Reload the history",
|
||||
"vcs.log.toolWindow.title": "Log",
|
||||
"vcs.log.truncated": "More files changed than are listed here.",
|
||||
"vcs.state.added": "added",
|
||||
"vcs.state.conflicted": "conflicted",
|
||||
"vcs.state.copied": "copied",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue