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
05ac3c40
Verified
Commit
05ac3c40
authored
8 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
Remove dead code
parent
8d2bf5a4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/model/git.py
+0
-231
0 additions, 231 deletions
swh/model/git.py
swh/model/tests/test_git.py
+0
-483
0 additions, 483 deletions
swh/model/tests/test_git.py
with
0 additions
and
714 deletions
swh/model/git.py
+
0
−
231
View file @
05ac3c40
...
...
@@ -530,237 +530,6 @@ def compute_hashes_from_directory(rootdir,
return
ls_hashes
def
recompute_sha1_in_memory
(
root
,
deeper_rootdir
,
objects
):
"""
TODO: Use git.walk_and_compute_sha1_from_directory_2
Recompute git sha1 from directory deeper_rootdir to root.
This function relies exclusively on `objects` for hashes. It
expects the deeper_rootdir and every key below that path to be
already updated.
Args:
- root: Upper root directory (so same as
objects[ROOT_TREE_KEY][0][
'
path
'
])
- deeper_rootdir: Upper root directory from which the git hash
computation has alredy been updated.
- objects: objects dictionary as per returned by
`walk_and_compute_sha1_from_directory`
Returns:
Dictionary of entries with keys <path-name> and as values a list of
directory entries.
Those are list of dictionary with keys:
-
'
perms
'
-
'
type
'
-
'
name
'
-
'
sha1_git
'
- and specifically content:
'
sha1
'
,
'
sha256
'
, ...
Note:
One special key is ROOT_TREE_KEY to indicate the upper root of the
directory (this is the revision
'
s target directory).
Raises:
Nothing
If something is raised, this is a programmatic error.
"""
# list of paths to update from bottom to top
upper_root
=
os
.
path
.
dirname
(
root
)
rootdir
=
os
.
path
.
dirname
(
deeper_rootdir
)
while
rootdir
!=
upper_root
:
files
=
objects
[
rootdir
]
ls_hashes
=
[]
for
hashfile
in
files
:
fulldirname
=
hashfile
[
'
path
'
]
if
hashfile
[
'
type
'
]
==
GitType
.
TREE
:
tree_hash
=
compute_tree_metadata
(
fulldirname
,
objects
)
ls_hashes
.
append
(
tree_hash
)
else
:
ls_hashes
.
append
(
hashfile
)
objects
[
rootdir
]
=
ls_hashes
parent
=
os
.
path
.
dirname
(
rootdir
)
rootdir
=
parent
# update root
root_tree_hash
=
compute_directory_git_sha1
(
root
,
objects
)
objects
[
ROOT_TREE_KEY
][
0
][
'
sha1_git
'
]
=
root_tree_hash
return
objects
def
commonpath
(
paths
):
"""
Given a sequence of path names, returns the longest common sub-path.
Copied from Python3.5
"""
if
not
paths
:
raise
ValueError
(
'
commonpath() arg is an empty sequence
'
)
if
isinstance
(
paths
[
0
],
bytes
):
sep
=
b
'
/
'
curdir
=
b
'
.
'
else
:
sep
=
'
/
'
curdir
=
'
.
'
try
:
split_paths
=
[
path
.
split
(
sep
)
for
path
in
paths
]
try
:
isabs
,
=
set
(
p
[:
1
]
==
sep
for
p
in
paths
)
except
ValueError
:
raise
ValueError
(
"
Can
'
t mix absolute and relative paths
"
)
split_paths
=
[
[
c
for
c
in
s
if
c
and
c
!=
curdir
]
for
s
in
split_paths
]
s1
=
min
(
split_paths
)
s2
=
max
(
split_paths
)
common
=
s1
for
i
,
c
in
enumerate
(
s1
):
if
c
!=
s2
[
i
]:
common
=
s1
[:
i
]
break
prefix
=
sep
if
isabs
else
sep
[:
0
]
return
prefix
+
sep
.
join
(
common
)
except
(
TypeError
,
AttributeError
):
raise
def
__remove_paths_from_objects
(
objects
,
rootpaths
,
dir_ok_fn
=
default_validation_dir
):
"""
Given top paths to remove, remove all paths and descendants from
objects.
Args:
objects: The dictionary of paths to clean up.
rootpaths: The rootpaths to remove from objects.
- dir_ok_fn: Validation function on folder/file names.
Default to accept all.
Returns:
Objects dictionary without the rootpaths and their descendants.
"""
dirpaths_to_clean
=
set
()
for
path
in
rootpaths
:
path_list
=
objects
.
pop
(
path
,
None
)
if
path_list
:
# need to remove the children directories too
for
child
in
path_list
:
if
child
[
'
type
'
]
==
GitType
.
TREE
:
dirpaths_to_clean
.
add
(
child
[
'
path
'
])
parent
=
os
.
path
.
dirname
(
path
)
# Is the parent still ok? (e.g. not an empty dir for example)
parent_check
=
dir_ok_fn
(
parent
)
if
not
parent_check
and
parent
not
in
dirpaths_to_clean
:
dirpaths_to_clean
.
add
(
parent
)
else
:
# we need to pop the reference to path in the parent list
if
objects
.
get
(
parent
):
objects
[
parent
]
=
filter
(
lambda
p
:
p
!=
path
,
objects
.
get
(
parent
,
[]))
if
dirpaths_to_clean
:
objects
=
__remove_paths_from_objects
(
objects
,
dirpaths_to_clean
,
dir_ok_fn
)
return
objects
def
update_checksums_from
(
changed_paths
,
objects
,
dir_ok_fn
=
default_validation_dir
,
remove_empty_folder
=
False
):
"""
Given a list of changed paths, recompute the checksums only where
needed.
Args:
changed_paths: Dictionary list representing path changes.
A dictionary has the form:
- path: the full path to the file Added, Modified or Deleted
- action: A, M or D
objects: dictionary returned by `walk_and_compute_sha1_from_directory`.
- dir_ok_fn: Validation function on folder/file names.
Default to accept all.
Returns:
Dictionary returned by `walk_and_compute_sha1_from_directory`
updated (mutated) according to latest filesystem modifications.
"""
root
=
objects
[
ROOT_TREE_KEY
][
0
][
'
path
'
]
if
root
.
endswith
(
b
'
/
'
):
root
=
root
.
rstrip
(
b
'
/
'
)
paths
=
set
()
# contain the list of impacted paths (A, D, M)
paths_to_remove
=
set
()
# will contain the list of deletion paths (only D)
# a first round-trip to ensure we don't need to...
for
changed_path
in
changed_paths
:
path
=
changed_path
[
'
path
'
]
parent
=
os
.
path
.
dirname
(
path
)
if
parent
==
root
:
# ... recompute everything anyway
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
)
paths
.
add
(
parent
)
# no modification on paths (paths also contain deletion paths if any)
if
not
paths
:
return
objects
rootdir
=
commonpath
(
list
(
paths
))
if
paths_to_remove
:
# Now we can remove the deleted directories from objects dictionary
objects
=
__remove_paths_from_objects
(
objects
,
paths_to_remove
,
dir_ok_fn
)
# Recompute from disk the checksums from impacted common ancestor
# rootdir changes.
while
not
objects
.
get
(
rootdir
,
None
):
# it could happened that the path is not found.
# In the case of an ignored folder for example.
# So we'll find the next existing parent
rootdir
=
os
.
path
.
dirname
(
rootdir
)
if
rootdir
==
root
:
# fallback, if we hit root, walk
# everything anyway
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
objects
.
update
(
hashes
)
# Recompute hashes in memory from rootdir to root
return
recompute_sha1_in_memory
(
root
,
rootdir
,
objects
)
def
objects_per_type
(
filter_type
,
objects_per_path
):
"""
Given an object dictionary returned by
`swh.model.git.compute_hashes_from_directory`, yields
...
...
This diff is collapsed.
Click to expand it.
swh/model/tests/test_git.py
+
0
−
483
View file @
05ac3c40
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