# HG changeset patch # User Scott Chacon # Date 1241807742 25200 # Node ID 8f5fddaf002abe664feb31b53e979692aacabf97 # Parent 0e0a2d20deed9552df41153fde587a8145b1c64d# Parent 81b78a91f2f55ea81f2c3e7d9306a8634524f65b merged in changes from stepancheg patch queues diff --git a/dulwich/misc.py b/dulwich/misc.py --- 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.""" diff --git a/dulwich/objects.py b/dulwich/objects.py --- 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]) diff --git a/dulwich/pack.py b/dulwich/pack.py --- 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 = {}