aboutsummaryrefslogtreecommitdiffstats
path: root/clients/common/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'clients/common/common.go')
-rw-r--r--clients/common/common.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/clients/common/common.go b/clients/common/common.go
index 8756cfd..460eb10 100644
--- a/clients/common/common.go
+++ b/clients/common/common.go
@@ -92,6 +92,17 @@ func (c *Capabilities) Decode(raw string) {
}
}
+// Get returns the values for a capability
+func (c *Capabilities) Get(capability string) *Capability {
+ return c.m[capability]
+}
+
+// Set sets a capability removing the values
+func (c *Capabilities) Set(capability string, values ...string) {
+ delete(c.m, capability)
+ c.Add(capability, values...)
+}
+
// Add adds a capability, values are optional
func (c *Capabilities) Add(capability string, values ...string) {
if !c.Supports(capability) {
@@ -112,11 +123,6 @@ func (c *Capabilities) Supports(capability string) bool {
return ok
}
-// Get returns the values for a capability
-func (c *Capabilities) Get(capability string) *Capability {
- return c.m[capability]
-}
-
// SymbolicReference returns the reference for a given symbolic reference
func (c *Capabilities) SymbolicReference(sym string) string {
if !c.Supports("symref") {
@@ -170,7 +176,7 @@ func (c *Capabilities) String() string {
type GitUploadPackInfo struct {
Capabilities *Capabilities
- Head string
+ Head core.Hash
Refs map[string]core.Hash
}
@@ -221,8 +227,7 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error {
func (r *GitUploadPackInfo) decodeHeaderLine(line string) {
parts := strings.SplitN(line, " HEAD", 2)
-
- r.Head = parts[0]
+ r.Head = core.NewHash(parts[0])
r.Capabilities.Decode(line)
}
@@ -251,7 +256,7 @@ 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.Refs[r.Head].String(), r.Capabilities.String()))
+ e.AddLine(fmt.Sprintf("%s HEAD\x00%s", r.Head, r.Capabilities.String()))
for name, id := range r.Refs {
e.AddLine(fmt.Sprintf("%s %s", id, name))