Skip to content

solve the issue #670 Configure similarity index for diffs #714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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