Skip to content

Commit 151e809

Browse files
committed
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.
1 parent 44159ff commit 151e809

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pkg/commands/git_commands/tag.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package git_commands
22

33
import (
4+
"strings"
5+
46
"github.com/jesseduffield/gocui"
57
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
68
)
@@ -74,3 +76,13 @@ func (self *TagCommands) ShowAnnotationInfo(tagName string) (string, error) {
7476

7577
return self.cmd.New(cmdArgs).RunWithOutput()
7678
}
79+
80+
func (self *TagCommands) IsTagAnnotated(tagName string) (bool, error) {
81+
cmdArgs := NewGitCmd("cat-file").
82+
Arg("-t").
83+
Arg("refs/tags/" + tagName).
84+
ToArgv()
85+
86+
output, err := self.cmd.New(cmdArgs).RunWithOutput()
87+
return strings.TrimSpace(output) == "tag", err
88+
}

pkg/gui/controllers/tags_controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ func (self *TagsController) GetOnRenderToMain() func() {
117117
}
118118

119119
func (self *TagsController) getTagInfo(tag *models.Tag) string {
120-
if tag.IsAnnotated {
120+
tagIsAnnotated, err := self.c.Git().Tag.IsTagAnnotated(tag.Name)
121+
if err != nil {
122+
self.c.Log.Warnf("Error checking if tag is annotated: %v", err)
123+
}
124+
125+
if tagIsAnnotated {
121126
info := fmt.Sprintf("%s: %s", self.c.Tr.AnnotatedTag, style.AttrBold.Sprint(style.FgYellow.Sprint(tag.Name)))
122127
output, err := self.c.Git().Tag.ShowAnnotationInfo(tag.Name)
123128
if err == nil {

0 commit comments

Comments
 (0)