Git - adopt _workbench.openMultiDiffEditor command (#202236)

This commit is contained in:
Ladislau Szomoru 2024-01-11 12:21:17 +01:00 committed by GitHub
parent effbda690c
commit 8720ead44d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 16 deletions

View File

@ -3550,14 +3550,16 @@ export class CommandCenter {
return;
}
const args: [Uri, Uri | undefined, Uri | undefined][] = [];
const title = `Git Stash #${stash.index}: ${stash.description}`;
const multiDiffSourceUri = toGitUri(Uri.file(repository.root), `stash@{${stash.index}}`, { scheme: 'git-stash' });
const resources: { originalUri: Uri; modifiedUri: Uri }[] = [];
for (const file of stashFiles) {
const fileUri = Uri.file(path.join(repository.root, file));
args.push([fileUri, fileUri, toGitUri(fileUri, `stash@{${stash.index}}`)]);
resources.push({ originalUri: fileUri, modifiedUri: toGitUri(fileUri, `stash@{${stash.index}}`) });
}
commands.executeCommand('vscode.changes', `Git Stash #${stash.index}: ${stash.description}`, args);
commands.executeCommand('_workbench.openMultiDiffEditor', { multiDiffSourceUri, title, resources });
}
private async pickStash(repository: Repository, placeHolder: string): Promise<Stash | undefined> {
@ -3649,16 +3651,19 @@ export class CommandCenter {
const commit = await repository.getCommit(item.ref);
const commitFiles = await repository.getCommitFiles(item.ref);
const args: [Uri, Uri | undefined, Uri | undefined][] = [];
const title = `${item.shortRef} - ${commit.message}`;
const multiDiffSourceUri = toGitUri(Uri.file(repository.root), item.ref, { scheme: 'git-commit' });
const resources: { originalUri: Uri; modifiedUri: Uri }[] = [];
for (const commitFile of commitFiles) {
const commitFileUri = Uri.file(path.join(repository.root, commitFile));
args.push([commitFileUri, toGitUri(commitFileUri, item.previousRef), toGitUri(commitFileUri, item.ref)]);
resources.push({ originalUri: toGitUri(commitFileUri, item.previousRef), modifiedUri: toGitUri(commitFileUri, item.ref) });
}
return {
command: 'vscode.changes',
command: '_workbench.openMultiDiffEditor',
title: l10n.t('Open Commit'),
arguments: [`${item.shortRef} - ${commit.message}`, args, options]
arguments: [{ multiDiffSourceUri, title, resources }, options]
};
}
@ -3827,9 +3832,9 @@ export class CommandCenter {
const historyProvider = repository.historyProvider;
const historyItemParentId = historyItem.parentIds.length > 0 ? historyItem.parentIds[0] : undefined;
const historyItemChanges = await historyProvider.provideHistoryItemChanges(historyItem.id, historyItemParentId);
const commitFiles = await historyProvider.provideHistoryItemChanges(historyItem.id, historyItemParentId);
if (historyItemChanges.length === 0) {
if (commitFiles.length === 0) {
return;
}
@ -3837,9 +3842,10 @@ export class CommandCenter {
const originalShortRef = historyItem.parentIds.length > 0 ? historyItem.parentIds[0].substring(0, 8) : `${modifiedShortRef}^`;
const title = l10n.t('Changes ({0} ↔ {1})', originalShortRef, modifiedShortRef);
const args = historyItemChanges.map(change => [change.uri, change.originalUri, change.modifiedUri]);
const multiDiffSourceUri = toGitUri(Uri.file(repository.root), historyItem.id, { scheme: 'git-commit' });
const resources = commitFiles.map(change => ({ originalUri: change.originalUri, modifiedUri: change.modifiedUri }));
commands.executeCommand('vscode.changes', title, args);
commands.executeCommand('_workbench.openMultiDiffEditor', { multiDiffSourceUri, title, resources });
}
private createCommand(id: string, key: string, method: Function, options: ScmCommandOptions): (...args: any[]) => any {

View File

@ -20,6 +20,7 @@ export function fromGitUri(uri: Uri): GitUriParams {
}
export interface GitUriOptions {
scheme?: string;
replaceFileExtension?: boolean;
submoduleOf?: string;
}
@ -45,11 +46,7 @@ export function toGitUri(uri: Uri, ref: string, options: GitUriOptions = {}): Ur
path = `${path}.diff`;
}
return uri.with({
scheme: 'git',
path,
query: JSON.stringify(params)
});
return uri.with({ scheme: options.scheme ?? 'git', path, query: JSON.stringify(params) });
}
/**