Skip to content
Snippets Groups Projects
Commit cd881639 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

Detect if we need to recompute all from disk anyway (change at the root

level for example)
parent 02e23573
No related merge requests found
......@@ -357,13 +357,14 @@ def update_checksums_from(changed_paths, objects,
"""
root = objects[ROOT_TREE_KEY][0]['path']
# compute the list of changed paths to update (no action discrimination is
# necessary here since we'll walk back the fs from the deeper node's
# directory, so every deletion, add or modification will be seen)
# FIXME: Compute the lowest common ancestor to reduce the computations
# FIXME: if one changed path is a file at the rootdir, we recompute all
# from disk
# a first round-trip to ensure we don't need to recompute everything anyway
for parent in (os.path.dirname(p['path']) for p in changed_paths):
if parent == root:
return walk_and_compute_sha1_from_directory(root, dir_ok_fn)
# Recompute only what's needed
for changed_path in changed_paths:
path = changed_path['path']
if changed_path['action'] == 'D':
......@@ -376,14 +377,18 @@ def update_checksums_from(changed_paths, objects,
objects.pop(rootdir, None)
continue
# recompute from disk the checksums
# recompute from disk the checksums from impacted rootdir changes
# and update the original objects with new checksums for the
# arborescence tree below rootdir
hashes = walk_and_compute_sha1_from_directory(rootdir, dir_ok_fn,
with_root_tree=False)
# update the objects with new checksums for the arborescence tree below
# rootdir
objects.update(hashes)
# now recompute the hashes in memory from deeper_rootdir to root
# FIXME: In some cases, there will be too much computations
# here. We cannot postpone the computations though since the
# keys in the dict are not sorted.
# Recompute the hashes in memory from rootdir to root
objects = recompute_sha1_in_memory(root, rootdir, objects)
return objects
......@@ -407,3 +407,46 @@ class GitHashUpdateWithCommonAncestor(GitHashArborescenceTree):
objects)
self.assertEquals(expected_dict, actual_dict)
@istest
def update_checksums_detects_recomputation_from_all_is_needed(self):
# when
objects = git.walk_and_compute_sha1_from_directory(
self.tmp_root_path)
# Actions on disk (imagine a checkout of some form)
# 1. Create a new file
changed_path = os.path.join(self.tmp_root_path,
b'new-file-at-root')
with open(changed_path, 'wb') as f:
f.write(b'new line')
# 2. update the existing file
changed_path1 = os.path.join(
self.tmp_root_path,
b'sample-folder/bar/barfoo/another-quote.org')
with open(changed_path1, 'wb') as f:
f.write(b'new line')
# 3. Remove some folder
changed_path2 = os.path.join(self.tmp_root_path,
b'sample-folder/foo')
# 3. Remove some folder
changed_path2 = os.path.join(self.tmp_root_path,
b'sample-folder/bar/barfoo')
shutil.rmtree(changed_path2)
# Actually walking the fs will be the resulting expectation
expected_dict = git.walk_and_compute_sha1_from_directory(
self.tmp_root_path)
# then
actual_dict = git.update_checksums_from(
[{'path': changed_path, 'action': 'A'},
{'path': changed_path1, 'action': 'M'},
{'path': changed_path2, 'action': 'D'}],
objects)
self.assertEquals(expected_dict, actual_dict)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment