@@ -97,11 +97,6 @@ func NewCapabilities() *Capabilities {
9797
9898// Decode decodes a string
9999func (c * Capabilities ) Decode (raw string ) {
100- parts := strings .SplitN (raw , "HEAD" , 2 )
101- if len (parts ) == 2 {
102- raw = parts [1 ]
103- }
104-
105100 params := strings .Split (raw , " " )
106101 for _ , p := range params {
107102 s := strings .SplitN (p , "=" , 2 )
@@ -234,12 +229,10 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error {
234229 continue
235230 }
236231
237- if len (r .Capabilities .o ) == 0 {
238- r .decodeHeaderLine (line )
239- continue
232+ if err := r .readLine (line ); err != nil {
233+ return err
240234 }
241235
242- r .readLine (line )
243236 isEmpty = false
244237 }
245238
@@ -250,29 +243,31 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error {
250243 return nil
251244}
252245
253- func (r * GitUploadPackInfo ) decodeHeaderLine (line string ) {
254- r .Capabilities .Decode (line )
255-
256- name := r .Capabilities .SymbolicReference ("HEAD" )
257- if len (name ) == 0 {
258- return
259- }
260-
261- refName := core .ReferenceName (name )
262- r .Refs .Set (core .NewSymbolicReference (core .HEAD , refName ))
263- }
264-
265246func (r * GitUploadPackInfo ) isValidLine (line string ) bool {
266247 return line [0 ] != '#'
267248}
268249
269- func (r * GitUploadPackInfo ) readLine (line string ) {
270- parts := strings .Split (strings .Trim (line , " \n " ), " " )
271- if len (parts ) != 2 {
272- return
250+ func (r * GitUploadPackInfo ) readLine (line string ) error {
251+ hashEnd := strings .Index (line , " " )
252+ hash := line [:hashEnd ]
253+
254+ zeroID := strings .Index (line , string ([]byte {0 }))
255+ if zeroID == - 1 {
256+ name := line [hashEnd + 1 : len (line )- 1 ]
257+ ref := core .NewReferenceFromStrings (name , hash )
258+ return r .Refs .Set (ref )
259+ }
260+
261+ name := line [hashEnd + 1 : zeroID ]
262+ r .Capabilities .Decode (line [zeroID + 1 : len (line )- 1 ])
263+ if ! r .Capabilities .Supports ("symref" ) {
264+ ref := core .NewReferenceFromStrings (name , hash )
265+ return r .Refs .Set (ref )
273266 }
274267
275- r .Refs .Set (core .NewReferenceFromStrings (parts [1 ], parts [0 ]))
268+ target := r .Capabilities .SymbolicReference (name )
269+ ref := core .NewSymbolicReference (core .ReferenceName (name ), core .ReferenceName (target ))
270+ return r .Refs .Set (ref )
276271}
277272
278273func (r * GitUploadPackInfo ) Head () * core.Reference {
0 commit comments