aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/reference.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2022-11-07 16:53:56 +0100
committerGitHub <noreply@github.com>2022-11-07 16:53:56 +0100
commit652bc83fe45c114440de41d7e0fecf3e4b9e517d (patch)
treea784f0a4b677abc00247638e600f5efef1c44dfc /plumbing/reference.go
parent08cffa1efade914020497a73907763e8d3707a77 (diff)
parentffa7e69efb8c4ba8d4e08ec4c65e49e2228fd88b (diff)
downloadgo-git-652bc83fe45c114440de41d7e0fecf3e4b9e517d.tar.gz
Merge pull request #602 from pjbgf/parse-optimisation
Parse optimisations
Diffstat (limited to 'plumbing/reference.go')
-rw-r--r--plumbing/reference.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/plumbing/reference.go b/plumbing/reference.go
index deb5067..eef11e8 100644
--- a/plumbing/reference.go
+++ b/plumbing/reference.go
@@ -204,6 +204,21 @@ func (r *Reference) Strings() [2]string {
}
func (r *Reference) String() string {
- s := r.Strings()
- return fmt.Sprintf("%s %s", s[1], s[0])
+ ref := ""
+ switch r.Type() {
+ case HashReference:
+ ref = r.Hash().String()
+ case SymbolicReference:
+ ref = symrefPrefix + r.Target().String()
+ default:
+ return ""
+ }
+
+ name := r.Name().String()
+ var v strings.Builder
+ v.Grow(len(ref) + len(name) + 1)
+ v.WriteString(ref)
+ v.WriteString(" ")
+ v.WriteString(name)
+ return v.String()
}