Файли
openidea/src/features/vcs/diffBlame.ts
T
l0ng-ai 0d80e2c05a feat(vcs): annotate either side of a diff with Git Blame (#1476)
Right-clicking a line or the line numbers of a diff pane now offers Annotate with
Git Blame / Close Annotations. Each side is blamed on its own history: a revision on
that revision (at the path the file had there), the index on HEAD with its own text,
and the working file like the editor's annotations, refreshed after edits and when
HEAD moves. Compare Files, Local History and plain-text sides don't offer it. The
divider between the panes, which had no menu, acts on the pane focused last.

Fixes #1443
2026-11-05 14:03:46 +08:00

28 рядки
1.0 KiB
TypeScript

import type { DiffSide } from "./diffInput";
/** What `git blame` annotates a diff side with. */
export interface DiffBlameTarget {
/** The file at that side's revision (it may have been renamed since). */
path: string;
/** Blame history; unset for the working file, which follows HEAD and edits like the editor's annotations. */
revision?: string;
}
/**
* The blame for one side of a diff: a revision blames its own history, the working file the
* file on disk; Compare Files, Local History and plain texts are not Git content.
* The index (`:0`) is not a revision `git blame` takes, so its text is blamed on HEAD and the
* lines staged since show as not committed.
*/
export function diffBlameTarget(side: DiffSide, path: string, vcsAvailable: boolean): DiffBlameTarget | null {
if (!vcsAvailable) return null;
switch (side.type) {
case "rev":
return { path: side.path ?? path, revision: side.rev.startsWith(":") ? "HEAD" : side.rev };
case "worktree":
return { path };
default:
return null;
}
}