Pārlūkot izejas kodu

Extract all-zero SHA as a constant in protocol.py

Change-Id: Ie8305773ba034ae9c35c6503573fe56de5c24064
Dave Borowitz 15 gadi atpakaļ
vecāks
revīzija
3ec93cb958
3 mainītis faili ar 11 papildinājumiem un 7 dzēšanām
  1. 5 5
      dulwich/client.py
  2. 2 0
      dulwich/protocol.py
  3. 4 2
      dulwich/server.py

+ 5 - 5
dulwich/client.py

@@ -32,6 +32,7 @@ from dulwich.errors import (
 from dulwich.protocol import (
     Protocol,
     TCP_GIT_PORT,
+    ZERO_SHA,
     extract_capabilities,
     )
 from dulwich.pack import (
@@ -97,18 +98,18 @@ class GitClient(object):
             self.proto.write_pkt_line(None)
             return {}
         want = []
-        have = [x for x in old_refs.values() if not x == "0" * 40]
+        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, "0" * 40)
-            new_sha1 = new_refs.get(refname, "0" * 40)
+            old_sha1 = old_refs.get(refname, ZERO_SHA)
+            new_sha1 = new_refs.get(refname, ZERO_SHA)
             if old_sha1 != new_sha1:
                 if sent_capabilities:
                     self.proto.write_pkt_line("%s %s %s" % (old_sha1, new_sha1, refname))
                 else:
                     self.proto.write_pkt_line("%s %s %s\0%s" % (old_sha1, new_sha1, refname, self.capabilities()))
                     sent_capabilities = True
-            if not new_sha1 in (have, "0" * 40):
+            if not new_sha1 in (have, ZERO_SHA):
                 want.append(new_sha1)
         self.proto.write_pkt_line(None)
         if not want:
@@ -333,4 +334,3 @@ class SSHGitClient(GitClient):
         client = GitClient(lambda: _fileno_can_read(remote.proc.stdout.fileno()), remote.recv, remote.send, *self._args, **self._kwargs)
         return client.fetch_pack(path, determine_wants, graph_walker, pack_data,
                                  progress)
-

+ 2 - 0
dulwich/protocol.py

@@ -28,6 +28,8 @@ from dulwich.errors import (
 
 TCP_GIT_PORT = 9418
 
+ZERO_SHA = "0" * 40
+
 SINGLE_ACK = 0
 MULTI_ACK = 1
 MULTI_ACK_DETAILED = 2

+ 4 - 2
dulwich/server.py

@@ -42,6 +42,7 @@ from dulwich.protocol import (
     Protocol,
     ProtocolFile,
     TCP_GIT_PORT,
+    ZERO_SHA,
     extract_capabilities,
     extract_want_line_capabilities,
     SINGLE_ACK,
@@ -125,7 +126,7 @@ class GitBackend(Backend):
             # TODO: check refname
             ref_error = None
             try:
-                if sha == "0" * 40:
+                if sha == ZERO_SHA:
                     if not delete_refs:
                         raise GitProtocolError(
                           'Attempted to delete refs without delete-refs '
@@ -547,7 +548,8 @@ class ReceivePackHandler(Handler):
                     ref = refs[i]
                     self.proto.write_pkt_line("%s %s\n" % (ref[1], ref[0]))
             else:
-                self.proto.write_pkt_line("0000000000000000000000000000000000000000 capabilities^{} %s" % self.capability_line())
+                self.proto.write_pkt_line("%s capabilities^{} %s" % (
+                  ZERO_SHA, self.capability_line()))
 
             self.proto.write("0000")
             if self.advertise_refs: