From 2b1777fbafe269ccaaa32cd326da7a3fefd5238c Mon Sep 17 00:00:00 2001 From: x13machine Date: Thu, 18 Apr 2019 03:21:40 -0500 Subject: [PATCH] Fixes #670 - Configure similarity index for diffs --- package.json | 6 ++++++ src/config.ts | 1 + src/git/git.ts | 10 ++++++++-- src/git/gitService.ts | 2 +- src/views/nodes/resultsFilesNode.ts | 5 ++++- src/views/nodes/statusFilesNode.ts | 5 ++++- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6bb2f07..621cda2 100644 --- a/package.json +++ b/package.json @@ -1293,6 +1293,12 @@ "markdownDescription": "Specifies whether to show avatar images instead of commit (or status) icons in the _Compare_ view", "scope": "window" }, + "gitlens.views.compare.findRenames": { + "type": "number", + "default": 50, + "markdownDescription": "Specifies the threshold for the rename similarity index.", + "scope": "window" + }, "gitlens.views.compare.enabled": { "type": "boolean", "default": true, diff --git a/src/config.ts b/src/config.ts index eabb43b..aeeb2f4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -244,6 +244,7 @@ export interface CompareViewConfig { avatars: boolean; enabled: boolean; files: ViewsFilesConfig; + findRenames: number; location: ViewLocation; } diff --git a/src/git/git.ts b/src/git/git.ts index 3835111..885b105 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -525,8 +525,14 @@ export class Git { } } - static diff_nameStatus(repoPath: string, ref1?: string, ref2?: string, options: { filter?: string } = {}) { - const params = ['diff', '--name-status', '-M', '--no-ext-diff']; + static diff_nameStatus( + repoPath: string, + ref1?: string, + ref2?: string, + options: { filter?: string; findRenames?: number } = {} + ) { + const renameParameter = options.findRenames == null ? '-M' : `-M${options.findRenames}%`; + const params = ['diff', '--name-status', renameParameter, '--no-ext-diff']; if (options && options.filter) { params.push(`--diff-filter=${options.filter}`); } diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 0dbba3f..589712f 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -1309,7 +1309,7 @@ export class GitService implements Disposable { repoPath: string, ref1?: string, ref2?: string, - options: { filter?: string } = {} + options: { filter?: string; findRenames?: number } = {} ): Promise { try { const data = await Git.diff_nameStatus(repoPath, ref1, ref2, options); diff --git a/src/views/nodes/resultsFilesNode.ts b/src/views/nodes/resultsFilesNode.ts index 0a0c70d..52f736c 100644 --- a/src/views/nodes/resultsFilesNode.ts +++ b/src/views/nodes/resultsFilesNode.ts @@ -82,7 +82,10 @@ export class ResultsFilesNode extends ViewNode { } private async getFilesQueryResultsCore(): Promise { - const diff = await Container.git.getDiffStatus(this.uri.repoPath!, this._ref1, this._ref2); + const diff = await Container.git.getDiffStatus(this.uri.repoPath!, this._ref1, this._ref2, { + findRenames: Container.config.views.compare.findRenames + }); + return { label: `${Strings.pluralize('file', diff !== undefined ? diff.length : 0, { zero: 'No' })} changed`, diff: diff diff --git a/src/views/nodes/statusFilesNode.ts b/src/views/nodes/statusFilesNode.ts index fcf0d9b..8871192 100644 --- a/src/views/nodes/statusFilesNode.ts +++ b/src/views/nodes/statusFilesNode.ts @@ -119,7 +119,10 @@ export class StatusFilesNode extends ViewNode { if (this.status.upstream !== undefined && this.status.state.ahead > 0) { if (files > 0) { - const aheadFiles = await Container.git.getDiffStatus(this.repoPath, `${this.status.upstream}...`); + const aheadFiles = await Container.git.getDiffStatus(this.repoPath, `${this.status.upstream}...`, undefined, { + findRenames: Container.config.views.compare.findRenames + }); + if (aheadFiles !== undefined) { const uniques = new Set(); for (const f of this.status.files) {