Skip to content

Commit

Permalink
solve the issue #670 Configure similarity index for diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
x13machine committed Apr 12, 2019
1 parent 37a7f8b commit b06584b
Show file tree
Hide file tree
Showing 52 changed files with 156 additions and 269 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -804,6 +804,7 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
| `gitlens.views.compare.avatars` | Specifies whether to show avatar images instead of commit (or status) icons in the _Compare_ view |
| `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` |
| `gitlens.views.compare.enabled` | Specifies whether to show the _Compare_ view |
| `gitlens.views.compare.findRenames` | Specifies the threshold for the rename similarity index. |
| `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 |
| `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` |
| `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 |
Expand Down
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Expand Up @@ -1279,6 +1279,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
Expand Up @@ -237,6 +237,7 @@ export interface CompareViewConfig {
avatars: boolean;
enabled: boolean;
files: ViewsFilesConfig;
findRenames: number;
location: 'explorer' | 'gitlens' | 'scm';
}

Expand Down
15 changes: 5 additions & 10 deletions src/container.ts
Expand Up @@ -54,8 +54,7 @@ export class Container {

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

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

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

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

if (config.views.search.enabled) {
context.subscriptions.push((this._searchView = new SearchView()));
}
else {
} else {
let disposable: Disposable;
// eslint-disable-next-line prefer-const
disposable = configuration.onDidChange(e => {
Expand Down
12 changes: 4 additions & 8 deletions src/extension.ts
Expand Up @@ -53,8 +53,7 @@ export async function activate(context: ExtensionContext) {

try {
await GitService.initialize();
}
catch (ex) {
} catch (ex) {
Logger.error(ex, `GitLens(v${gitlensVersion}).activate`);
setCommandContext(CommandContext.Enabled, false);

Expand Down Expand Up @@ -105,8 +104,7 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin
await configuration.migrate('views.avatars', configuration.name('views')('compare')('avatars').value);
await configuration.migrate('views.avatars', configuration.name('views')('repositories')('avatars').value);
await configuration.migrate('views.avatars', configuration.name('views')('search')('avatars').value);
}
else if (Versions.compare(previous, Versions.from(9, 0, 0)) !== 1) {
} else if (Versions.compare(previous, Versions.from(9, 0, 0)) !== 1) {
await configuration.migrate(
'gitExplorer.autoRefresh',
configuration.name('views')('repositories')('autoRefresh').value
Expand Down Expand Up @@ -258,8 +256,7 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin
}
});
}
}
catch (ex) {
} catch (ex) {
Logger.error(ex, 'migrateSettings');
}
}
Expand Down Expand Up @@ -298,8 +295,7 @@ async function showWelcomePage(version: string, previousVersion: string | undefi

if (Container.config.showWhatsNewAfterUpgrades && major !== prevMajor) {
await commands.executeCommand(Commands.ShowWelcomePage);
}
else {
} else {
await Messages.showWhatsNewMessage(version);
}
}
9 changes: 3 additions & 6 deletions src/git/formatters/commitFormatter.ts
Expand Up @@ -173,19 +173,16 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
let message: string;
if (this._item.isStagedUncommitted) {
message = 'Staged changes';
}
else if (this._item.isUncommitted) {
} else if (this._item.isUncommitted) {
message = 'Uncommitted changes';
}
else {
} else {
if (this._options.truncateMessageAtNewLine) {
const index = this._item.message.indexOf('\n');
message =
index === -1
? this._item.message
: `${this._item.message.substring(0, index)}${GlyphChars.Space}${GlyphChars.Ellipsis}`;
}
else {
} else {
message = this._item.message;
}

Expand Down
15 changes: 5 additions & 10 deletions src/git/formatters/formatter.ts
Expand Up @@ -62,8 +62,7 @@ export abstract class Formatter<TItem = any, TOptions extends FormatOptions = Fo
let max = options.truncateTo;
if (max === undefined) {
this.collapsableWhitespace = 0;
}
else {
} else {
max += this.collapsableWhitespace;
this.collapsableWhitespace = 0;

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

if (options.padDirection === 'left') {
s = Strings.padLeft(s, max, undefined, width);
}
else {
} else {
if (options.collapseWhitespace) {
max -= diff;
}
s = Strings.padRight(s, max, undefined, width);
}
}
else if (diff < 0) {
} else if (diff < 0) {
s = Strings.truncate(s, max, undefined, width);
}
}
Expand Down Expand Up @@ -118,8 +115,7 @@ export abstract class Formatter<TItem = any, TOptions extends FormatOptions = Fo
options = {
dateFormat: dateFormatOrOptions
} as TOptions;
}
else {
} else {
options = dateFormatOrOptions;
}

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

if (this._formatter === undefined) {
this._formatter = new formatter(item, options);
}
else {
} else {
this._formatter.reset(item, options);
}

