Mercurial > hg > hg-git
changeset 123:b51381c6fab8
Fix gclone on Windows
author | Ian Dees <undees@gmail.com> |
---|---|
date | Sun, 17 May 2009 01:55:48 -0700 (2009-05-17) |
parents | b3be536e3f50 |
children | 9dafb9ac24ff |
files | dulwich/object_store.py dulwich/pack.py dulwich/repo.py |
diffstat | 3 files changed, 15 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/dulwich/object_store.py +++ b/dulwich/object_store.py @@ -22,6 +22,7 @@ import itertools import os +import shutil import stat import tempfile import urllib2 @@ -248,7 +249,12 @@ basename = os.path.join(self.pack_dir, "pack-%s" % iter_sha1(entry[0] for entry in entries)) write_pack_index_v2(basename+".idx", entries, p.get_stored_checksum()) - os.rename(path, basename + ".pack") + try: + os.rename(path, basename + ".pack") + except OSError: + # Hack for Windows access denied error. + # TODO: mark the original for deletion later. + shutil.copyfile(path, basename + ".pack") self._add_known_pack(basename) def add_thin_pack(self):
--- a/dulwich/pack.py +++ b/dulwich/pack.py @@ -128,7 +128,7 @@ def load_pack_index(filename): - f = open(filename, 'r') + f = open(filename, 'rb') if f.read(4) == '\377tOc': version = struct.unpack(">L", f.read(4))[0] if version == 2: @@ -181,7 +181,7 @@ # ensure that it hasn't changed. self._size = os.path.getsize(filename) if file is None: - self._file = open(filename, 'r') + self._file = open(filename, 'rb') else: self._file = file self._contents, map_offset = simple_mmap(self._file, 0, self._size) @@ -733,7 +733,7 @@ :param objects: Iterable over (object, path) tuples to write :param num_objects: Number of objects to write """ - f = open(filename + ".pack", 'w') + f = open(filename + ".pack", 'wb') try: entries, data_sum = write_pack_data(f, objects, num_objects) finally: @@ -797,7 +797,7 @@ crc32_checksum. :param pack_checksum: Checksum of the pack file. """ - f = open(filename, 'w') + f = open(filename, 'wb') f = SHA1Writer(f) fan_out_table = defaultdict(lambda: 0) for (name, offset, entry_checksum) in entries: @@ -945,7 +945,7 @@ crc32_checksum. :param pack_checksum: Checksum of the pack file. """ - f = open(filename, 'w') + f = open(filename, 'wb') f = SHA1Writer(f) f.write('\377tOc') # Magic! f.write(struct.pack(">L", 2))
--- a/dulwich/repo.py +++ b/dulwich/repo.py @@ -173,14 +173,12 @@ def _get_ref(self, file): f = open(file, 'rb') try: - contents = f.read() + contents = f.read().strip() if contents.startswith(SYMREF): ref = contents[len(SYMREF):] - if ref[-1] == '\n': - ref = ref[:-1] return self.ref(ref) - assert len(contents) == 41, 'Invalid ref in %s' % file - return contents[:-1] + assert len(contents) == 40, 'Invalid ref in %s' % file + return contents finally: f.close()