Bläddra i källkod

Share capabilities extractor, port number.

Jelmer Vernooij 16 år sedan
förälder
incheckning
4a19eb2948
4 ändrade filer med 15 tillägg och 31 borttagningar
  1. 1 8
      dulwich/client.py
  2. 1 1
      dulwich/pack.py
  3. 7 0
      dulwich/protocol.py
  4. 6 22
      dulwich/server.py

+ 1 - 8
dulwich/client.py

@@ -18,14 +18,7 @@
 
 import select
 import socket
-from dulwich.protocol import Protocol, TCP_GIT_PORT
-
-def extract_capabilities(text):
-    if not "\0" in text:
-        return text
-    capabilities = text.split("\0")
-    return (capabilities[0], capabilities[1:])
-
+from dulwich.protocol import Protocol, TCP_GIT_PORT, extract_capabilities
 
 class SimpleFetchGraphWalker(object):
 

+ 1 - 1
dulwich/pack.py

@@ -420,7 +420,7 @@ class PackData(object):
       assert isinstance(type, int)
       assert isinstance(obj, tuple) or isinstance(obj, str)
       try:
-        type, obj = resolve_object(offset, type, obj, get_ref_delta,
+        type, obj = resolve_object(offset, type, obj, get_ref_text,
             at.__getitem__)
       except Postpone, (sha, ):
         postponed[sha].append((offset, type, obj))

+ 7 - 0
dulwich/protocol.py

@@ -1,5 +1,6 @@
 # protocol.py -- Shared parts of the git protocols
 # Copryight (C) 2008 John Carr <john.carr@unrouted.co.uk>
+# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -70,3 +71,9 @@ class Protocol(object):
             blob = blob[65530:]
 
 
+def extract_capabilities(text):
+    if not "\0" in text:
+        return text
+    capabilities = text.split("\0")
+    return (capabilities[0], capabilities[1:])
+

+ 6 - 22
dulwich/server.py

@@ -18,6 +18,9 @@
 
 import SocketServer
 from dulwich.protocol import Protocol, TCP_GIT_PORT
+from dulwich.repo import Repo
+from dulwich.pack import PackData, Pack, write_pack_data, extract_capabilities
+import os, sha, tempfile
 
 class Backend(object):
 
@@ -56,10 +59,6 @@ class Backend(object):
         """
         raise NotImplementedError
 
-from dulwich.repo import Repo
-from dulwich.pack import PackData, Pack
-import sha, tempfile, os
-from dulwich.pack import write_pack_data
 
 class GitBackend(Backend):
 
@@ -155,21 +154,6 @@ class Handler(object):
     def capabilities(self):
         return " ".join(self.default_capabilities())
 
-    def handshake(self, blob):
-        """
-        Compare remote capabilites with our own and alter protocol accordingly
-
-        :param blob: space seperated list of capabilities (i.e. wire format)
-        """
-        if not "\x00" in blob:
-            return blob
-        blob, caps = blob.split("\x00")
-
-        # FIXME: Do something with this..
-        caps = caps.split()
-
-        return blob
-
 
 class UploadPackHandler(Handler):
 
@@ -194,7 +178,7 @@ class UploadPackHandler(Handler):
         if want == None:
             return
 
-        want = self.handshake(want)
+        want, client_capabilities = extract_capabilities(want)
 
         # Keep reading the list of demands until we hit another "0000" 
         want_revs = []
@@ -211,7 +195,7 @@ class UploadPackHandler(Handler):
         have_revs = []
         have = self.proto.read_pkt_line()
         while have and have[:4] == 'have':
-            have_ref = have[6:46]
+            have_ref = have[5:45]
             if self.backend.has_revision(have_ref):
                 self.proto.write_pkt_line("ACK %s continue\n" % have_ref)
                 last_sha = have_ref
@@ -259,7 +243,7 @@ class ReceivePackHandler(Handler):
         if ref is None:
             return
 
-        ref = self.handshake(ref)
+        ref, client_capabilities = extract_capabilities(ref)
 
         # client will now send us a list of (oldsha, newsha, ref)
         while ref: