objectstore: implicit clone based on object ids

If the object's id does not match with the one supplied for the
commit, we create a clone. Otherwise we store the tree.
The code path is arranged in a way that we always go through
`Object.store_tree` so we always call `Object.finalize` as a
prepration for the future, where we might actually do something
meaningful in the finalizer, like reset the *times or count the
tree size.
This commit is contained in:
Christian Kellner 2022-08-22 17:00:06 +00:00
parent 5346025031
commit 28b8252a04
3 changed files with 15 additions and 9 deletions

View file

@ -113,7 +113,7 @@ class TestObjectStore(unittest.TestCase):
data_inode = st.st_ino
# commit the object as "x", making a copy
store.commit(tree, "x", clone=True)
store.commit(tree, "x")
# check that "data" got indeed copied
tree = store.get("x")
@ -191,7 +191,7 @@ class TestObjectStore(unittest.TestCase):
p.touch()
assert not store.contains("a")
store.commit(tree, "a", clone=True)
store.commit(tree, "a") # store via "a", creates a clone
assert store.contains("a")
with tree.write() as path: