Skip to content

Commit

Permalink
Fixes #670 - Configure similarity index for diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
x13machine authored and eamodio committed Apr 28, 2019
1 parent e77be8b commit 2b1777f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export interface CompareViewConfig {
avatars: boolean;
enabled: boolean;
files: ViewsFilesConfig;
findRenames: number;
location: ViewLocation;
}

Expand Down
10 changes: 8 additions & 2 deletions src/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/git/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ export class GitService implements Disposable {
repoPath: string,
ref1?: string,
ref2?: string,
options: { filter?: string } = {}
options: { filter?: string; findRenames?: number } = {}
): Promise<GitFile[] | undefined> {
try {
const data = await Git.diff_nameStatus(repoPath, ref1, ref2, options);
Expand Down
5 changes: 4 additions & 1 deletion src/views/nodes/resultsFilesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export class ResultsFilesNode extends ViewNode<ViewWithFiles> {
}

private async getFilesQueryResultsCore(): Promise<FilesQueryResults> {
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
Expand Down
5 changes: 4 additions & 1 deletion src/views/nodes/statusFilesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ export class StatusFilesNode extends ViewNode<RepositoriesView> {

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) {
Expand Down

0 comments on commit 2b1777f

Please sign in to comment.