mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
Implements first iteration of multi diff editors.
Co-authored-by: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com>
This commit is contained in:
@@ -3426,6 +3426,54 @@ export class CommandCenter {
|
||||
};
|
||||
}
|
||||
|
||||
@command('git.timeline.openCommit', { repository: false })
|
||||
async timelineOpenCommit(item: TimelineItem, uri: Uri | undefined, _source: string) {
|
||||
console.log('timelineOpenCommit', item);
|
||||
if (!GitTimelineItem.is(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cmd = await this._resolveTimelineOpenCommitCommand(
|
||||
item, uri,
|
||||
{
|
||||
preserveFocus: true,
|
||||
preview: true,
|
||||
viewColumn: ViewColumn.Active
|
||||
},
|
||||
);
|
||||
if (cmd === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return commands.executeCommand(cmd.command, ...(cmd.arguments ?? []));
|
||||
}
|
||||
|
||||
private async _resolveTimelineOpenCommitCommand(item: TimelineItem, uri: Uri | undefined, options?: TextDocumentShowOptions): Promise<Command | undefined> {
|
||||
if (uri === undefined || uri === null || !GitTimelineItem.is(item)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const repository = await this.model.getRepository(uri.fsPath);
|
||||
if (!repository) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const commit = await repository.getCommit(item.ref);
|
||||
const commitFiles = await repository.getCommitFiles(item.ref);
|
||||
|
||||
const args: [Uri, Uri | undefined, Uri | undefined][] = [];
|
||||
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)]);
|
||||
}
|
||||
|
||||
return {
|
||||
command: 'vscode.changes',
|
||||
title: l10n.t('Open Commit'),
|
||||
arguments: [`${item.shortRef} - ${commit.message}`, args, options]
|
||||
};
|
||||
}
|
||||
|
||||
@command('git.timeline.copyCommitId', { repository: false })
|
||||
async timelineCopyCommitId(item: TimelineItem, _uri: Uri | undefined, _source: string) {
|
||||
if (!GitTimelineItem.is(item)) {
|
||||
@@ -3603,6 +3651,26 @@ export class CommandCenter {
|
||||
repository.generateCommitMessageCancel();
|
||||
}
|
||||
|
||||
@command('git.viewChanges', { repository: true })
|
||||
viewChanges(repository: Repository): void {
|
||||
this._viewChanges('Changes', repository.workingTreeGroup.resourceStates);
|
||||
}
|
||||
|
||||
@command('git.viewStagedChanges', { repository: true })
|
||||
viewStagedChanges(repository: Repository): void {
|
||||
this._viewChanges('Staged Changes', repository.indexGroup.resourceStates);
|
||||
}
|
||||
|
||||
private _viewChanges(title: string, resources: Resource[]): void {
|
||||
const args: [Uri, Uri | undefined, Uri | undefined][] = [];
|
||||
|
||||
for (const resource of resources) {
|
||||
args.push([resource.resourceUri, resource.leftUri, resource.rightUri]);
|
||||
}
|
||||
|
||||
commands.executeCommand('vscode.changes', title, args);
|
||||
}
|
||||
|
||||
private createCommand(id: string, key: string, method: Function, options: ScmCommandOptions): (...args: any[]) => any {
|
||||
const result = (...args: any[]) => {
|
||||
let result: Promise<any>;
|
||||
|
||||
@@ -2552,6 +2552,11 @@ export class Repository {
|
||||
return commits[0];
|
||||
}
|
||||
|
||||
async getCommitFiles(ref: string): Promise<string[]> {
|
||||
const result = await this.exec(['diff-tree', '--no-commit-id', '--name-only', '-r', ref]);
|
||||
return result.stdout.split('\n').filter(l => !!l);
|
||||
}
|
||||
|
||||
async getCommitCount(range: string): Promise<{ ahead: number; behind: number }> {
|
||||
const result = await this.exec(['rev-list', '--count', '--left-right', range]);
|
||||
const [ahead, behind] = result.stdout.trim().split('\t');
|
||||
|
||||
@@ -1658,6 +1658,10 @@ export class Repository implements Disposable {
|
||||
return await this.repository.getCommit(ref);
|
||||
}
|
||||
|
||||
async getCommitFiles(ref: string): Promise<string[]> {
|
||||
return await this.repository.getCommitFiles(ref);
|
||||
}
|
||||
|
||||
async getCommitCount(range: string): Promise<{ ahead: number; behind: number }> {
|
||||
return await this.run(Operation.RevList, () => this.repository.getCommitCount(range));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user