changeset 85:8f5fddaf002a

merged in changes from stepancheg patch queues
author Scott Chacon <schacon@gmail.com>
date Fri, 08 May 2009 11:35:42 -0700
parents 0e0a2d20deed (current diff) 81b78a91f2f5 (diff)
children 3ce739f2bd7e
files
diffstat 3 files changed, 31 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/dulwich/misc.py
+++ b/dulwich/misc.py
@@ -20,12 +20,19 @@
 These utilities can all be deleted when dulwich decides it wants to stop
 support for python 2.4.
 """
+
+from mercurial import demandimport
+import __builtin__
+orig_import = __builtin__.__import__
+demandimport.disable()
+
 try:
     import hashlib
 except ImportError:
     import sha
 import struct
 
+__builtin__.__import__ = orig_import
 
 class defaultdict(dict):
     """A python 2.4 equivalent of collections.defaultdict."""
--- a/dulwich/objects.py
+++ b/dulwich/objects.py
@@ -467,7 +467,7 @@
             assert text[count] == ' ', "Invalid commit object, " \
                  "author information must be followed by space not %s" % text[count]
             count += 1
-            self._author_time = int(text[count:count+10])
+            self._author_time = int(text[count:].split(" ", 1)[0])
             while text[count] != ' ':
                 count += 1
             self._author_timezone = int(text[count:count+6])
--- a/dulwich/pack.py
+++ b/dulwich/pack.py
@@ -30,6 +30,11 @@
 a pointer in to the corresponding packfile.
 """
 
+from mercurial import demandimport
+import __builtin__
+orig_import = __builtin__.__import__
+demandimport.disable()
+
 try:
     from collections import defaultdict
 except ImportError:
@@ -61,6 +66,8 @@
     )
 from misc import make_sha
 
+__builtin__.__import__ = orig_import
+
 supports_mmap_offset = (sys.version_info[0] >= 3 or
         (sys.version_info[0] == 2 and sys.version_info[1] >= 6))
 
@@ -107,9 +114,14 @@
     :param access: Access mechanism.
     :return: MMAP'd area.
     """
-    mem = mmap.mmap(f.fileno(), size+offset, access=access)
-    return mem, offset
-
+    print f, offset, size
+    if supports_mmap_offset:
+        mem = mmap.mmap(f.fileno(), size + offset % mmap.PAGESIZE, access=access,
+                offset=offset / mmap.PAGESIZE * mmap.PAGESIZE)
+        return mem, offset % mmap.PAGESIZE
+    else:
+        mem = mmap.mmap(f.fileno(), size+offset, access=access)
+        return mem, offset
 
 def load_pack_index(filename):
     f = open(filename, 'r')
@@ -451,9 +463,12 @@
         """Calculate the checksum for this pack."""
         map, map_offset = simple_mmap(self._file, 0, self._size - 20)
         try:
-            return make_sha(map[map_offset:self._size-20]).digest()
-        finally:
+            r = make_sha(map[map_offset:self._size-20]).digest()
             map.close()
+            return r
+        except:
+            map.close()
+            raise
 
     def resolve_object(self, offset, type, obj, get_ref, get_offset=None):
         """Resolve an object, possibly resolving deltas when necessary.
@@ -500,8 +515,10 @@
                 offset += total_size
                 if progress:
                     progress(i, num)
-        finally:
             map.close()
+        except:
+            map.close()
+            raise
   
     def iterentries(self, ext_resolve_ref=None, progress=None):
         found = {}