aboutsummaryrefslogtreecommitdiffstats
path: root/clients/common/common.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2015-10-23 02:26:15 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2015-10-23 02:26:15 +0200
commite1d8866ffa78fa16d2f39b0ba5344a7269ee5371 (patch)
tree4602b0ca341187aad77048f807cde423af410554 /clients/common/common.go
parent2275fa7d0c75d20103f90b0e1616937d5a9fc5e6 (diff)
downloadgo-git-e1d8866ffa78fa16d2f39b0ba5344a7269ee5371.tar.gz
clients and remote: fetch implementation
Diffstat (limited to 'clients/common/common.go')
-rw-r--r--clients/common/common.go46
1 files changed, 39 insertions, 7 deletions
diff --git a/clients/common/common.go b/clients/common/common.go
index 3527d7c..c3d15c1 100644
--- a/clients/common/common.go
+++ b/clients/common/common.go
@@ -2,6 +2,7 @@ package common
import (
"fmt"
+ "io/ioutil"
"net/url"
"strings"
@@ -72,9 +73,14 @@ func (r Capabilities) SymbolicReference(sym string) string {
return ""
}
+type RemoteHead struct {
+ Id string
+ Name string
+}
+
type GitUploadPackInfo struct {
Capabilities Capabilities
- Branches map[string]string
+ Refs map[string]*RemoteHead
}
func NewGitUploadPackInfo(d *pktline.Decoder) (*GitUploadPackInfo, error) {
@@ -92,7 +98,7 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error {
return err
}
- r.Branches = map[string]string{}
+ r.Refs = map[string]*RemoteHead{}
for _, line := range lines {
if !r.isValidLine(line) {
continue
@@ -118,15 +124,41 @@ func (r *GitUploadPackInfo) isValidLine(line string) bool {
}
func (r *GitUploadPackInfo) readLine(line string) {
- commit, branch := r.getCommitAndBranch(line)
- r.Branches[branch] = commit
+ rh := r.getRemoteHead(line)
+ r.Refs[rh.Name] = rh
}
-func (r *GitUploadPackInfo) getCommitAndBranch(line string) (string, string) {
+func (r *GitUploadPackInfo) getRemoteHead(line string) *RemoteHead {
parts := strings.Split(strings.Trim(line, " \n"), " ")
if len(parts) != 2 {
- return "", ""
+ return nil
}
- return parts[0], parts[1]
+ return &RemoteHead{parts[0], parts[1]}
+}
+
+type GitUploadPackRequest struct {
+ Want []string
+ Have []string
+}
+
+func (r *GitUploadPackRequest) String() string {
+ b, _ := ioutil.ReadAll(r.Reader())
+ return string(b)
+}
+
+func (r *GitUploadPackRequest) Reader() *strings.Reader {
+ e := pktline.NewEncoder()
+ for _, want := range r.Want {
+ e.AddLine(fmt.Sprintf("want %s", want))
+ }
+
+ for _, have := range r.Have {
+ e.AddLine(fmt.Sprintf("have %s", have))
+ }
+
+ e.AddFlush()
+ e.AddLine("done")
+
+ return e.GetReader()
}