дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
The Git Log toolbar gets a Cherry-Pick button next to Refresh that runs the existing vcs.log.cherryPick action. The context menu's can-apply rule (no merge commit, nothing from an external log) moves into canApplyCommits and backs both the action's enabled state and the menu. Hidden in external logs and File History. Closes #5738 Co-authored-by: wildcatDownstairs <[email protected]>
62 рядки
2.3 KiB
TypeScript
62 рядки
2.3 KiB
TypeScript
/** Repository identity for log rows and shared repository queries. */
|
|
import type { Branch, Commit } from "@/bindings";
|
|
import { call, commands } from "@/platform/ipc";
|
|
import type { GraphCommit } from "./graph";
|
|
|
|
export type RepoCommit = Commit & {
|
|
repo?: string | null;
|
|
user?: string | null;
|
|
userName?: string | null;
|
|
remoteNames?: string[];
|
|
refBranches?: Branch[];
|
|
readOnly?: boolean;
|
|
};
|
|
export const commitRepo = (c: Commit | undefined): string | null | undefined => (c as RepoCommit | undefined)?.repo;
|
|
export const commitKey = (c: Pick<RepoCommit, "id" | "repo">): string => (c.repo ? `${c.repo}\0${c.id}` : c.id);
|
|
/** Commits Cherry-Pick and Revert can apply: at least one, no merge commit, none from an external log. */
|
|
export const canApplyCommits = (commits: readonly Commit[]): boolean =>
|
|
commits.length > 0 && !commits.some((c) => c.parents.length > 1 || (c as RepoCommit).readOnly);
|
|
export const graphCommit = (c: Commit): Commit & GraphCommit => ({
|
|
...c,
|
|
id: commitKey(c),
|
|
parents: [...(c.graphParents ?? c.parents), ...(c.graphBoundaryParents ?? [])].map((id) => commitKey({ ...c, id })),
|
|
dashed: c.graphDashed ?? c.dashed,
|
|
edgeTypes: [
|
|
...(c.graphParents ?? c.parents).map((_, i) =>
|
|
(c.graphDashed ?? c.dashed)?.[i] ? ("filtered" as const) : ("normal" as const),
|
|
),
|
|
...(c.graphBoundaryParents ?? []).map(() => "shallow" as const),
|
|
],
|
|
});
|
|
|
|
/** Merge ordered streams without breaking any repository's topological order. */
|
|
export function mergeRepoLogs(streams: readonly RepoCommit[][], limit: number): RepoCommit[] {
|
|
const offsets = streams.map(() => 0);
|
|
const result: RepoCommit[] = [];
|
|
while (result.length < limit) {
|
|
let best = -1;
|
|
let latest = -Infinity;
|
|
for (let i = 0; i < streams.length; i++) {
|
|
const c = streams[i]![offsets[i]!];
|
|
if (!c) continue;
|
|
const time = c.logMergeTimeMs ?? c.commitTimeMs ?? c.timeMs ?? 0;
|
|
if (time > latest) {
|
|
best = i;
|
|
latest = time;
|
|
}
|
|
}
|
|
if (best < 0) break;
|
|
result.push(streams[best]![offsets[best]!]!);
|
|
offsets[best]!++;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export async function branchesByRepo(roots: readonly string[]): Promise<Record<string, Branch[]>> {
|
|
return Object.fromEntries(
|
|
await Promise.all(
|
|
roots.map(async (root) => [root, await call(commands.vcsBranches(root)).catch(() => [] as Branch[])] as const),
|
|
),
|
|
);
|
|
}
|