aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/vcs/git.go
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2024-08-28 11:54:59 +0200
committerTaras Madan <tarasmadan@google.com>2024-08-29 13:21:19 +0000
commite46dcff2767435630f9f28e4e5ea141309798801 (patch)
tree1c62decf65a6fdf1829b2f4b33fbb9ea8e3b1cf9 /pkg/vcs/git.go
parentaf983df1f68f6c49fc740287927618a30ce3e8a8 (diff)
pkg/covermerger: optimize checkouts
Every commit checkout takes >3 seconds. Let's optimize this operation to save on large merges.
Diffstat (limited to 'pkg/vcs/git.go')
-rw-r--r--pkg/vcs/git.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go
index 840a8592e..d1a91404c 100644
--- a/pkg/vcs/git.go
+++ b/pkg/vcs/git.go
@@ -619,3 +619,19 @@ func (git *git) MergeBases(firstCommit, secondCommit string) ([]*Commit, error)
}
return ret, nil
}
+
+// CommitExists relies on 'git cat-file -e'.
+// If object exists its exit status is 0.
+// If object doesn't exist its exit status is 1 (not documented).
+// Otherwise, the exit status is 128 (not documented).
+func (git *git) CommitExists(commit string) (bool, error) {
+ _, err := git.git("cat-file", "-e", commit)
+ var vErr *osutil.VerboseError
+ if errors.As(err, &vErr) && vErr.ExitCode == 1 {
+ return false, nil
+ }
+ if err != nil {
+ return false, err
+ }
+ return true, nil
+}