mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-03 23:06:49 +01:00
Git - use git diff-tree only for the first commit in the repository (#274107)
This commit is contained in:
@@ -1688,9 +1688,8 @@ export class Repository {
|
||||
return result.stdout.trim();
|
||||
}
|
||||
|
||||
async diffBetween2(ref1: string, ref2: string, options: { similarityThreshold?: number; symmetric?: boolean }): Promise<Change[]> {
|
||||
const range = options.symmetric ? `${ref1}...${ref2}` : `${ref1}..${ref2}`;
|
||||
return await this.diffFiles(range, { cached: false, similarityThreshold: options.similarityThreshold });
|
||||
async diffBetween2(ref1: string, ref2: string, options: { similarityThreshold?: number }): Promise<Change[]> {
|
||||
return await this.diffFiles(`${ref1}...${ref2}`, { cached: false, similarityThreshold: options.similarityThreshold });
|
||||
}
|
||||
|
||||
private async diffFiles(ref: string | undefined, options: { cached: boolean; similarityThreshold?: number }): Promise<Change[]> {
|
||||
@@ -1718,6 +1717,29 @@ export class Repository {
|
||||
return parseGitChanges(this.repositoryRoot, gitResult.stdout);
|
||||
}
|
||||
|
||||
async diffTrees(treeish1: string, treeish2?: string, options?: { similarityThreshold?: number }): Promise<Change[]> {
|
||||
const args = ['diff-tree', '-r', '--name-status', '-z', '--diff-filter=ADMR'];
|
||||
|
||||
if (options?.similarityThreshold) {
|
||||
args.push(`--find-renames=${options.similarityThreshold}%`);
|
||||
}
|
||||
|
||||
args.push(treeish1);
|
||||
|
||||
if (treeish2) {
|
||||
args.push(treeish2);
|
||||
}
|
||||
|
||||
args.push('--');
|
||||
|
||||
const gitResult = await this.exec(args);
|
||||
if (gitResult.exitCode) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return parseGitChanges(this.repositoryRoot, gitResult.stdout);
|
||||
}
|
||||
|
||||
async getMergeBase(ref1: string, ref2: string, ...refs: string[]): Promise<string | undefined> {
|
||||
try {
|
||||
const args = ['merge-base'];
|
||||
|
||||
@@ -1232,12 +1232,25 @@ export class Repository implements Disposable {
|
||||
}
|
||||
|
||||
diffBetween2(ref1: string, ref2: string): Promise<Change[]> {
|
||||
if (ref1 === this._EMPTY_TREE) {
|
||||
// Use git diff-tree to get the
|
||||
// changes in the first commit
|
||||
return this.diffTrees(ref1, ref2);
|
||||
}
|
||||
|
||||
const scopedConfig = workspace.getConfiguration('git', Uri.file(this.root));
|
||||
const similarityThreshold = scopedConfig.get<number>('similarityThreshold', 50);
|
||||
|
||||
return this.run(Operation.Diff, () => this.repository.diffBetween2(ref1, ref2, { similarityThreshold }));
|
||||
}
|
||||
|
||||
diffTrees(treeish1: string, treeish2?: string): Promise<Change[]> {
|
||||
const scopedConfig = workspace.getConfiguration('git', Uri.file(this.root));
|
||||
const similarityThreshold = scopedConfig.get<number>('similarityThreshold', 50);
|
||||
|
||||
return this.run(Operation.Diff, () => this.repository.diffTrees(treeish1, treeish2, { similarityThreshold }));
|
||||
}
|
||||
|
||||
getMergeBase(ref1: string, ref2: string, ...refs: string[]): Promise<string | undefined> {
|
||||
return this.run(Operation.MergeBase, () => this.repository.getMergeBase(ref1, ref2, ...refs));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user