Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master-1, master-0, and 0.9.4

client: Refactor handling of negotiation.

Changeset 15910d9f0875

Parent 288fc91228cf

by Jelmer Vernooij

Changes to one file · Browse files at 15910d9f0875 Showing diff from parent 288fc91228cf Diff from another changeset...

Change 1 of 3 Show Entire File dulwich/​client.py Stacked
 
254
255
256
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
258
259
 
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
 
 
344
345
346
 
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
 
 
613
614
615
 
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
 
352
353
354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
356
357
358
359
 
605
606
607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
609
610
611
612
@@ -254,6 +254,35 @@
  else:   if cb is not None:   cb(pkt) + + def _handle_receive_pack_head(self, proto, capabilities, old_refs, new_refs): + """Handle the head of a 'git-receive-pack' request. + + :param proto: Protocol object to read from + :param capabilities: List of negotiated capabilities + :param old_refs: Old refs, as received from the server + :param new_refs: New refs + :return: (have, want) tuple + """ + want = [] + have = [x for x in old_refs.values() if not x == ZERO_SHA] + sent_capabilities = False + for refname in set(new_refs.keys() + old_refs.keys()): + old_sha1 = old_refs.get(refname, ZERO_SHA) + new_sha1 = new_refs.get(refname, ZERO_SHA) + if old_sha1 != new_sha1: + if sent_capabilities: + proto.write_pkt_line('%s %s %s' % (old_sha1, new_sha1, + refname)) + else: + proto.write_pkt_line( + '%s %s %s\0%s' % (old_sha1, new_sha1, refname, + ' '.join(capabilities))) + sent_capabilities = True + if new_sha1 not in have and new_sha1 != ZERO_SHA: + want.append(new_sha1) + proto.write_pkt_line(None) + return (have, want)     def _handle_receive_pack_tail(self, proto, capabilities, progress):   """Handle the tail of a 'git-receive-pack' request. @@ -323,24 +352,8 @@
  if not new_refs:   proto.write_pkt_line(None)   return {} - want = [] - have = [x for x in old_refs.values() if not x == ZERO_SHA] - sent_capabilities = False - for refname in set(new_refs.keys() + old_refs.keys()): - old_sha1 = old_refs.get(refname, ZERO_SHA) - new_sha1 = new_refs.get(refname, ZERO_SHA) - if old_sha1 != new_sha1: - if sent_capabilities: - proto.write_pkt_line('%s %s %s' % (old_sha1, new_sha1, - refname)) - else: - proto.write_pkt_line( - '%s %s %s\0%s' % (old_sha1, new_sha1, refname, - ' '.join(negotiated_capabilities))) - sent_capabilities = True - if new_sha1 not in have and new_sha1 != ZERO_SHA: - want.append(new_sha1) - proto.write_pkt_line(None) + (have, want) = self._handle_receive_pack_head(proto, + negotiated_capabilities, old_refs, new_refs)   if not want:   return new_refs   objects = generate_pack_contents(have, want) @@ -592,24 +605,8 @@
  raise NotImplementedError(self.fetch_pack)   req_data = StringIO()   req_proto = Protocol(None, req_data.write) - want = [] - have = [x for x in old_refs.values() if not x == ZERO_SHA] - sent_capabilities = False - for refname in set(new_refs.keys() + old_refs.keys()): - old_sha1 = old_refs.get(refname, ZERO_SHA) - new_sha1 = new_refs.get(refname, ZERO_SHA) - if old_sha1 != new_sha1: - if sent_capabilities: - req_proto.write_pkt_line('%s %s %s' % (old_sha1, new_sha1, - refname)) - else: - req_proto.write_pkt_line( - '%s %s %s\0%s' % (old_sha1, new_sha1, refname, - ' '.join(self._send_capabilities))) - sent_capabilities = True - if new_sha1 not in have and new_sha1 != ZERO_SHA: - want.append(new_sha1) - req_proto.write_pkt_line(None) + (have, want) = self._handle_receive_pack_head( + req_proto, negotiated_capabilities, old_refs, new_refs)   if not want:   return new_refs   objects = generate_pack_contents(have, want)