Skip to content

Commit 3be1094

Browse files
committed
Fixes #259 - limits merges to first parent
Since git log --follow drops merges, -m --first-parent adds them back
1 parent a32bb98 commit 3be1094

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1010

1111
### Fixed
1212
- Fixes [#266](https://github.com/eamodio/vscode-gitlens/issues/266) - Wrong time in Popup
13+
- Fixes [#259](https://github.com/eamodio/vscode-gitlens/issues/259) (again) - File history lists unrelated merge commits
1314

1415
## [7.5.9] - 2018-01-30
1516
### Fixed

src/commands/diffWithNext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
4141
// If we are a fake "staged" sha, treat it as a DiffWithWorking
4242
if (GitService.isStagedUncommitted(sha!)) return commands.executeCommand(Commands.DiffWithWorking, uri);
4343

44-
const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: sha !== undefined ? undefined : 2, range: args.range!, skipMerges: true });
44+
const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: sha !== undefined ? undefined : 2, range: args.range!, renames: true });
4545
if (log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare');
4646

4747
args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values());

src/commands/diffWithPrevious.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
4545
isStagedUncommitted = true;
4646
}
4747

48-
const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: 2, ref: sha, skipMerges: true });
48+
const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: 2, ref: sha, renames: true });
4949
if (log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare');
5050

5151
args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values());

src/git/git.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,17 @@ export class Git {
404404
return gitCommand({ cwd: repoPath }, ...params);
405405
}
406406

407-
static log_file(repoPath: string, fileName: string, options: { maxCount?: number, ref?: string, reverse?: boolean, startLine?: number, endLine?: number, skipMerges?: boolean } = { reverse: false, skipMerges: false }) {
407+
static log_file(repoPath: string, fileName: string, options: { maxCount?: number, ref?: string, renames?: boolean, reverse?: boolean, startLine?: number, endLine?: number } = { renames: true, reverse: false }) {
408408
const [file, root] = Git.splitPath(fileName, repoPath);
409409

410-
const params = [...defaultLogParams, '--follow'];
410+
const params = [...defaultLogParams];
411411
if (options.maxCount && !options.reverse) {
412412
params.push(`-n${options.maxCount}`);
413413
}
414414

415-
params.push(options.skipMerges ? '--no-merges' : '-m');
415+
if (options.renames) {
416+
params.push('--follow', '-m', '--first-parent');
417+
}
416418

417419
if (options.ref && !Git.isStagedUncommitted(options.ref)) {
418420
if (options.reverse) {

src/gitService.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -935,10 +935,14 @@ export class GitService extends Disposable {
935935
}
936936
}
937937

938-
async getLogForFile(repoPath: string | undefined, fileName: string, options: { maxCount?: number, range?: Range, ref?: string, reverse?: boolean, skipMerges?: boolean } = {}): Promise<GitLog | undefined> {
938+
async getLogForFile(repoPath: string | undefined, fileName: string, options: { maxCount?: number, range?: Range, ref?: string, renames?: boolean, reverse?: boolean } = {}): Promise<GitLog | undefined> {
939939
if (repoPath !== undefined && repoPath === Strings.normalizePath(fileName)) throw new Error(`File name cannot match the repository path; fileName=${fileName}`);
940940

941-
options = { reverse: false, skipMerges: false, ...options };
941+
options = { reverse: false, ...options };
942+
943+
if (options.renames === undefined) {
944+
options.renames = true;
945+
}
942946

943947
let key = 'log';
944948
if (options.ref !== undefined) {
@@ -947,13 +951,16 @@ export class GitService extends Disposable {
947951
if (options.maxCount !== undefined) {
948952
key += `:n${options.maxCount}`;
949953
}
954+
if (options.renames) {
955+
key += `:follow`;
956+
}
950957

951958
const doc = await Container.tracker.getOrAdd(new GitUri(Uri.file(fileName), { repoPath: repoPath!, sha: options.ref }));
952959
if (this.UseCaching && options.range === undefined && !options.reverse) {
953960
if (doc.state !== undefined) {
954961
const cachedLog = doc.state.get<CachedLog>(key);
955962
if (cachedLog !== undefined) {
956-
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
963+
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.renames}, ${options.reverse})`);
957964
return cachedLog.item;
958965
}
959966

@@ -962,28 +969,28 @@ export class GitService extends Disposable {
962969
const cachedLog = doc.state.get<CachedLog>('log');
963970
if (cachedLog !== undefined) {
964971
if (options.ref === undefined) {
965-
Logger.log(`getLogForFile[Cached(~${key})]('${repoPath}', '${fileName}', '', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
972+
Logger.log(`getLogForFile[Cached(~${key})]('${repoPath}', '${fileName}', '', ${options.maxCount}, undefined, ${options.renames}, ${options.reverse})`);
966973
return cachedLog.item;
967974
}
968975

969-
Logger.log(`getLogForFile[? Cache(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
976+
Logger.log(`getLogForFile[? Cache(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.renames}, ${options.reverse})`);
970977
const log = await cachedLog.item;
971978
if (log !== undefined && log.commits.has(options.ref)) {
972-
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
979+
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.renames}, ${options.reverse})`);
973980
return cachedLog.item;
974981
}
975982
}
976983
}
977984
}
978985

979-
Logger.log(`getLogForFile[Not Cached(${key})]('${repoPath}', '${fileName}', ${options.ref}, ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
986+
Logger.log(`getLogForFile[Not Cached(${key})]('${repoPath}', '${fileName}', ${options.ref}, ${options.maxCount}, undefined, ${options.reverse})`);
980987

981988
if (doc.state === undefined) {
982989
doc.state = new GitDocumentState(doc.key);
983990
}
984991
}
985992
else {
986-
Logger.log(`getLogForFile('${repoPath}', '${fileName}', ${options.ref}, ${options.maxCount}, ${options.range && `[${options.range.start.line}, ${options.range.end.line}]`}, ${options.reverse}, ${options.skipMerges})`);
993+
Logger.log(`getLogForFile('${repoPath}', '${fileName}', ${options.ref}, ${options.maxCount}, ${options.range && `[${options.range.start.line}, ${options.range.end.line}]`}, ${options.reverse})`);
987994
}
988995

989996
const promise = this.getLogForFileCore(repoPath, fileName, options, doc, key);
@@ -999,7 +1006,7 @@ export class GitService extends Disposable {
9991006
return promise;
10001007
}
10011008

1002-
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> {
1009+
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> {
10031010
if (!(await this.isTracked(fileName, repoPath, { ref: options.ref }))) {
10041011
Logger.log(`Skipping log; '${fileName}' is not tracked`);
10051012
return GitService.emptyPromise as Promise<GitLog>;

0 commit comments

Comments
 (0)