1
0
mirror of https://github.com/go-gitea/git.git synced 2026-02-05 06:45:03 +01:00

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)
This commit is contained in:
无闻
2016-08-31 00:30:20 -07:00
committed by GitHub

View File

@@ -158,7 +158,7 @@ func commitsCount(repoPath, revision, relpath string) (int64, error) {
}
if isFallback {
return int64(len(strings.Split(stdout, "\n"))), nil
return int64(strings.Count(stdout, "\n")) + 1, nil
}
return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
}