소스 검색

remove unused multi_ord.

Jelmer Vernooij 16 년 전
부모
커밋
4ec2879d2e
3개의 변경된 파일30개의 추가작업 그리고 28개의 파일을 삭제
  1. 4 1
      bin/dumppack
  2. 26 20
      dulwich/pack.py
  3. 0 7
      dulwich/tests/test_pack.py

+ 4 - 1
bin/dumppack

@@ -27,4 +27,7 @@ if not x.check():
 	print "CHECKSUM DOES NOT MATCH"
 print "Length: %d" % len(x)
 for name in x:
-	print "\t%s: %s" % (name, x[name])
+	try:
+		print "\t%s: %s" % (name, x[name])
+	except KeyError, k:
+		print "\t%s: Unable to resolve base %s" % (name, k)

+ 26 - 20
dulwich/pack.py

@@ -41,19 +41,21 @@ import struct
 import sys
 import zlib
 
+from objects import (
+        ShaFile,
+        )
+
 supports_mmap_offset = (sys.version_info[0] >= 3 or 
         (sys.version_info[0] == 2 and sys.version_info[1] >= 6))
 
-from objects import (ShaFile,
-                     _decompress,
-                     )
 
 def read_zlib(data, offset, dec_size):
     obj = zlib.decompressobj()
     x = ""
     fed = 0
     while obj.unused_data == "":
-        add = data[offset+fed:offset+fed+1024]
+        base = offset+fed
+        add = data[base:base+1024]
         fed += len(add)
         x += obj.decompress(add)
     assert len(x) == dec_size
@@ -76,6 +78,14 @@ def sha_to_hex(sha):
 MAX_MMAP_SIZE = 256 * 1024 * 1024
 
 def simple_mmap(f, offset, size, access=mmap.ACCESS_READ):
+    """Simple wrapper for mmap() which always supports the offset parameter.
+
+    :param f: File object.
+    :param offset: Offset in the file, from the beginning of the file.
+    :param size: Size of the mmap'ed area
+    :param access: Access mechanism.
+    :return: MMAP'd area.
+    """
     if offset+size > MAX_MMAP_SIZE and not supports_mmap_offset:
         raise AssertionError("%s is larger than 256 meg, and this version "
             "of Python does not support the offset argument to mmap().")
@@ -106,13 +116,6 @@ def simple_mmap(f, offset, size, access=mmap.ACCESS_READ):
         return ArraySkipper(mem, offset)
 
 
-def multi_ord(map, start, count):
-    value = 0
-    for i in range(count):
-        value = value * 0x100 + ord(map[start+i])
-    return value
-
-
 def resolve_object(offset, type, obj, get_ref, get_offset):
   if type == 6: # offset delta
      (delta_offset, delta) = obj
@@ -416,23 +419,26 @@ class PackData(object):
       cur_offset += 1
     raw_base = cur_offset+1
     if type == 6: # offset delta
-        # FIXME: Parse size
-        raise AssertionError("OFS_DELTA not yet supported")
+        first_byte = ord(map[raw_base])
+        sign_extend = first_byte & 0x80
+        delta_base_offset = first_byte & 0x7f
+        cur_offset = 0
+        while sign_extend > 0:
+          byte = ord(map[raw_base+cur_offset+1])
+          sign_extend = byte & 0x80
+          delta_base_offset_part = byte & 0x7f
+          delta_base_offset += delta_base_offset_part << ((cur_offset * 7) + 4)
+          cur_offset += 1
         uncomp, comp_len = read_zlib(map, raw_base, size)
         assert size == len(uncomp)
-        return type, (uncomp, offset), comp_len+raw_base
+        return type, (uncomp, delta_bsae_offset), comp_len+raw_base
     elif type == 7: # ref delta
         basename = map[cur_offset:cur_offset+20]
         raw_base += 20
         uncomp, comp_len = read_zlib(map, raw_base, size)
         assert size == len(uncomp)
-        # text = apply_delta(base, uncomp)
         return type, (uncomp, basename), comp_len+raw_base
     else:
-        # The size is the inflated size, so we have no idea what the deflated size
-        # is, so for now give it as much as we have. It should really iterate
-        # feeding it more data if it doesn't decompress, but as we have the whole
-        # thing then just use it.
         uncomp, comp_len = read_zlib(map, raw_base, size)
         assert len(uncomp) == size
         return type, uncomp, comp_len+raw_base
@@ -623,7 +629,7 @@ class Pack(object):
         if offset is None:
             raise KeyError(sha1)
 
-        type, obj =  self._pack.get_object_at(offset)
+        type, obj = self._pack.get_object_at(offset)
         return resolve_object(offset, type, obj, self._get_text, 
             self._pack.get_object_at)
 

+ 0 - 7
dulwich/tests/test_pack.py

@@ -28,7 +28,6 @@ from dulwich.pack import (
         PackIndex,
         PackData,
         hex_to_sha,
-        multi_ord,
         sha_to_hex,
         write_pack_index_v1,
         write_pack_index_v2,
@@ -172,12 +171,6 @@ class TestHexToSha(unittest.TestCase):
         self.assertEquals("abcdef", sha_to_hex('\xab\xcd\xef'))
 
 
-class TestMultiOrd(unittest.TestCase):
-
-    def test_simple(self):
-        self.assertEquals(418262508645L, multi_ord("abcde", 0, 5))
-
-
 class TestPackIndexWriting(object):
 
     def test_empty(self):