Skip to content

Commit b4813a7

Browse files
committed
Adds commit count to GitLog
Fixes maxCount calculations
1 parent cc7fe1f commit b4813a7

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/git/models/log.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface GitLog {
99
commits: Map<string, GitLogCommit>;
1010

1111
sha: string | undefined;
12+
count: number;
1213
maxCount: number | undefined;
1314
range: Range;
1415
truncated: boolean;

src/git/parsers/logParser.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,17 @@ export class GitLogParser {
4444
let lineParts: string[];
4545
let next: IteratorResult<string> | undefined = undefined;
4646

47-
let i = -1;
47+
let i = 0;
4848
let first = true;
4949
let skip = false;
5050

5151
const lines = Strings.lines(data);
52-
// for (line of lines) {
5352
while (true) {
5453
if (!skip) {
5554
next = lines.next();
5655
if (next.done) break;
5756

5857
line = next.value;
59-
i++;
6058
}
6159
else {
6260
skip = false;
@@ -99,7 +97,6 @@ export class GitLogParser {
9997
next = lines.next();
10098
if (next.done) break;
10199

102-
i++;
103100
line = next.value;
104101
if (!line) break;
105102

@@ -117,7 +114,6 @@ export class GitLogParser {
117114
next = lines.next();
118115
if (next.done) break;
119116

120-
i++;
121117
line = next.value;
122118

123119
// If the next line isn't blank, make sure it isn't starting a new commit
@@ -131,7 +127,6 @@ export class GitLogParser {
131127
next = lines.next();
132128
if (next.done) break;
133129

134-
i++;
135130
line = next.value;
136131
lineParts = line.split(' ');
137132

@@ -178,7 +173,6 @@ export class GitLogParser {
178173
lines.next();
179174
next = lines.next();
180175

181-
i += 2;
182176
line = next.value;
183177

184178
entry.status = line[0] as GitStatusFileStatus;
@@ -196,7 +190,11 @@ export class GitLogParser {
196190
}
197191
first = false;
198192

199-
recentCommit = GitLogParser.parseEntry(entry, type, repoPath, relativeFileName, commits, authors, recentCommit);
193+
const commit = commits.get(entry.sha);
194+
if (commit === undefined) {
195+
i++;
196+
}
197+
recentCommit = GitLogParser.parseEntry(entry, commit, type, repoPath, relativeFileName, commits, authors, recentCommit);
200198

201199
entry = undefined;
202200
break;
@@ -211,14 +209,14 @@ export class GitLogParser {
211209
authors: authors,
212210
commits: commits,
213211
sha: sha,
212+
count: i,
214213
maxCount: maxCount,
215214
range: range,
216215
truncated: !!(maxCount && i >= maxCount)
217216
} as GitLog;
218217
}
219218

220-
private static parseEntry(entry: LogEntry, type: GitCommitType, repoPath: string | undefined, relativeFileName: string, commits: Map<string, GitLogCommit>, authors: Map<string, GitAuthor>, recentCommit: GitLogCommit | undefined): GitLogCommit | undefined {
221-
let commit = commits.get(entry.sha);
219+
private static parseEntry(entry: LogEntry, commit: GitLogCommit | undefined, type: GitCommitType, repoPath: string | undefined, relativeFileName: string, commits: Map<string, GitLogCommit>, authors: Map<string, GitAuthor>, recentCommit: GitLogCommit | undefined): GitLogCommit | undefined {
222220
if (commit === undefined) {
223221
if (entry.author !== undefined) {
224222
let author = authors.get(entry.author);

0 commit comments

Comments
 (0)