Prechádzať zdrojové kódy

Merge fixes from abderrahim.

Jelmer Vernooij 15 rokov pred
rodič
commit
8a15645c08

+ 6 - 0
NEWS

@@ -1,3 +1,9 @@
+0.3.3	UNRELEASED
+
+ FEATURES
+
+  * Implement ShaFile.__hash__().
+
 0.3.2	2009-05-20
 
  BUG FIXES

+ 2 - 5
bin/dulwich

@@ -43,12 +43,9 @@ def cmd_fetch_pack(args):
 	graphwalker = r.get_graph_walker()
 	f, commit = r.object_store.add_pack()
 	try:
-		client.fetch_pack(path, determine_wants, graphwalker, f.write, sys.stdout.write)
-		f.close()
+            client.fetch_pack(path, determine_wants, graphwalker, f.write, sys.stdout.write)
+        finally:
 		commit()
-	except:
-		f.close()
-		raise
 
 
 def cmd_log(args):

+ 2 - 1
dulwich/object_store.py

@@ -36,6 +36,7 @@ from dulwich.objects import (
     Tree,
     hex_to_sha,
     sha_to_hex,
+    S_ISGITLINK,
     )
 from dulwich.pack import (
     Pack,
@@ -505,7 +506,7 @@ class MissingObjectFinder(object):
         self.objects_to_send.update([e for e in entries if not e[0] in self.sha_done])
 
     def parse_tree(self, tree):
-        self.add_todo([(sha, name, not stat.S_ISDIR(mode)) for (mode, name, sha) in tree.entries()])
+        self.add_todo([(sha, name, not stat.S_ISDIR(mode)) for (mode, name, sha) in tree.entries() if not S_ISGITLINK(mode)])
 
     def parse_commit(self, commit):
         self.add_todo([(commit.tree, "", False)])

+ 3 - 0
dulwich/objects.py

@@ -128,6 +128,9 @@ class ShaFile(object):
     def __str__(self):
         return self.as_raw_string()
 
+    def __hash__(self):
+        return hash(self.id)
+
     def as_pretty_string(self):
         return self.as_raw_string()
 

+ 2 - 2
dulwich/pack.py

@@ -772,7 +772,7 @@ def write_pack_object(f, type, object):
     :param o: Object to write
     :return: Tuple with offset at which the object was written, and crc32
     """
-    ret = f.tell()
+    offset = f.tell()
     packed_data_hdr = ""
     if type == 6: # ref delta
         (delta_base_offset, object) = object
@@ -799,7 +799,7 @@ def write_pack_object(f, type, object):
         packed_data_hdr += basename
     packed_data = packed_data_hdr + zlib.compress(object)
     f.write(packed_data)
-    return (f.tell(), (zlib.crc32(packed_data) & 0xffffffff))
+    return (offset, (zlib.crc32(packed_data) & 0xffffffff))
 
 
 def write_pack(filename, objects, num_objects):

+ 7 - 6
dulwich/server.py

@@ -77,16 +77,17 @@ class GitBackend(Backend):
         self.get_refs = self.repo.get_refs
 
     def apply_pack(self, refs, read):
-        fd, commit = self.repo.object_store.add_thin_pack()
-        fd.write(read())
-        fd.close()
-        commit()
+        f, commit = self.repo.object_store.add_thin_pack()
+        try:
+            f.write(read())
+        finally:
+            commit()
 
         for oldsha, sha, ref in refs:
             if ref == "0" * 40:
-                self.repo.remove_ref(ref)
+                del self.repo.refs[ref]
             else:
-                self.repo.set_ref(ref, sha)
+                self.repo.refs[ref] = sha
 
         print "pack applied"
 

+ 4 - 0
dulwich/tests/test_objects.py

@@ -66,6 +66,10 @@ class BlobReadTests(unittest.TestCase):
         self.assertEqual(b.data, 'test 1\n')
         self.assertEqual(b.sha().hexdigest(), a_sha)
   
+    def test_hash(self):
+        b = self.get_blob(a_sha)
+        self.assertEqual(hash(b.id), hash(b))
+
     def test_parse_empty_blob_object(self):
         sha = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'
         b = self.get_blob(sha)