Browse Source

Changes & renames findRenames to always apply

main
Eric Amodio 5 years ago
parent
commit
e901bff3ce
7 changed files with 149 additions and 42 deletions
  1. +1
    -0
      README.md
  2. +6
    -6
      package.json
  3. +1
    -1
      src/config.ts
  4. +70
    -15
      src/git/git.ts
  5. +69
    -14
      src/git/gitService.ts
  6. +1
    -3
      src/views/nodes/resultsFilesNode.ts
  7. +1
    -3
      src/views/nodes/statusFilesNode.ts

+ 1
- 0
README.md View File

@ -850,6 +850,7 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
| `gitlens.advanced.messages` | Specifies which messages should be suppressed |
| `gitlens.advanced.quickPick.closeOnFocusOut` | Specifies whether to close QuickPick menus when focus is lost |
| `gitlens.advanced.repositorySearchDepth` | Specifies how many folders deep to search for repositories |
| `gitlens.advanced.similarityThreshold` | Specifies the amount (percent) of similarity a deleted and added file pair must have to be considered a rename |
| `gitlens.advanced.telemetry.enabled` | Specifies whether to enable GitLens telemetry (even if enabled still abides by the overall `telemetry.enableTelemetry` setting |
#### Custom Remotes Settings

+ 6
- 6
package.json View File

@ -1293,12 +1293,6 @@
"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,
@ -1721,6 +1715,12 @@
"markdownDescription": "Specifies how many folders deep to search for repositories",
"scope": "resource"
},
"gitlens.advanced.similarityThreshold": {
"type": "number",
"default": null,
"markdownDescription": "Specifies the amount (percent) of similarity a deleted and added file pair must have to be considered a rename",
"scope": "window"
},
"gitlens.advanced.telemetry.enabled": {
"type": "boolean",
"default": true,

+ 1
- 1
src/config.ts View File

@ -213,6 +213,7 @@ export interface AdvancedConfig {
closeOnFocusOut: boolean;
};
repositorySearchDepth: number;
similarityThreshold: number;
telemetry: {
enabled: boolean;
};
@ -244,7 +245,6 @@ export interface CompareViewConfig {
avatars: boolean;
enabled: boolean;
files: ViewsFilesConfig;
findRenames: number;
location: ViewLocation;
}

+ 70
- 15
src/git/git.ts View File

@ -482,9 +482,15 @@ export class Git {
fileName: string,
ref1?: string,
ref2?: string,
options: { encoding?: string; filter?: string } = {}
options: { encoding?: string; filter?: string; similarityThreshold?: number } = {}
): Promise<string> {
const params = ['diff', '-M', '--no-ext-diff', '-U0', '--minimal'];
const params = [
'diff',
`-M${options.similarityThreshold == null ? '' : `${options.similarityThreshold}%`}`,
'--no-ext-diff',
'-U0',
'--minimal'
];
if (options.filter) {
params.push(`--diff-filter=${options.filter}`);
}
@ -529,12 +535,16 @@ export class Git {
repoPath: string,
ref1?: string,
ref2?: string,
options: { filter?: string; findRenames?: number } = {}
{ filter, similarityThreshold }: { filter?: string; similarityThreshold?: 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}`);
const params = [
'diff',
'--name-status',
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
'--no-ext-diff'
];
if (filter) {
params.push(`--diff-filter=${filter}`);
}
if (ref1) {
params.push(ref1);
@ -551,6 +561,7 @@ export class Git {
if (ref) {
params.push(ref);
}
return git<string>({ cwd: repoPath, configs: ['-c', 'color.diff=false'] }, ...params);
}
@ -598,9 +609,21 @@ export class Git {
static log(
repoPath: string,
ref: string | undefined,
{ authors, maxCount, reverse }: { authors?: string[]; maxCount?: number; reverse?: boolean }
{
authors,
maxCount,
reverse,
similarityThreshold
}: { authors?: string[]; maxCount?: number; reverse?: boolean; similarityThreshold?: number }
) {
const params = ['log', '--name-status', `--format=${GitLogParser.defaultFormat}`, '--full-history', '-M', '-m'];
const params = [
'log',
'--name-status',
`--format=${GitLogParser.defaultFormat}`,
'--full-history',
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
'-m'
];
if (maxCount && !reverse) {
params.push(`-n${maxCount}`);
}
@ -682,11 +705,15 @@ export class Git {
return git<string>({ cwd: root, configs: ['-c', 'log.showSignature=false'] }, ...params, '--', file);
}
static async log_recent(repoPath: string, fileName: string) {
static async log_recent(
repoPath: string,
fileName: string,
{ similarityThreshold }: { similarityThreshold?: number } = {}
) {
const data = await git<string>(
{ cwd: repoPath, errors: GitErrorHandling.Ignore },
'log',
'-M',
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
'-n1',
'--format=%H',
'--',
@ -866,8 +893,23 @@ export class Git {
}
}
static show_diff(repoPath: string, fileName: string, ref: string) {
return git<string>({ cwd: repoPath }, 'show', '--format=', '--minimal', '-U0', ref, '--', fileName);
static show_diff(
repoPath: string,
fileName: string,
ref: string,
{ similarityThreshold }: { similarityThreshold?: number } = {}
) {
return git<string>(
{ cwd: repoPath },
'show',
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
'--format=',
'--minimal',
'-U0',
ref,
'--',
fileName
);
}
static show_status(repoPath: string, fileName: string, ref: string) {
@ -888,8 +930,21 @@ export class Git {
return git<string>({ cwd: repoPath }, 'stash', 'drop', stashName);
}
static stash_list(repoPath: string, { format = GitStashParser.defaultFormat }: { format?: string } = {}) {
return git<string>({ cwd: repoPath }, 'stash', 'list', '--name-status', '-M', `--format=${format}`);
static stash_list(
repoPath: string,
{
format = GitStashParser.defaultFormat,
similarityThreshold
}: { format?: string; similarityThreshold?: number } = {}
) {
return git<string>(
{ cwd: repoPath },
'stash',
'list',
'--name-status',
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
`--format=${format}`
);
}
static stash_push(repoPath: string, pathspecs: string[], message?: string) {

+ 69
- 14
src/git/gitService.ts View File

@ -454,7 +454,9 @@ export class GitService implements Disposable {
let patch;
try {
patch = await Git.diff(uri.repoPath, uri.fsPath, ref1, ref2);
patch = await Git.diff(uri.repoPath, uri.fsPath, ref1, ref2, {
similarityThreshold: Container.config.advanced.similarityThreshold
});
void (await Git.apply(uri.repoPath!, patch));
}
catch (ex) {
@ -1249,10 +1251,16 @@ export class GitService implements Disposable {
try {
let data;
if (ref1 !== undefined && ref2 === undefined && !GitService.isStagedUncommitted(ref1)) {
data = await Git.show_diff(root, file, ref1);
data = await Git.show_diff(root, file, ref1, {
similarityThreshold: Container.config.advanced.similarityThreshold
});
}
else {
data = await Git.diff(root, file, ref1, ref2, { ...options, filter: 'M' });
data = await Git.diff(root, file, ref1, ref2, {
...options,
filter: 'M',
similarityThreshold: Container.config.advanced.similarityThreshold
});
}
const diff = GitDiffParser.parse(data);
@ -1309,10 +1317,13 @@ export class GitService implements Disposable {
repoPath: string,
ref1?: string,
ref2?: string,
options: { filter?: string; findRenames?: number } = {}
options: { filter?: string; similarityThreshold?: number } = {}
): Promise<GitFile[] | undefined> {
try {
const data = await Git.diff_nameStatus(repoPath, ref1, ref2, options);
const data = await Git.diff_nameStatus(repoPath, ref1, ref2, {
similarityThreshold: Container.config.advanced.similarityThreshold,
...options
});
const diff = GitDiffParser.parseNameStatus(data, repoPath);
return diff;
}
@ -1341,7 +1352,9 @@ export class GitService implements Disposable {
@log()
getRecentShaForFile(repoPath: string, fileName: string) {
return Git.log_recent(repoPath, fileName);
return Git.log_recent(repoPath, fileName, {
similarityThreshold: Container.config.advanced.similarityThreshold
});
}
@log()
@ -1385,7 +1398,8 @@ export class GitService implements Disposable {
const data = await Git.log(repoPath, ref, {
authors: options.authors,
maxCount: maxCount,
reverse: options.reverse
reverse: options.reverse,
similarityThreshold: Container.config.advanced.similarityThreshold
});
const log = GitLogParser.parse(
data,
@ -1419,29 +1433,68 @@ export class GitService implements Disposable {
options: { maxCount?: number } = {}
): Promise<GitLog | undefined> {
let maxCount = options.maxCount == null ? Container.config.advanced.maxListItems || 0 : options.maxCount;
const similarityThreshold = Container.config.advanced.similarityThreshold;
let searchArgs: string[] | undefined = undefined;
switch (searchBy) {
case GitRepoSearchBy.Author:
searchArgs = ['-m', '-M', '--all', '--full-history', '-E', '-i', `--author=${search}`];
searchArgs = [
'-m',
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
'--all',
'--full-history',
'-E',
'-i',
`--author=${search}`
];
break;
case GitRepoSearchBy.ChangedLines:
searchArgs = ['-M', '--all', '--full-history', '-E', '-i', `-G${search}`];
searchArgs = [
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
'--all',
'--full-history',
'-E',
'-i',
`-G${search}`
];
break;
case GitRepoSearchBy.Changes:
searchArgs = ['-M', '--all', '--full-history', '-E', '-i', '--pickaxe-regex', `-S${search}`];
searchArgs = [
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
'--all',
'--full-history',
'-E',
'-i',
'--pickaxe-regex',
`-S${search}`
];
break;
case GitRepoSearchBy.Files:
searchArgs = ['-M', '--all', '--full-history', '-E', '-i', '--', `${search}`];
searchArgs = [
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
'--all',
'--full-history',
'-E',
'-i',
'--',
`${search}`
];
break;
case GitRepoSearchBy.Message:
searchArgs = ['-m', '-M', '--all', '--full-history', '-E', '-i'];
searchArgs = [
'-m',
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
'--all',
'--full-history',
'-E',
'-i'
];
if (search) {
searchArgs.push(`--grep=${search}`);
}
break;
case GitRepoSearchBy.Sha:
searchArgs = ['-m', '-M', search];
searchArgs = ['-m', `-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`, search];
maxCount = 1;
break;
}
@ -2099,7 +2152,9 @@ export class GitService implements Disposable {
async getStashList(repoPath: string | undefined): Promise<GitStash | undefined> {
if (repoPath === undefined) return undefined;
const data = await Git.stash_list(repoPath);
const data = await Git.stash_list(repoPath, {
similarityThreshold: Container.config.advanced.similarityThreshold
});
const stash = GitStashParser.parse(data, repoPath);
return stash;
}

+ 1
- 3
src/views/nodes/resultsFilesNode.ts View File

@ -82,9 +82,7 @@ export class ResultsFilesNode extends ViewNode {
}
private async getFilesQueryResultsCore(): Promise<FilesQueryResults> {
const diff = await Container.git.getDiffStatus(this.uri.repoPath!, this._ref1, this._ref2, {
findRenames: Container.config.views.compare.findRenames
});
const diff = await Container.git.getDiffStatus(this.uri.repoPath!, this._ref1, this._ref2);
return {
label: `${Strings.pluralize('file', diff !== undefined ? diff.length : 0, { zero: 'No' })} changed`,

+ 1
- 3
src/views/nodes/statusFilesNode.ts View File

@ -119,9 +119,7 @@ export class StatusFilesNode extends ViewNode {
if (this.status.upstream !== undefined && this.status.state.ahead > 0) {
if (files > 0) {
const aheadFiles = await Container.git.getDiffStatus(this.repoPath, `${this.status.upstream}...`, undefined, {
findRenames: Container.config.views.compare.findRenames
});
const aheadFiles = await Container.git.getDiffStatus(this.repoPath, `${this.status.upstream}...`);
if (aheadFiles !== undefined) {
const uniques = new Set();

Loading…
Cancel
Save