@@ -97,11 +97,6 @@ func NewCapabilities() *Capabilities {
97
97
98
98
// Decode decodes a string
99
99
func (c * Capabilities ) Decode (raw string ) {
100
- parts := strings .SplitN (raw , "HEAD" , 2 )
101
- if len (parts ) == 2 {
102
- raw = parts [1 ]
103
- }
104
-
105
100
params := strings .Split (raw , " " )
106
101
for _ , p := range params {
107
102
s := strings .SplitN (p , "=" , 2 )
@@ -234,12 +229,10 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error {
234
229
continue
235
230
}
236
231
237
- if len (r .Capabilities .o ) == 0 {
238
- r .decodeHeaderLine (line )
239
- continue
232
+ if err := r .readLine (line ); err != nil {
233
+ return err
240
234
}
241
235
242
- r .readLine (line )
243
236
isEmpty = false
244
237
}
245
238
@@ -250,29 +243,31 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error {
250
243
return nil
251
244
}
252
245
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
-
265
246
func (r * GitUploadPackInfo ) isValidLine (line string ) bool {
266
247
return line [0 ] != '#'
267
248
}
268
249
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 )
273
266
}
274
267
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 )
276
271
}
277
272
278
273
func (r * GitUploadPackInfo ) Head () * core.Reference {
0 commit comments