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
}

0 commit comments

Comments
 (0)