Browse Source

Fixes #259 - limits merges to first parent

Since git log --follow drops merges, -m --first-parent adds them back
main
Eric Amodio 7 years ago
parent
commit
3be10947f5
5 changed files with 24 additions and 14 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -1
      src/commands/diffWithNext.ts
  3. +1
    -1
      src/commands/diffWithPrevious.ts
  4. +5
    -3
      src/git/git.ts
  5. +16
    -9
      src/gitService.ts

+ 1
- 0
CHANGELOG.md View File

@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed
- Fixes [#266](https://github.com/eamodio/vscode-gitlens/issues/266) - Wrong time in Popup
- Fixes [#259](https://github.com/eamodio/vscode-gitlens/issues/259) (again) - File history lists unrelated merge commits
## [7.5.9] - 2018-01-30
### Fixed

+ 1
- 1
src/commands/diffWithNext.ts View File

@ -41,7 +41,7 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
// If we are a fake "staged" sha, treat it as a DiffWithWorking
if (GitService.isStagedUncommitted(sha!)) return commands.executeCommand(Commands.DiffWithWorking, uri);
const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: sha !== undefined ? undefined : 2, range: args.range!, skipMerges: true });
const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: sha !== undefined ? undefined : 2, range: args.range!, renames: true });
if (log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare');
args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values());

+ 1
- 1
src/commands/diffWithPrevious.ts View File

@ -45,7 +45,7 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
isStagedUncommitted = true;
}
const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: 2, ref: sha, skipMerges: true });
const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: 2, ref: sha, renames: true });
if (log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare');
args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values());

+ 5
- 3
src/git/git.ts View File

@ -404,15 +404,17 @@ export class Git {
return gitCommand({ cwd: repoPath }, ...params);
}
static log_file(repoPath: string, fileName: string, options: { maxCount?: number, ref?: string, reverse?: boolean, startLine?: number, endLine?: number, skipMerges?: boolean } = { reverse: false, skipMerges: false }) {
static log_file(repoPath: string, fileName: string, options: { maxCount?: number, ref?: string, renames?: boolean, reverse?: boolean, startLine?: number, endLine?: number } = { renames: true, reverse: false }) {
const [file, root] = Git.splitPath(fileName, repoPath);
const params = [...defaultLogParams, '--follow'];
const params = [...defaultLogParams];
if (options.maxCount && !options.reverse) {
params.push(`-n${options.maxCount}`);
}
params.push(options.skipMerges ? '--no-merges' : '-m');
if (options.renames) {
params.push('--follow', '-m', '--first-parent');
}
if (options.ref && !Git.isStagedUncommitted(options.ref)) {
if (options.reverse) {

+ 16
- 9
src/gitService.ts View File

@ -935,10 +935,14 @@ export class GitService extends Disposable {
}
}
async getLogForFile(repoPath: string | undefined, fileName: string, options: { maxCount?: number, range?: Range, ref?: string, reverse?: boolean, skipMerges?: boolean } = {}): Promise<GitLog | undefined> {
async getLogForFile(repoPath: string | undefined, fileName: string, options: { maxCount?: number, range?: Range, ref?: string, renames?: boolean, reverse?: boolean } = {}): Promise<GitLog | undefined> {
if (repoPath !== undefined && repoPath === Strings.normalizePath(fileName)) throw new Error(`File name cannot match the repository path; fileName=${fileName}`);
options = { reverse: false, skipMerges: false, ...options };
options = { reverse: false, ...options };
if (options.renames === undefined) {
options.renames = true;
}
let key = 'log';
if (options.ref !== undefined) {
@ -947,13 +951,16 @@ export class GitService extends Disposable {
if (options.maxCount !== undefined) {
key += `:n${options.maxCount}`;
}
if (options.renames) {
key += `:follow`;
}
const doc = await Container.tracker.getOrAdd(new GitUri(Uri.file(fileName), { repoPath: repoPath!, sha: options.ref }));
if (this.UseCaching && options.range === undefined && !options.reverse) {
if (doc.state !== undefined) {
const cachedLog = doc.state.get<CachedLog>(key);
if (cachedLog !== undefined) {
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.renames}, ${options.reverse})`);
return cachedLog.item;
}
@ -962,28 +969,28 @@ export class GitService extends Disposable {
const cachedLog = doc.state.get<CachedLog>('log');
if (cachedLog !== undefined) {
if (options.ref === undefined) {
Logger.log(`getLogForFile[Cached(~${key})]('${repoPath}', '${fileName}', '', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
Logger.log(`getLogForFile[Cached(~${key})]('${repoPath}', '${fileName}', '', ${options.maxCount}, undefined, ${options.renames}, ${options.reverse})`);
return cachedLog.item;
}
Logger.log(`getLogForFile[? Cache(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
Logger.log(`getLogForFile[? Cache(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.renames}, ${options.reverse})`);
const log = await cachedLog.item;
if (log !== undefined && log.commits.has(options.ref)) {
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.renames}, ${options.reverse})`);
return cachedLog.item;
}
}
}
}
Logger.log(`getLogForFile[Not Cached(${key})]('${repoPath}', '${fileName}', ${options.ref}, ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
Logger.log(`getLogForFile[Not Cached(${key})]('${repoPath}', '${fileName}', ${options.ref}, ${options.maxCount}, undefined, ${options.reverse})`);
if (doc.state === undefined) {
doc.state = new GitDocumentState(doc.key);
}
}
else {
Logger.log(`getLogForFile('${repoPath}', '${fileName}', ${options.ref}, ${options.maxCount}, ${options.range && `[${options.range.start.line}, ${options.range.end.line}]`}, ${options.reverse}, ${options.skipMerges})`);
Logger.log(`getLogForFile('${repoPath}', '${fileName}', ${options.ref}, ${options.maxCount}, ${options.range && `[${options.range.start.line}, ${options.range.end.line}]`}, ${options.reverse})`);
}
const promise = this.getLogForFileCore(repoPath, fileName, options, doc, key);
@ -999,7 +1006,7 @@ export class GitService extends Disposable {
return promise;
}
private async getLogForFileCore(repoPath: string | undefined, fileName: string, options: { maxCount?: number, range?: Range, ref?: string, reverse?: boolean, skipMerges?: boolean }, document: TrackedDocument<GitDocumentState>, key: string): Promise<GitLog | undefined> {
private async getLogForFileCore(repoPath: string | undefined, fileName: string, options: { maxCount?: number, range?: Range, ref?: string, renames?: boolean, reverse?: boolean }, document: TrackedDocument<GitDocumentState>, key: string): Promise<GitLog | undefined> {
if (!(await this.isTracked(fileName, repoPath, { ref: options.ref }))) {
Logger.log(`Skipping log; '${fileName}' is not tracked`);
return GitService.emptyPromise as Promise<GitLog>;

Loading…
Cancel
Save