Skip to content

Commit ecc0ecd

Browse files
committed
Speed up hasCommits check
`git rev-list --all` is very slow for large repositories (order of 5s on a repo with 500k commits). This alternative version works by checking whether HEAD points at a valid commit, by using a git command that returns an error code if not. This means it has to use the 'silentgitignorefailure' version of the git invocation functions, and check for an error.
1 parent 78292ef commit ecc0ecd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mob.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ func run(osArgs []string) {
297297
}
298298

299299
func hasCommits() bool {
300-
commitCount := silentgit("rev-list", "--all", "--count")
301-
return commitCount != "0"
300+
_, err := silentgitignorefailure("rev-parse", "--verify", "HEAD")
301+
return (err == nil)
302302
}
303303

304304
func currentCliName(argZero string) string {

0 commit comments

Comments
 (0)