From ecc0ecd03f542273b38385e12c210d5b399792c6 Mon Sep 17 00:00:00 2001 From: Harry Date: Fri, 27 Jun 2025 12:44:52 +0100 Subject: [PATCH] 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. --- mob.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mob.go b/mob.go index 267c9ef..4a00092 100644 --- a/mob.go +++ b/mob.go @@ -297,8 +297,8 @@ func run(osArgs []string) { } func hasCommits() bool { - commitCount := silentgit("rev-list", "--all", "--count") - return commitCount != "0" + _, err := silentgitignorefailure("rev-parse", "--verify", "HEAD") + return (err == nil) } func currentCliName(argZero string) string {