diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-31 19:54:17 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-31 19:54:17 +0200 |
commit | 587d380585c08e9b5f839d06df0f0c7bd32218cf (patch) | |
tree | 6fa1e967214da00720ce9ccd04d426908ae05589 | |
parent | 7aa8f0750c93b58876a06e79c50398901e5bdeb8 (diff) | |
parent | 484d472550d74138731bfdef4e68d8b810abb93f (diff) | |
download | go-git-587d380585c08e9b5f839d06df0f0c7bd32218cf.tar.gz |
Merge branch 'v4' of github.com:src-d/go-git into v4
-rw-r--r-- | clients/common/common.go | 47 | ||||
-rw-r--r-- | clients/common/common_test.go | 18 |
2 files changed, 39 insertions, 26 deletions
diff --git a/clients/common/common.go b/clients/common/common.go index e1140ec..0d0026b 100644 --- a/clients/common/common.go +++ b/clients/common/common.go @@ -97,11 +97,6 @@ func NewCapabilities() *Capabilities { // Decode decodes a string func (c *Capabilities) Decode(raw string) { - parts := strings.SplitN(raw, "HEAD", 2) - if len(parts) == 2 { - raw = parts[1] - } - params := strings.Split(raw, " ") for _, p := range params { s := strings.SplitN(p, "=", 2) @@ -234,12 +229,10 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error { continue } - if len(r.Capabilities.o) == 0 { - r.decodeHeaderLine(line) - continue + if err := r.readLine(line); err != nil { + return err } - r.readLine(line) isEmpty = false } @@ -250,29 +243,31 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error { return nil } -func (r *GitUploadPackInfo) decodeHeaderLine(line string) { - r.Capabilities.Decode(line) - - name := r.Capabilities.SymbolicReference("HEAD") - if len(name) == 0 { - return - } - - refName := core.ReferenceName(name) - r.Refs.Set(core.NewSymbolicReference(core.HEAD, refName)) -} - func (r *GitUploadPackInfo) isValidLine(line string) bool { return line[0] != '#' } -func (r *GitUploadPackInfo) readLine(line string) { - parts := strings.Split(strings.Trim(line, " \n"), " ") - if len(parts) != 2 { - return +func (r *GitUploadPackInfo) readLine(line string) error { + hashEnd := strings.Index(line, " ") + hash := line[:hashEnd] + + zeroID := strings.Index(line, string([]byte{0})) + if zeroID == -1 { + name := line[hashEnd+1 : len(line)-1] + ref := core.NewReferenceFromStrings(name, hash) + return r.Refs.Set(ref) + } + + name := line[hashEnd+1 : zeroID] + r.Capabilities.Decode(line[zeroID+1 : len(line)-1]) + if !r.Capabilities.Supports("symref") { + ref := core.NewReferenceFromStrings(name, hash) + return r.Refs.Set(ref) } - r.Refs.Set(core.NewReferenceFromStrings(parts[1], parts[0])) + target := r.Capabilities.SymbolicReference(name) + ref := core.NewSymbolicReference(core.ReferenceName(name), core.ReferenceName(target)) + return r.Refs.Set(ref) } func (r *GitUploadPackInfo) Head() *core.Reference { diff --git a/clients/common/common_test.go b/clients/common/common_test.go index d2d3696..cc6c6d1 100644 --- a/clients/common/common_test.go +++ b/clients/common/common_test.go @@ -64,6 +64,24 @@ func (s *SuiteCommon) TestGitUploadPackInfo(c *C) { c.Assert(ref.Target(), Equals, core.ReferenceName(name)) } +const GitUploadPackInfoNoHEADFixture = "MDAxZSMgc2VydmljZT1naXQtdXBsb2FkLXBhY2sKMDAwMDAwYmNkN2UxZmVlMjYxMjM0YmIzYTQzYzA5NmY1NTg3NDhhNTY5ZDc5ZWZmIHJlZnMvaGVhZHMvdjQAbXVsdGlfYWNrIHRoaW4tcGFjayBzaWRlLWJhbmQgc2lkZS1iYW5kLTY0ayBvZnMtZGVsdGEgc2hhbGxvdyBuby1wcm9ncmVzcyBpbmNsdWRlLXRhZyBtdWx0aV9hY2tfZGV0YWlsZWQgbm8tZG9uZSBhZ2VudD1naXQvMS45LjEKMDAwMA==" + +func (s *SuiteCommon) TestGitUploadPackInfoNoHEAD(c *C) { + b, _ := base64.StdEncoding.DecodeString(GitUploadPackInfoNoHEADFixture) + + i := NewGitUploadPackInfo() + err := i.Decode(pktline.NewDecoder(bytes.NewBuffer(b))) + c.Assert(err, IsNil) + + name := i.Capabilities.SymbolicReference("HEAD") + c.Assert(name, Equals, "") + c.Assert(i.Refs, HasLen, 1) + + ref := i.Refs["refs/heads/v4"] + c.Assert(ref, NotNil) + c.Assert(ref.Hash().String(), Equals, "d7e1fee261234bb3a43c096f558748a569d79eff") +} + func (s *SuiteCommon) TestGitUploadPackInfoEmpty(c *C) { b := bytes.NewBuffer(nil) |