From 151e80902ec1be653e3faf9f01338e88d276c756 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 27 Jul 2025 17:57:28 +0200 Subject: [PATCH] Use a different way to check if a tag is annotated Storing it in the Tag struct makes loading tags a lot slower when there is a very large number of tags; so determine it on the fly instead. On my machine, the additional call takes under 5ms, so it seems we can afford it. --- pkg/commands/git_commands/tag.go | 12 ++++++++++++ pkg/gui/controllers/tags_controller.go | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/commands/git_commands/tag.go b/pkg/commands/git_commands/tag.go index d32f669b3..1e9b449b1 100644 --- a/pkg/commands/git_commands/tag.go +++ b/pkg/commands/git_commands/tag.go @@ -1,6 +1,8 @@ package git_commands import ( + "strings" + "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" ) @@ -74,3 +76,13 @@ func (self *TagCommands) ShowAnnotationInfo(tagName string) (string, error) { return self.cmd.New(cmdArgs).RunWithOutput() } + +func (self *TagCommands) IsTagAnnotated(tagName string) (bool, error) { + cmdArgs := NewGitCmd("cat-file"). + Arg("-t"). + Arg("refs/tags/" + tagName). + ToArgv() + + output, err := self.cmd.New(cmdArgs).RunWithOutput() + return strings.TrimSpace(output) == "tag", err +} diff --git a/pkg/gui/controllers/tags_controller.go b/pkg/gui/controllers/tags_controller.go index 71561ed6e..c6fa60bd2 100644 --- a/pkg/gui/controllers/tags_controller.go +++ b/pkg/gui/controllers/tags_controller.go @@ -117,7 +117,12 @@ func (self *TagsController) GetOnRenderToMain() func() { } func (self *TagsController) getTagInfo(tag *models.Tag) string { - if tag.IsAnnotated { + tagIsAnnotated, err := self.c.Git().Tag.IsTagAnnotated(tag.Name) + if err != nil { + self.c.Log.Warnf("Error checking if tag is annotated: %v", err) + } + + if tagIsAnnotated { info := fmt.Sprintf("%s: %s", self.c.Tr.AnnotatedTag, style.AttrBold.Sprint(style.FgYellow.Sprint(tag.Name))) output, err := self.c.Git().Tag.ShowAnnotationInfo(tag.Name) if err == nil {