Browse Source

Fix open modes of e.g. packs to be binary.

Jelmer Vernooij 16 years ago
parent
commit
ba8e57dd8d
4 changed files with 16 additions and 10 deletions
  1. 6 0
      NEWS
  2. 2 2
      dulwich/object_store.py
  3. 5 5
      dulwich/pack.py
  4. 3 3
      dulwich/repo.py

+ 6 - 0
NEWS

@@ -1,5 +1,11 @@
 0.3.2   UNRELEASED
 
+ BUG FIXES
+
+  * Support the encoding field in Commits.
+  
+  * Some Windows compatibility fixes.
+
 0.3.1	2009-05-13
 
  FEATURES

+ 2 - 2
dulwich/object_store.py

@@ -287,7 +287,7 @@ class DiskObjectStore(BaseObjectStore):
         in a different pack.
         """
         fd, path = tempfile.mkstemp(dir=self.pack_dir, suffix=".pack")
-        f = os.fdopen(fd, 'w')
+        f = os.fdopen(fd, 'wb')
         def commit():
             os.fsync(fd)
             f.close()
@@ -302,7 +302,7 @@ class DiskObjectStore(BaseObjectStore):
             call when the pack is finished.
         """
         fd, path = tempfile.mkstemp(dir=self.pack_dir, suffix=".pack")
-        f = os.fdopen(fd, 'w')
+        f = os.fdopen(fd, 'wb')
         def commit():
             os.fsync(fd)
             f.close()

+ 5 - 5
dulwich/pack.py

@@ -123,7 +123,7 @@ def simple_mmap(f, offset, size, access=mmap.ACCESS_READ):
 
 
 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:
@@ -176,7 +176,7 @@ class PackIndex(object):
         # 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)
@@ -754,7 +754,7 @@ def write_pack(filename, objects, num_objects):
     :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:
@@ -818,7 +818,7 @@ def write_pack_index_v1(filename, entries, pack_checksum):
             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:
@@ -966,7 +966,7 @@ def write_pack_index_v2(filename, entries, pack_checksum):
             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))

+ 3 - 3
dulwich/repo.py

@@ -146,7 +146,7 @@ class DiskRefsContainer(RefsContainer):
         dirpath = os.path.dirname(file)
         if not os.path.exists(dirpath):
             os.makedirs(dirpath)
-        f = open(file, 'w')
+        f = open(file, 'wb')
         try:
             f.write(ref+"\n")
         finally:
@@ -390,8 +390,8 @@ class Repo(object):
             os.mkdir(os.path.join(path, *d))
         ret = cls(path)
         ret.refs.set_ref("HEAD", "refs/heads/master")
-        open(os.path.join(path, 'description'), 'w').write("Unnamed repository")
-        open(os.path.join(path, 'info', 'excludes'), 'w').write("")
+        open(os.path.join(path, 'description'), 'wb').write("Unnamed repository")
+        open(os.path.join(path, 'info', 'excludes'), 'wb').write("")
         return ret
 
     create = init_bare