Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Dandrimont
swh-model
Commits
cd881639
Commit
cd881639
authored
9 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
Detect if we need to recompute all from disk anyway (change at the root
level for example)
parent
02e23573
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/model/git.py
+15
-10
15 additions, 10 deletions
swh/model/git.py
swh/model/tests/test_git.py
+43
-0
43 additions, 0 deletions
swh/model/tests/test_git.py
with
58 additions
and
10 deletions
swh/model/git.py
+
15
−
10
View file @
cd881639
...
...
@@ -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
This diff is collapsed.
Click to expand it.
swh/model/tests/test_git.py
+
43
−
0
View file @
cd881639
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment