Skip to content

Commit b06584b

Browse files
committed
solve the issue #670 Configure similarity index for diffs
1 parent 37a7f8b commit b06584b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+156
-269
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
804804
| `gitlens.views.compare.avatars` | Specifies whether to show avatar images instead of commit (or status) icons in the _Compare_ view |
805805
| `gitlens.views.compare.files.compact` | Specifies whether to compact (flatten) unnecessary file nesting in the _Compare_ view. Only applies when `gitlens.views.compare.files.layout` is set to `tree` or `auto` |
806806
| `gitlens.views.compare.enabled` | Specifies whether to show the _Compare_ view |
807+
| `gitlens.views.compare.findRenames` | Specifies the threshold for the rename similarity index. |
807808
| `gitlens.views.compare.files.layout` | Specifies how the _Compare_ view will display files<br /><br />`auto` - automatically switches between displaying files as a `tree` or `list` based on the `gitlens.views.compare.files.threshold` value and the number of files at each nesting level<br />`list` - displays files as a list<br />`tree` - displays files as a tree |
808809
| `gitlens.views.compare.files.threshold` | Specifies when to switch between displaying files as a `tree` or `list` based on the number of files in a nesting level in the _Compare_ view. Only applies when `gitlens.views.compare.files.layout` is set to `auto` |
809810
| `gitlens.views.compare.location` | Specifies where to show the _Compare_ view<br /><br />`gitlens` - adds to the GitLens side bar<br />`explorer` - adds to the Explorer side bar<br />`scm` - adds to the Source Control side bar |

