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
Renaud Boyer
swh-model
Commits
1f98c67f
Verified
Commit
1f98c67f
authored
8 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
Add optional clean up round-trip to remove empty folders
parent
ca235a08
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/model/git.py
+29
-8
29 additions, 8 deletions
swh/model/git.py
swh/model/tests/test_git.py
+1
-0
1 addition, 0 deletions
swh/model/tests/test_git.py
with
30 additions
and
8 deletions
swh/model/git.py
+
29
−
8
View file @
1f98c67f
...
...
@@ -188,7 +188,8 @@ def compute_tree_metadata(dirname, ls_hashes):
def
walk_and_compute_sha1_from_directory
(
rootdir
,
dir_ok_fn
=
lambda
dirpath
:
True
,
with_root_tree
=
True
):
with_root_tree
=
True
,
remove_empty_folder
=
False
):
"""
Compute git sha1 from directory rootdir.
Args:
...
...
@@ -232,6 +233,17 @@ def walk_and_compute_sha1_from_directory(rootdir,
dirname
)),
dirnames
))
if
remove_empty_folder
:
# round-trip to remove empty folders
gen_dir
=
((
dp
,
filtfn
(
dp
,
dns
),
fns
)
for
(
dp
,
dns
,
fns
)
in
os
.
walk
(
rootdir
,
topdown
=
False
)
if
dir_ok_fn
(
dp
))
for
dirpath
,
dirnames
,
filenames
in
gen_dir
:
if
dirnames
==
[]
and
filenames
==
[]:
if
os
.
path
.
islink
(
dirpath
):
os
.
remove
(
dirpath
)
else
:
os
.
removedirs
(
dirpath
)
gen_dir
=
((
dp
,
filtfn
(
dp
,
dns
),
fns
)
for
(
dp
,
dns
,
fns
)
in
os
.
walk
(
rootdir
,
topdown
=
False
)
if
dir_ok_fn
(
dp
))
...
...
@@ -429,7 +441,8 @@ def __remove_paths_from_objects(objects, rootpaths,
def
update_checksums_from
(
changed_paths
,
objects
,
dir_ok_fn
=
lambda
dirpath
:
True
):
dir_ok_fn
=
lambda
dirpath
:
True
,
remove_empty_folder
=
False
):
"""
Given a list of changed paths, recompute the checksums only where
needed.
...
...
@@ -459,7 +472,10 @@ def update_checksums_from(changed_paths, objects,
parent
=
os
.
path
.
dirname
(
path
)
if
parent
==
root
:
# ... recompute everything anyway
return
walk_and_compute_sha1_from_directory
(
root
,
dir_ok_fn
)
return
walk_and_compute_sha1_from_directory
(
root
,
dir_ok_fn
=
dir_ok_fn
,
remove_empty_folder
=
remove_empty_folder
)
if
changed_path
[
'
action
'
]
==
'
D
'
:
# (D)elete
paths_to_remove
.
add
(
path
)
...
...
@@ -484,11 +500,16 @@ def update_checksums_from(changed_paths, objects,
# rootdir no longer exists, recompute all
# folder could have been previously ignored
# (e.g. in svn case with ignore flag activated)
return
walk_and_compute_sha1_from_directory
(
root
,
dir_ok_fn
)
hashes
=
walk_and_compute_sha1_from_directory
(
rootdir
,
dir_ok_fn
,
with_root_tree
=
False
)
return
walk_and_compute_sha1_from_directory
(
root
,
dir_ok_fn
=
dir_ok_fn
,
remove_empty_folder
=
remove_empty_folder
)
hashes
=
walk_and_compute_sha1_from_directory
(
rootdir
,
dir_ok_fn
=
dir_ok_fn
,
with_root_tree
=
False
,
remove_empty_folder
=
remove_empty_folder
)
# Then update the original objects with new
# checksums for the arborescence tree below rootdir
...
...
This diff is collapsed.
Click to expand it.
swh/model/tests/test_git.py
+
1
−
0
View file @
1f98c67f
...
...
@@ -146,6 +146,7 @@ class GitHashWalkArborescenceTree(unittest.TestCase):
"""
def
setUp
(
self
):
self
.
tmp_root_path
=
tempfile
.
mkdtemp
().
encode
(
'
utf-8
'
)
self
.
maxDiff
=
None
start_path
=
os
.
path
.
dirname
(
__file__
).
encode
(
'
utf-8
'
)
pkg_doc_linux_r11
=
os
.
path
.
join
(
start_path
,
...
...
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