mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Revert "Add IsAnnotated field to models.Tag struct"
It seems that `git for-each-ref` is a lot slower than `git tag --list` when
there are thousands of tags, so revert back to the previous method, now that we
no longer use the IsAnnotated field.
This reverts commit b12b1040c3.
This commit is contained in:
parent
151e80902e
commit
1c533dcd55
|
|
@ -1,7 +1,7 @@
|
|||
package git_commands
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"regexp"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
|
|
@ -26,13 +26,9 @@ func NewTagLoader(
|
|||
}
|
||||
|
||||
func (self *TagLoader) GetTags() ([]*models.Tag, error) {
|
||||
// get tags, sorted by creation date (descending)
|
||||
// get remote branches, sorted by creation date (descending)
|
||||
// see: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---sortltkeygt
|
||||
cmdArgs := NewGitCmd("for-each-ref").
|
||||
Arg("--sort=-creatordate").
|
||||
Arg("--format=%(refname)%00%(objecttype)%00%(contents:subject)").
|
||||
Arg("refs/tags").
|
||||
ToArgv()
|
||||
cmdArgs := NewGitCmd("tag").Arg("--list", "-n", "--sort=-creatordate").ToArgv()
|
||||
tagsOutput, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -40,20 +36,20 @@ func (self *TagLoader) GetTags() ([]*models.Tag, error) {
|
|||
|
||||
split := utils.SplitLines(tagsOutput)
|
||||
|
||||
tags := lo.FilterMap(split, func(line string, _ int) (*models.Tag, bool) {
|
||||
fields := strings.SplitN(line, "\x00", 3)
|
||||
if len(fields) != 3 {
|
||||
return nil, false
|
||||
lineRegex := regexp.MustCompile(`^([^\s]+)(\s+)?(.*)$`)
|
||||
|
||||
tags := lo.Map(split, func(line string, _ int) *models.Tag {
|
||||
matches := lineRegex.FindStringSubmatch(line)
|
||||
tagName := matches[1]
|
||||
message := ""
|
||||
if len(matches) > 3 {
|
||||
message = matches[3]
|
||||
}
|
||||
tagName := fields[0]
|
||||
objectType := fields[1]
|
||||
message := fields[2]
|
||||
|
||||
return &models.Tag{
|
||||
Name: strings.TrimPrefix(tagName, "refs/tags/"),
|
||||
Message: message,
|
||||
IsAnnotated: objectType == "tag",
|
||||
}, true
|
||||
Name: tagName,
|
||||
Message: message,
|
||||
}
|
||||
})
|
||||
|
||||
return tags, nil
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const tagsOutput = "refs/tags/tag1\x00tag\x00this is my message\n" +
|
||||
"refs/tags/tag2\x00commit\x00\n" +
|
||||
"refs/tags/tag3\x00tag\x00this is my other message\n"
|
||||
const tagsOutput = `tag1 this is my message
|
||||
tag2
|
||||
tag3 this is my other message
|
||||
`
|
||||
|
||||
func TestGetTags(t *testing.T) {
|
||||
type scenario struct {
|
||||
|
|
@ -25,18 +26,18 @@ func TestGetTags(t *testing.T) {
|
|||
{
|
||||
testName: "should return no tags if there are none",
|
||||
runner: oscommands.NewFakeRunner(t).
|
||||
ExpectGitArgs([]string{"for-each-ref", "--sort=-creatordate", "--format=%(refname)%00%(objecttype)%00%(contents:subject)", "refs/tags"}, "", nil),
|
||||
ExpectGitArgs([]string{"tag", "--list", "-n", "--sort=-creatordate"}, "", nil),
|
||||
expectedTags: []*models.Tag{},
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
testName: "should return tags if present",
|
||||
runner: oscommands.NewFakeRunner(t).
|
||||
ExpectGitArgs([]string{"for-each-ref", "--sort=-creatordate", "--format=%(refname)%00%(objecttype)%00%(contents:subject)", "refs/tags"}, tagsOutput, nil),
|
||||
ExpectGitArgs([]string{"tag", "--list", "-n", "--sort=-creatordate"}, tagsOutput, nil),
|
||||
expectedTags: []*models.Tag{
|
||||
{Name: "tag1", Message: "this is my message", IsAnnotated: true},
|
||||
{Name: "tag2", Message: "", IsAnnotated: false},
|
||||
{Name: "tag3", Message: "this is my other message", IsAnnotated: true},
|
||||
{Name: "tag1", Message: "this is my message"},
|
||||
{Name: "tag2", Message: ""},
|
||||
{Name: "tag3", Message: "this is my other message"},
|
||||
},
|
||||
expectedError: nil,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,13 +3,9 @@ package models
|
|||
// Tag : A git tag
|
||||
type Tag struct {
|
||||
Name string
|
||||
|
||||
// this is either the first line of the message of an annotated tag, or the
|
||||
// first line of a commit message for a lightweight tag
|
||||
Message string
|
||||
|
||||
// true if this is an annotated tag, false if it's a lightweight tag
|
||||
IsAnnotated bool
|
||||
}
|
||||
|
||||
func (t *Tag) FullRefName() string {
|
||||
|
|
|
|||
Loading…
Reference in a new issue