Browse Source

Use copies rather than references in MemoryObjectStore.

Jelmer Vernooij 9 năm trước cách đây
mục cha
commit
e099e14060
2 tập tin đã thay đổi với 9 bổ sung5 xóa
  1. 5 1
      NEWS
  2. 4 4
      dulwich/object_store.py

+ 5 - 1
NEWS

@@ -11,6 +11,10 @@
   * Fix `dulwich.porcelain.status` when used in empty trees.
     (Jelmer Vernooij, #415)
 
+  * Return copies of objects in MemoryObjectStore rather than
+    references, making the behaviour more consistent with that of
+    DiskObjectStore. (Félix Mattrat, Jelmer Vernooij)
+
  CHANGES
 
   * Drop support for Python 2.6.
@@ -25,7 +29,7 @@
     on wsgi.input. (Jonas Haag)
 
   * Support fastexport/fastimport functionality on python3 with newer
-    versions of fastimport (>= 0.9.5).
+    versions of fastimport (>= 0.9.5). (Jelmer Vernooij, Félix Mattrat)
 
 0.12.0	2015-12-13
 

+ 4 - 4
dulwich/object_store.py

@@ -716,7 +716,7 @@ class MemoryObjectStore(BaseObjectStore):
         return obj.type_num, obj.as_raw_string()
 
     def __getitem__(self, name):
-        return self._data[self._to_hexsha(name)]
+        return self._data[self._to_hexsha(name)].copy()
 
     def __delitem__(self, name):
         """Delete an object from this store, for testing only."""
@@ -726,7 +726,7 @@ class MemoryObjectStore(BaseObjectStore):
         """Add a single object to this object store.
 
         """
-        self._data[obj.id] = obj
+        self._data[obj.id] = obj.copy()
 
     def add_objects(self, objects):
         """Add a set of objects to this object store.
@@ -734,7 +734,7 @@ class MemoryObjectStore(BaseObjectStore):
         :param objects: Iterable over a list of objects.
         """
         for obj, path in objects:
-            self._data[obj.id] = obj
+            self.add_object(obj)
 
     def add_pack(self):
         """Add a new pack to this object store.
@@ -750,7 +750,7 @@ class MemoryObjectStore(BaseObjectStore):
             p = PackData.from_file(BytesIO(f.getvalue()), f.tell())
             f.close()
             for obj in PackInflater.for_pack_data(p, self.get_raw):
-                self._data[obj.id] = obj
+                self.add_object(obj)
         def abort():
             pass
         return f, commit, abort