Skip to content

Commit 0ecf237

Browse files
x13machineeamodio
authored andcommitted
Fixes #670 - Configure similarity index for diffs
1 parent e77be8b commit 0ecf237

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,12 @@
12931293
"markdownDescription": "Specifies whether to show avatar images instead of commit (or status) icons in the _Compare_ view",
12941294
"scope": "window"
12951295
},
1296+
"gitlens.views.compare.findRenames": {
1297+
"type": "number",
1298+
"default": 50,
1299+
"markdownDescription": "Specifies the threshold for the rename similarity index.",
1300+
"scope": "window"
1301+
},
12961302
"gitlens.views.compare.enabled": {
12971303
"type": "boolean",
12981304
"default": true,

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export interface CompareViewConfig {
244244
avatars: boolean;
245245
enabled: boolean;
246246
files: ViewsFilesConfig;
247+
findRenames: number;
247248
location: ViewLocation;
248249
}
249250

src/git/git.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,14 @@ export class Git {
525525
}
526526
}
527527

528-
static diff_nameStatus(repoPath: string, ref1?: string, ref2?: string, options: { filter?: string } = {}) {
529-
const params = ['diff', '--name-status', '-M', '--no-ext-diff'];
528+
static diff_nameStatus(
529+
repoPath: string,
530+
ref1?: string,
531+
ref2?: string,
532+
options: { filter?: string; findRenames?: number } = {}
533+
) {
534+
const renameParameter = options.findRenames == null ? '-M' : `-M${options.findRenames}%`;
535+
const params = ['diff', '--name-status', renameParameter, '--no-ext-diff'];
530536
if (options && options.filter) {
531537
params.push(`--diff-filter=${options.filter}`);
532538
}

src/git/gitService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ export class GitService implements Disposable {
13091309
repoPath: string,
13101310
ref1?: string,
13111311
ref2?: string,
1312-
options: { filter?: string } = {}
1312+
options: { filter?: string; findRenames?: number } = {}
13131313
): Promise<GitFile[] | undefined> {
13141314
try {
13151315
const data = await Git.diff_nameStatus(repoPath, ref1, ref2, options);

src/views/nodes/resultsFilesNode.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ export class ResultsFilesNode extends ViewNode<ViewWithFiles> {
8282
}
8383

8484
private async getFilesQueryResultsCore(): Promise<FilesQueryResults> {
85-
const diff = await Container.git.getDiffStatus(this.uri.repoPath!, this._ref1, this._ref2);
85+
const diff = await Container.git.getDiffStatus(this.uri.repoPath!, this._ref1, this._ref2, {
86+
findRenames: Container.config.views.compare.findRenames
87+
});
88+
8689
return {
8790
label: `${Strings.pluralize('file', diff !== undefined ? diff.length : 0, { zero: 'No' })} changed`,
8891
diff: diff

src/views/nodes/statusFilesNode.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ export class StatusFilesNode extends ViewNode<RepositoriesView> {
119119

120120
if (this.status.upstream !== undefined && this.status.state.ahead > 0) {
121121
if (files > 0) {
122-
const aheadFiles = await Container.git.getDiffStatus(this.repoPath, `${this.status.upstream}...`);
122+
const aheadFiles = await Container.git.getDiffStatus(this.repoPath, `${this.status.upstream}...`, undefined, {
123+
findRenames: Container.config.views.compare.findRenames
124+
});
125+
123126
if (aheadFiles !== undefined) {
124127
const uniques = new Set();
125128
for (const f of this.status.files) {

0 commit comments

Comments
 (0)