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
02e23573
Commit
02e23573
authored
9 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
Only compute root_tree_key's directory hash when needed
parent
cdf2b709
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/model/git.py
+19
-13
19 additions, 13 deletions
swh/model/git.py
swh/model/tests/test_git.py
+16
-0
16 additions, 0 deletions
swh/model/tests/test_git.py
with
35 additions
and
13 deletions
swh/model/git.py
+
19
−
13
View file @
02e23573
...
...
@@ -187,7 +187,8 @@ def compute_tree_metadata(dirname, ls_hashes):
def
walk_and_compute_sha1_from_directory
(
rootdir
,
dir_ok_fn
=
lambda
dirpath
:
True
):
dir_ok_fn
=
lambda
dirpath
:
True
,
with_root_tree
=
True
):
"""
Compute git sha1 from directory rootdir.
Args:
...
...
@@ -197,6 +198,10 @@ def walk_and_compute_sha1_from_directory(rootdir,
defined in the function. By default, all folders are ok.
Example override: dir_ok_fn = lambda dirpath: b
'
svn
'
not in dirpath
- with_root_tree: Determine if we compute the upper root tree
'
s
checksums. As a default, we want it. One possible use case where this
is not useful is the update (cf. `update_checksums_from`)
Returns:
Dictionary of entries with keys <path-name> and as values a list of
directory entries.
...
...
@@ -260,15 +265,16 @@ def walk_and_compute_sha1_from_directory(rootdir,
ls_hashes
[
dirpath
].
extend
(
dir_hashes
)
# compute the current directory hashes
root_hash
=
{
'
sha1_git
'
:
compute_directory_git_sha1
(
rootdir
,
ls_hashes
),
'
path
'
:
rootdir
,
'
name
'
:
os
.
path
.
basename
(
rootdir
),
'
perms
'
:
GitPerm
.
TREE
,
'
type
'
:
GitType
.
TREE
}
ls_hashes
[
ROOT_TREE_KEY
]
=
[
root_hash
]
if
with_root_tree
:
# compute the current directory hashes
root_hash
=
{
'
sha1_git
'
:
compute_directory_git_sha1
(
rootdir
,
ls_hashes
),
'
path
'
:
rootdir
,
'
name
'
:
os
.
path
.
basename
(
rootdir
),
'
perms
'
:
GitPerm
.
TREE
,
'
type
'
:
GitType
.
TREE
}
ls_hashes
[
ROOT_TREE_KEY
]
=
[
root_hash
]
return
ls_hashes
...
...
@@ -371,11 +377,11 @@ def update_checksums_from(changed_paths, objects,
continue
# recompute from disk the checksums
hashes
=
walk_and_compute_sha1_from_directory
(
rootdir
,
dir_ok_fn
)
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
for
d
in
(
k
for
k
in
hashes
.
keys
()
if
k
!=
ROOT_TREE_KEY
):
objects
[
d
]
=
hashes
[
d
]
objects
.
update
(
hashes
)
# now recompute the hashes in memory from deeper_rootdir to root
objects
=
recompute_sha1_in_memory
(
root
,
rootdir
,
objects
)
...
...
This diff is collapsed.
Click to expand it.
swh/model/tests/test_git.py
+
16
−
0
View file @
02e23573
...
...
@@ -216,6 +216,22 @@ class GitHashArborescenceTree(unittest.TestCase):
self
.
assertEquals
(
actual_walk1
,
expected_checksums
)
@istest
def
walk_and_compute_sha1_from_directory_without_root_tree
(
self
):
# compute the full checksums
expected_hashes
=
git
.
walk_and_compute_sha1_from_directory
(
self
.
tmp_root_path
)
# except for the key on that round
actual_hashes
=
git
.
walk_and_compute_sha1_from_directory
(
self
.
tmp_root_path
,
with_root_tree
=
False
)
# then, removing the root tree hash from the first round
del
expected_hashes
[
git
.
ROOT_TREE_KEY
]
# should give us the same checksums as the second round
self
.
assertEquals
(
actual_hashes
,
expected_hashes
)
class
GitHashUpdate
(
GitHashArborescenceTree
):
...
...
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