package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,12 @@
12791279
"markdownDescription": "Specifies whether to show avatar images instead of commit (or status) icons in the _Compare_ view",
12801280
"scope": "window"
12811281
},
1282+
"gitlens.views.compare.findRenames": {
1283+
"type": "number",
1284+
"default": 50,
1285+
"markdownDescription": "Specifies the threshold for the rename similarity index.",
1286+
"scope": "window"
1287+
},
12821288
"gitlens.views.compare.enabled": {
12831289
"type": "boolean",
12841290
"default": true,

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export interface CompareViewConfig {
237237
avatars: boolean;
238238
enabled: boolean;
239239
files: ViewsFilesConfig;
240+
findRenames: number;
240241
location: 'explorer' | 'gitlens' | 'scm';
241242
}
242243

src/container.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ export class Container {
5454

5555
if (config.views.compare.enabled) {
5656
context.subscriptions.push((this._compareView = new CompareView()));
57-
}
58-
else {
57+
} else {
5958
let disposable: Disposable;
6059
// eslint-disable-next-line prefer-const
6160
disposable = configuration.onDidChange(e => {
@@ -68,8 +67,7 @@ export class Container {
6867

6968
if (config.views.fileHistory.enabled) {
7069
context.subscriptions.push((this._fileHistoryView = new FileHistoryView()));
71-
}
72-
else {
70+
} else {
7371
let disposable: Disposable;
7472
// eslint-disable-next-line prefer-const
7573
disposable = configuration.onDidChange(e => {
@@ -82,8 +80,7 @@ export class Container {
8280

8381
if (config.views.lineHistory.enabled) {
8482
context.subscriptions.push((this._lineHistoryView = new LineHistoryView()));
85-
}
86-
else {
83+
} else {
8784
let disposable: Disposable;
8885
// eslint-disable-next-line prefer-const
8986
disposable = configuration.onDidChange(e => {
@@ -96,8 +93,7 @@ export class Container {
9693

9794
if (config.views.repositories.enabled) {
9895
context.subscriptions.push((this._repositoriesView = new RepositoriesView()));
99-
}
100-
else {
96+
} else {
10197
let disposable: Disposable;
10298
// eslint-disable-next-line prefer-const
10399
disposable = configuration.onDidChange(e => {
@@ -110,8 +106,7 @@ export class Container {
110106

111107
if (config.views.search.enabled) {
112108
context.subscriptions.push((this._searchView = new SearchView()));
113-
}
114-
else {
109+
} else {
115110
let disposable: Disposable;
116111
// eslint-disable-next-line prefer-const
117112
disposable = configuration.onDidChange(e => {

src/extension.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ export async function activate(context: ExtensionContext) {
5353

5454
try {
5555
await GitService.initialize();
56-
}
57-
catch (ex) {
56+
} catch (ex) {
5857
Logger.error(ex, `GitLens(v${gitlensVersion}).activate`);
5958
setCommandContext(CommandContext.Enabled, false);
6059

@@ -105,8 +104,7 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin
105104
await configuration.migrate('views.avatars', configuration.name('views')('compare')('avatars').value);
106105
await configuration.migrate('views.avatars', configuration.name('views')('repositories')('avatars').value);
107106
await configuration.migrate('views.avatars', configuration.name('views')('search')('avatars').value);
108-
}
109-
else if (Versions.compare(previous, Versions.from(9, 0, 0)) !== 1) {
107+
} else if (Versions.compare(previous, Versions.from(9, 0, 0)) !== 1) {
110108
await configuration.migrate(
111109
'gitExplorer.autoRefresh',
112110
configuration.name('views')('repositories')('autoRefresh').value
@@ -258,8 +256,7 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin
258256
}
259257
});
260258
}
261-
}
262-
catch (ex) {
259+
} catch (ex) {
263260
Logger.error(ex, 'migrateSettings');
264261
}
265262
}
@@ -298,8 +295,7 @@ async function showWelcomePage(version: string, previousVersion: string | undefi
298295

299296
if (Container.config.showWhatsNewAfterUpgrades && major !== prevMajor) {
300297
await commands.executeCommand(Commands.ShowWelcomePage);
301-
}
302-
else {
298+
} else {
303299
await Messages.showWhatsNewMessage(version);
304300
}
305301
}

src/git/formatters/commitFormatter.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,16 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
173173
let message: string;
174174
if (this._item.isStagedUncommitted) {
175175
message = 'Staged changes';
176-
}
177-
else if (this._item.isUncommitted) {
176+
} else if (this._item.isUncommitted) {
178177
message = 'Uncommitted changes';
179-
}
180-
else {
178+
} else {
181179
if (this._options.truncateMessageAtNewLine) {
182180
const index = this._item.message.indexOf('\n');
183181
message =
184182
index === -1
185183
? this._item.message
186184
: `${this._item.message.substring(0, index)}${GlyphChars.Space}${GlyphChars.Ellipsis}`;
187-
}
188-
else {
185+
} else {
189186
message = this._item.message;
190187
}
191188

src/git/formatters/formatter.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ export abstract class Formatter<TItem = any, TOptions extends FormatOptions = Fo
6262
let max = options.truncateTo;
6363
if (max === undefined) {
6464
this.collapsableWhitespace = 0;
65-
}
66-
else {
65+
} else {
6766
max += this.collapsableWhitespace;
6867
this.collapsableWhitespace = 0;
6968

@@ -76,15 +75,13 @@ export abstract class Formatter<TItem = any, TOptions extends FormatOptions = Fo
7675

7776
if (options.padDirection === 'left') {
7877
s = Strings.padLeft(s, max, undefined, width);
79-
}
80-
else {
78+
} else {
8179
if (options.collapseWhitespace) {
8280
max -= diff;
8381
}
8482
s = Strings.padRight(s, max, undefined, width);
8583
}
86-
}
87-
else if (diff < 0) {
84+
} else if (diff < 0) {
8885
s = Strings.truncate(s, max, undefined, width);
8986
}
9087
}
@@ -118,8 +115,7 @@ export abstract class Formatter<TItem = any, TOptions extends FormatOptions = Fo
118115
options = {
119116
dateFormat: dateFormatOrOptions
120117
} as TOptions;
121-
}
122-
else {
118+
} else {
123119
options = dateFormatOrOptions;
124120
}
125121

@@ -136,8 +132,7 @@ export abstract class Formatter<TItem = any, TOptions extends FormatOptions = Fo
136132

137133
if (this._formatter === undefined) {
138134
this._formatter = new formatter(item, options);
139-
}
140-
else {
135+
} else {
141136
this._formatter.reset(item, options);
142137
}
143138

src/git/formatters/statusFormatter.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,13 @@ export class StatusFileFormatter extends Formatter<GitFile, StatusFormatOptions>
5151
let icon;
5252
if (statusFile.workingTreeStatus !== undefined && statusFile.indexStatus !== undefined) {
5353
icon = `${GlyphChars.Pencil}${GlyphChars.Space}${GlyphChars.SpaceThinnest}${GlyphChars.Check}`;
54-
}
55-
else if (statusFile.workingTreeStatus !== undefined) {
54+
} else if (statusFile.workingTreeStatus !== undefined) {
5655
icon = `${GlyphChars.Pencil}${GlyphChars.SpaceThin}${GlyphChars.SpaceThinnest}${GlyphChars.EnDash}${
5756
GlyphChars.Space
5857
}`;
59-
}
60-
else if (statusFile.indexStatus !== undefined) {
58+
} else if (statusFile.indexStatus !== undefined) {
6159
icon = `${GlyphChars.Space}${GlyphChars.EnDash}${GlyphChars.Space.repeat(2)}${GlyphChars.Check}`;
62-
}
63-
else {
60+
} else {
6461
icon = '';
6562
}
6663
return this._padOrTruncate(icon, this._options.tokenOptions.working);

src/git/git.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,14 @@ export class Git {
550550
}
551551
}
552552

553-
static diff_nameStatus(repoPath: string, ref1?: string, ref2?: string, options: { filter?: string } = {}) {
554-
const params = ['diff', '--name-status', '-M', '--no-ext-diff'];
553+
static diff_nameStatus(
554+
repoPath: string,
555+
ref1?: string,
556+
ref2?: string,
557+
options: { filter?: string; findRenames?: number } = {}
558+
) {
559+
const renameParameter = options.findRenames == null ? '-M' : `-M${options.findRenames}%`;
560+
const params = ['diff', '--name-status', renameParameter, '--no-ext-diff'];
555561
if (options && options.filter) {
556562
params.push(`--diff-filter=${options.filter}`);
557563
}

src/git/gitService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ export class GitService implements Disposable {
12821282
repoPath: string,
12831283
ref1?: string,
12841284
ref2?: string,
1285-
options: { filter?: string } = {}
1285+
options: { filter?: string; findRenames?: number } = {}
12861286
): Promise<GitFile[] | undefined> {
12871287
try {
12881288
const data = await Git.diff_nameStatus(repoPath, ref1, ref2, options);

src/git/models/branch.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@ export class GitBranch {
3232
if (name.startsWith('remotes/')) {
3333
name = name.substring(8);
3434
this.remote = true;
35-
}
36-
else {
35+
} else {
3736
this.remote = false;
3837
}
3938

4039
this.detached = detached || (this.current ? GitBranch.isDetached(name) : false);
4140
if (this.detached) {
4241
this.name = GitBranch.formatDetached(this.sha!);
43-
}
44-
else {
42+
} else {
4543
this.name = name;
4644
}
4745

@@ -114,8 +112,7 @@ export class GitBranch {
114112

115113
if (star) {
116114
starred![this.id] = true;
117-
}
118-
else {
115+
} else {
119116
// eslint-disable-next-line @typescript-eslint/no-unused-vars
120117
const { [this.id]: _, ...rest } = starred!;
121118
starred = rest;

src/git/models/logCommit.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ export class GitLogCommit extends GitCommit {
137137
const fileName = Strings.normalizePath(paths.relative(this.repoPath, fileNameOrFile));
138138
file = this.files.find(f => f.fileName === fileName);
139139
if (file === undefined) return undefined;
140-
}
141-
else {
140+
} else {
142141
file = fileNameOrFile;
143142
}
144143

src/git/models/repository.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,10 @@ export class Repository implements Disposable {
103103
// If it isn't within a workspace folder we can't get change events, see: https://github.com/Microsoft/vscode/issues/3025
104104
this.supportsChangeEvents = false;
105105
this.formattedName = this.name = paths.basename(path);
106-
}
107-
else {
106+
} else {
108107
this.formattedName = this.name = folder.name;
109108
}
110-
}
111-
else {
109+
} else {
112110
this.formattedName = relativePath ? `${folder.name} (${relativePath})` : folder.name;
113111
this.name = folder.name;
114112
}
@@ -404,8 +402,7 @@ export class Repository implements Disposable {
404402

405403
if (star) {
406404
starred![this.id] = true;
407-
}
408-
else {
405+
} else {
409406
// eslint-disable-next-line @typescript-eslint/no-unused-vars
410407
const { [this.id]: _, ...rest } = starred!;
411408
starred = rest;

src/git/models/status.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ export class GitStatus {
101101
if (deleted !== 0) {
102102
status += `${status.length === 0 ? '' : separator}-${deleted}`;
103103
}
104-
}
105-
else {
104+
} else {
106105
status += `+${added}${separator}~${changed}${separator}-${deleted}`;
107106
}
108107

src/git/parsers/blameParser.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ export class GitBlameParser {
6767
case 'author':
6868
if (Git.isUncommitted(entry.sha)) {
6969
entry.author = 'You';
70-
}
71-
else {
70+
} else {
7271
entry.author = lineParts
7372
.slice(1)
7473
.join(' ')
@@ -91,8 +90,7 @@ export class GitBlameParser {
9190
const end = entry.authorEmail.indexOf('>', start);
9291
if (end > start) {
9392
entry.authorEmail = entry.authorEmail.substring(start + 1, end);
94-
}
95-
else {
93+
} else {
9694
entry.authorEmail = entry.authorEmail.substring(start + 1);
9795
}
9896
}
@@ -131,8 +129,7 @@ export class GitBlameParser {
131129
)
132130
);
133131
relativeFileName = Strings.normalizePath(paths.relative(repoPath, fileName));
134-
}
135-
else {
132+
} else {
136133
relativeFileName = entry.fileName!;
137134
}
138135
first = false;

src/git/parsers/diffParser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ export class GitDiffParser {
6767

6868
if (removed > 0) {
6969
removed--;
70-
}
71-
else {
70+
} else {
7271
previousLines.push(undefined);
7372
}
7473

0 commit comments

Comments
 (0)