aboutsummaryrefslogtreecommitdiffstats
path: root/clients/common/common.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-12 01:59:53 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-12 01:59:53 +0200
commit805cc777b083fee68a8834ebe1823d0b9dc6a00f (patch)
treee497602859f7e238072a31d20477db6a656f6482 /clients/common/common.go
parent68307cee4259c6c4fded8124af7f993f0266a545 (diff)
downloadgo-git-805cc777b083fee68a8834ebe1823d0b9dc6a00f.tar.gz
general: usage of the new Reference objects
Diffstat (limited to 'clients/common/common.go')
-rw-r--r--clients/common/common.go42
1 files changed, 33 insertions, 9 deletions
diff --git a/clients/common/common.go b/clients/common/common.go
index 1c6e552..a09f2d8 100644
--- a/clients/common/common.go
+++ b/clients/common/common.go
@@ -180,8 +180,7 @@ func (c *Capabilities) String() string {
type GitUploadPackInfo struct {
Capabilities *Capabilities
- Head core.Hash
- Refs map[string]core.Hash
+ Refs map[core.ReferenceName]*core.Reference
}
func NewGitUploadPackInfo() *GitUploadPackInfo {
@@ -207,7 +206,7 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error {
}
isEmpty := true
- r.Refs = map[string]core.Hash{}
+ r.Refs = map[core.ReferenceName]*core.Reference{}
for _, line := range lines {
if !r.isValidLine(line) {
continue
@@ -230,9 +229,15 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error {
}
func (r *GitUploadPackInfo) decodeHeaderLine(line string) {
- parts := strings.SplitN(line, " HEAD", 2)
- r.Head = core.NewHash(parts[0])
r.Capabilities.Decode(line)
+
+ name := r.Capabilities.SymbolicReference("HEAD")
+ if len(name) == 0 {
+ return
+ }
+
+ refName := core.ReferenceName(name)
+ r.Refs[core.HEAD] = core.NewSymbolicReference(core.HEAD, refName)
}
func (r *GitUploadPackInfo) isValidLine(line string) bool {
@@ -245,7 +250,22 @@ func (r *GitUploadPackInfo) readLine(line string) {
return
}
- r.Refs[parts[1]] = core.NewHash(parts[0])
+ ref := core.NewReferenceFromStrings(parts[1], parts[0])
+ r.Refs[ref.Name()] = ref
+}
+
+func (r *GitUploadPackInfo) Head() *core.Reference {
+ h, ok := r.Refs[core.HEAD]
+ if !ok {
+ return nil
+ }
+
+ ref, ok := r.Refs[h.Target()]
+ if !ok {
+ return nil
+ }
+
+ return ref
}
func (r *GitUploadPackInfo) String() string {
@@ -256,10 +276,14 @@ func (r *GitUploadPackInfo) Bytes() []byte {
e := pktline.NewEncoder()
e.AddLine("# service=git-upload-pack")
e.AddFlush()
- e.AddLine(fmt.Sprintf("%s HEAD\x00%s", r.Head, r.Capabilities.String()))
+ e.AddLine(fmt.Sprintf("%s HEAD\x00%s", r.Head().Hash(), r.Capabilities.String()))
+
+ for _, ref := range r.Refs {
+ if ref.Type() != core.HashReference {
+ continue
+ }
- for name, id := range r.Refs {
- e.AddLine(fmt.Sprintf("%s %s", id, name))
+ e.AddLine(fmt.Sprintf("%s %s", ref.Hash(), ref.Name()))
}
e.AddFlush()