Skip to content

Commit 2ef563c

Browse files
authored
Avoid creating an array for the sole purpose of counting elements (#17)
* Avoid creating an array for the sole purpose of counting elements Probably speeds up counting commits for git versions < 1.8.0, although I dubt it would make a visible difference * Fix commit count with git version < 1.8.0 With format='' the output does not end with a newline (checked)
2 parents 5e0c133 + 5ebab5d commit 2ef563c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func commitsCount(repoPath, revision, relpath string) (int64, error) {
158158
}
159159

160160
if isFallback {
161-
return int64(len(strings.Split(stdout, "\n"))), nil
161+
return int64(strings.Count(stdout, "\n")) + 1, nil
162162
}
163163
return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
164164
}

0 commit comments

Comments
 (0)