Browse Source

Remove duplicate functions.

Jelmer Vernooij 16 years ago
parent
commit
925d9c7a14
3 changed files with 7 additions and 20 deletions
  1. 3 2
      dulwich/objects.py
  2. 2 16
      dulwich/pack.py
  3. 2 2
      dulwich/tests/test_pack.py

+ 3 - 2
dulwich/objects.py

@@ -1,5 +1,6 @@
 # objects.py -- Acces to base git objects
 # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
+# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
 # The header parsing code is based on that from git itself, which is
 # Copyright (C) 2005 Linus Torvalds
 # and licensed under v2 of the GPL.
@@ -55,8 +56,8 @@ def sha_to_hex(sha):
 def hex_to_sha(hex):
   """Takes a hex sha and returns a binary sha"""
   sha = ''
-  for i in range(0,20):
-    sha += chr(int(hex[i*2:i*2+2], 16))
+  for i in range(0, len(hex), 2):
+    sha += chr(int(hex[i:i+2], 16))
   assert len(sha) == 20, "Incorrent length of sha1: %d" % len(sha)
   return sha
 

+ 2 - 16
dulwich/pack.py

@@ -45,6 +45,8 @@ import zlib
 
 from objects import (
         ShaFile,
+        hex_to_sha,
+        sha_to_hex,
         )
 from errors import ApplyDeltaError
 
@@ -81,22 +83,6 @@ def iter_sha1(iter):
     return sha.hexdigest()
 
 
-def hex_to_sha(hex):
-  """Convert a hex string to a binary sha string."""
-  ret = ""
-  for i in range(0, len(hex), 2):
-    ret += chr(int(hex[i:i+2], 16))
-  return ret
-
-
-def sha_to_hex(sha):
-  """Convert a binary sha string to a hex sha string."""
-  ret = ""
-  for i in sha:
-      ret += "%02x" % ord(i)
-  return ret
-
-
 MAX_MMAP_SIZE = 256 * 1024 * 1024
 
 def simple_mmap(f, offset, size, access=mmap.ACCESS_READ):

+ 2 - 2
dulwich/tests/test_pack.py

@@ -179,10 +179,10 @@ class TestPack(PackTests):
 class TestHexToSha(unittest.TestCase):
 
     def test_simple(self):
-        self.assertEquals('\xab\xcd\xef', hex_to_sha("abcdef"))
+        self.assertEquals('\xab\xcd' * 10, hex_to_sha("abcd" * 10))
 
     def test_reverse(self):
-        self.assertEquals("abcdef", sha_to_hex('\xab\xcd\xef'))
+        self.assertEquals("abcd" * 10, sha_to_hex('\xab\xcd' * 10))
 
 
 class BaseTestPackIndexWriting(object):