From b4813a7b2524b376c96cc0e9c48540fde4cee936 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 29 Nov 2017 04:13:46 -0500 Subject: [PATCH] Adds commit count to GitLog Fixes maxCount calculations --- src/git/models/log.ts | 1 + src/git/parsers/logParser.ts | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/git/models/log.ts b/src/git/models/log.ts index 3d5b873..de443ef 100644 --- a/src/git/models/log.ts +++ b/src/git/models/log.ts @@ -9,6 +9,7 @@ export interface GitLog { commits: Map; sha: string | undefined; + count: number; maxCount: number | undefined; range: Range; truncated: boolean; diff --git a/src/git/parsers/logParser.ts b/src/git/parsers/logParser.ts index 004b047..5ba7da9 100644 --- a/src/git/parsers/logParser.ts +++ b/src/git/parsers/logParser.ts @@ -44,19 +44,17 @@ export class GitLogParser { let lineParts: string[]; let next: IteratorResult | undefined = undefined; - let i = -1; + let i = 0; let first = true; let skip = false; const lines = Strings.lines(data); - // for (line of lines) { while (true) { if (!skip) { next = lines.next(); if (next.done) break; line = next.value; - i++; } else { skip = false; @@ -99,7 +97,6 @@ export class GitLogParser { next = lines.next(); if (next.done) break; - i++; line = next.value; if (!line) break; @@ -117,7 +114,6 @@ export class GitLogParser { next = lines.next(); if (next.done) break; - i++; line = next.value; // If the next line isn't blank, make sure it isn't starting a new commit @@ -131,7 +127,6 @@ export class GitLogParser { next = lines.next(); if (next.done) break; - i++; line = next.value; lineParts = line.split(' '); @@ -178,7 +173,6 @@ export class GitLogParser { lines.next(); next = lines.next(); - i += 2; line = next.value; entry.status = line[0] as GitStatusFileStatus; @@ -196,7 +190,11 @@ export class GitLogParser { } first = false; - recentCommit = GitLogParser.parseEntry(entry, type, repoPath, relativeFileName, commits, authors, recentCommit); + const commit = commits.get(entry.sha); + if (commit === undefined) { + i++; + } + recentCommit = GitLogParser.parseEntry(entry, commit, type, repoPath, relativeFileName, commits, authors, recentCommit); entry = undefined; break; @@ -211,14 +209,14 @@ export class GitLogParser { authors: authors, commits: commits, sha: sha, + count: i, maxCount: maxCount, range: range, truncated: !!(maxCount && i >= maxCount) } as GitLog; } - private static parseEntry(entry: LogEntry, type: GitCommitType, repoPath: string | undefined, relativeFileName: string, commits: Map, authors: Map, recentCommit: GitLogCommit | undefined): GitLogCommit | undefined { - let commit = commits.get(entry.sha); + private static parseEntry(entry: LogEntry, commit: GitLogCommit | undefined, type: GitCommitType, repoPath: string | undefined, relativeFileName: string, commits: Map, authors: Map, recentCommit: GitLogCommit | undefined): GitLogCommit | undefined { if (commit === undefined) { if (entry.author !== undefined) { let author = authors.get(entry.author);