Expand Down
9 changes: 3 additions & 6 deletions src/git/formatters/statusFormatter.ts
Expand Up @@ -51,16 +51,13 @@ export class StatusFileFormatter extends Formatter<GitFile, StatusFormatOptions>
let icon;
if (statusFile.workingTreeStatus !== undefined && statusFile.indexStatus !== undefined) {
icon = `${GlyphChars.Pencil}${GlyphChars.Space}${GlyphChars.SpaceThinnest}${GlyphChars.Check}`;
}
else if (statusFile.workingTreeStatus !== undefined) {
} else if (statusFile.workingTreeStatus !== undefined) {
icon = `${GlyphChars.Pencil}${GlyphChars.SpaceThin}${GlyphChars.SpaceThinnest}${GlyphChars.EnDash}${
GlyphChars.Space
}`;
}
else if (statusFile.indexStatus !== undefined) {
} else if (statusFile.indexStatus !== undefined) {
icon = `${GlyphChars.Space}${GlyphChars.EnDash}${GlyphChars.Space.repeat(2)}${GlyphChars.Check}`;
}
else {
} else {
icon = '';
}
return this._padOrTruncate(icon, this._options.tokenOptions.working);
Expand Down
10 changes: 8 additions & 2 deletions src/git/git.ts
Expand Up @@ -550,8 +550,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
Expand Up @@ -1282,7 +1282,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
9 changes: 3 additions & 6 deletions src/git/models/branch.ts
Expand Up @@ -32,16 +32,14 @@ export class GitBranch {
if (name.startsWith('remotes/')) {
name = name.substring(8);
this.remote = true;
}
else {
} else {
this.remote = false;
}

this.detached = detached || (this.current ? GitBranch.isDetached(name) : false);
if (this.detached) {
this.name = GitBranch.formatDetached(this.sha!);
}
else {
} else {
this.name = name;
}

Expand Down Expand Up @@ -114,8 +112,7 @@ export class GitBranch {

if (star) {
starred![this.id] = true;
}
else {
} else {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { [this.id]: _, ...rest } = starred!;
starred = rest;
Expand Down
3 changes: 1 addition & 2 deletions src/git/models/logCommit.ts
Expand Up @@ -137,8 +137,7 @@ export class GitLogCommit extends GitCommit {
const fileName = Strings.normalizePath(paths.relative(this.repoPath, fileNameOrFile));
file = this.files.find(f => f.fileName === fileName);
if (file === undefined) return undefined;
}
else {
} else {
file = fileNameOrFile;
}

Expand Down
9 changes: 3 additions & 6 deletions src/git/models/repository.ts
Expand Up @@ -103,12 +103,10 @@ export class Repository implements Disposable {
// If it isn't within a workspace folder we can't get change events, see: https://github.com/Microsoft/vscode/issues/3025
this.supportsChangeEvents = false;
this.formattedName = this.name = paths.basename(path);
}
else {
} else {
this.formattedName = this.name = folder.name;
}
}
else {
} else {
this.formattedName = relativePath ? `${folder.name} (${relativePath})` : folder.name;
this.name = folder.name;
}
Expand Down Expand Up @@ -404,8 +402,7 @@ export class Repository implements Disposable {

if (star) {
starred![this.id] = true;
}
else {
} else {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { [this.id]: _, ...rest } = starred!;
starred = rest;
Expand Down
3 changes: 1 addition & 2 deletions src/git/models/status.ts
Expand Up @@ -101,8 +101,7 @@ export class GitStatus {
if (deleted !== 0) {
status += `${status.length === 0 ? '' : separator}-${deleted}`;
}
}
else {
} else {
status += `+${added}${separator}~${changed}${separator}-${deleted}`;
}

Expand Down
9 changes: 3 additions & 6 deletions src/git/parsers/blameParser.ts
Expand Up @@ -67,8 +67,7 @@ export class GitBlameParser {
case 'author':
if (Git.isUncommitted(entry.sha)) {
entry.author = 'You';
}
else {
} else {
entry.author = lineParts
.slice(1)
.join(' ')
Expand All @@ -91,8 +90,7 @@ export class GitBlameParser {
const end = entry.authorEmail.indexOf('>', start);
if (end > start) {
entry.authorEmail = entry.authorEmail.substring(start + 1, end);
}
else {
} else {
entry.authorEmail = entry.authorEmail.substring(start + 1);
}
}
Expand Down Expand Up @@ -131,8 +129,7 @@ export class GitBlameParser {
)
);
relativeFileName = Strings.normalizePath(paths.relative(repoPath, fileName));
}
else {
} else {
relativeFileName = entry.fileName!;
}
first = false;
Expand Down
3 changes: 1 addition & 2 deletions src/git/parsers/diffParser.ts
Expand Up @@ -67,8 +67,7 @@ export class GitDiffParser {

if (removed > 0) {
removed--;
}
else {
} else {
previousLines.push(undefined);
}

Expand Down

0 comments on commit b06584b

Please sign in to comment.