aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Stribling <strib@alum.mit.edu>2017-11-27 16:21:44 -0800
committerJeremy Stribling <strib@alum.mit.edu>2017-11-27 16:22:16 -0800
commit9c80677ec0d1778e6d304b235a22f4e636322e74 (patch)
tree5f4d4f6d1da3f19ef7c0d78d67a24677c18f354c
parent129ff16f8686bb74a206cf58000de1d9640e370a (diff)
downloadgo-git-9c80677ec0d1778e6d304b235a22f4e636322e74.tar.gz
dotgit: don't list references twice
Restore the `seen` map that avoided listing packed-refs twice.
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go11
-rw-r--r--storage/filesystem/internal/dotgit/dotgit_test.go13
2 files changed, 20 insertions, 4 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go
index 43d0e2d..8e5381c 100644
--- a/storage/filesystem/internal/dotgit/dotgit.go
+++ b/storage/filesystem/internal/dotgit/dotgit.go
@@ -268,7 +268,7 @@ func (d *DotGit) Refs() ([]*plumbing.Reference, error) {
return nil, err
}
- if err := d.addRefsFromPackedRefs(&refs); err != nil {
+ if err := d.addRefsFromPackedRefs(&refs, seen); err != nil {
return nil, err
}
@@ -347,13 +347,18 @@ func (d *DotGit) RemoveRef(name plumbing.ReferenceName) error {
return d.rewritePackedRefsWithoutRef(name)
}
-func (d *DotGit) addRefsFromPackedRefs(refs *[]*plumbing.Reference) (err error) {
+func (d *DotGit) addRefsFromPackedRefs(refs *[]*plumbing.Reference, seen map[plumbing.ReferenceName]bool) (err error) {
packedRefs, err := d.findPackedRefs()
if err != nil {
return err
}
- *refs = append(*refs, packedRefs...)
+ for _, ref := range packedRefs {
+ if !seen[ref.Name()] {
+ *refs = append(*refs, ref)
+ seen[ref.Name()] = true
+ }
+ }
return nil
}
diff --git a/storage/filesystem/internal/dotgit/dotgit_test.go b/storage/filesystem/internal/dotgit/dotgit_test.go
index 913622a..a775536 100644
--- a/storage/filesystem/internal/dotgit/dotgit_test.go
+++ b/storage/filesystem/internal/dotgit/dotgit_test.go
@@ -194,6 +194,17 @@ func (s *SuiteDotGit) TestRemoveRefFromReferenceFileAndPackedRefs(c *C) {
"e8d3ffab552895c19b9fcf7aa264d277cde33881",
))
+ // Make sure it only appears once in the refs list.
+ refs, err := dir.Refs()
+ c.Assert(err, IsNil)
+ found := false
+ for _, ref := range refs {
+ if ref.Name() == "refs/remotes/origin/branch" {
+ c.Assert(found, Equals, false)
+ found = true
+ }
+ }
+
name := plumbing.ReferenceName("refs/remotes/origin/branch")
err = dir.RemoveRef(name)
c.Assert(err, IsNil)
@@ -206,7 +217,7 @@ func (s *SuiteDotGit) TestRemoveRefFromReferenceFileAndPackedRefs(c *C) {
"6ecf0ef2c2dffb796033e5a02219af86ec6584e5 refs/heads/master\n"+
"6ecf0ef2c2dffb796033e5a02219af86ec6584e5 refs/remotes/origin/master\n")
- refs, err := dir.Refs()
+ refs, err = dir.Refs()
c.Assert(err, IsNil)
ref := findReference(refs, string(name))