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
e09446a6
Commit
e09446a6
authored
3 years ago
by
Daniele Serafini
Browse files
Options
Downloads
Patches
Plain Diff
encode exclude patterns before extracting regex objects
- add typing annotation to avoid such error in the future Fixes T3383
parent
8ec0cf68
No related branches found
Branches containing commit
Tags
v2.6.1
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/model/cli.py
+10
-7
10 additions, 7 deletions
swh/model/cli.py
with
10 additions
and
7 deletions
swh/model/cli.py
+
10
−
7
View file @
e09446a6
...
...
@@ -5,7 +5,7 @@
import
os
import
sys
from
typing
import
Dict
,
List
,
Optional
from
typing
import
Dict
,
Iterable
,
Optional
# WARNING: do not import unnecessary things here to keep cli startup time under
# control
...
...
@@ -75,7 +75,7 @@ def swhid_of_file_content(data) -> CoreSWHID:
)
def
model_of_dir
(
path
:
bytes
,
exclude_patterns
:
List
[
bytes
]
=
None
)
->
Directory
:
def
model_of_dir
(
path
:
bytes
,
exclude_patterns
:
Iterable
[
bytes
]
=
None
)
->
Directory
:
from
swh.model.from_disk
import
accept_all_directories
,
ignore_directories_patterns
dir_filter
=
(
...
...
@@ -87,7 +87,7 @@ def model_of_dir(path: bytes, exclude_patterns: List[bytes] = None) -> Directory
return
Directory
.
from_disk
(
path
=
path
,
dir_filter
=
dir_filter
)
def
swhid_of_dir
(
path
:
bytes
,
exclude_patterns
:
List
[
bytes
]
=
None
)
->
CoreSWHID
:
def
swhid_of_dir
(
path
:
bytes
,
exclude_patterns
:
Iterable
[
bytes
]
=
None
)
->
CoreSWHID
:
from
swh.model.hashutil
import
hash_to_bytes
obj
=
model_of_dir
(
path
,
exclude_patterns
)
...
...
@@ -150,7 +150,9 @@ def swhid_of_git_repo(path) -> CoreSWHID:
)
def
identify_object
(
obj_type
,
follow_symlinks
,
exclude_patterns
,
obj
)
->
str
:
def
identify_object
(
obj_type
:
str
,
follow_symlinks
:
bool
,
exclude_patterns
:
Iterable
[
bytes
],
obj
)
->
str
:
from
urllib.parse
import
urlparse
if
obj_type
==
"
auto
"
:
...
...
@@ -177,9 +179,7 @@ def identify_object(obj_type, follow_symlinks, exclude_patterns, obj) -> str:
if
obj_type
==
"
content
"
:
swhid
=
str
(
swhid_of_file
(
path
))
elif
obj_type
==
"
directory
"
:
swhid
=
str
(
swhid_of_dir
(
path
,
[
pattern
.
encode
()
for
pattern
in
exclude_patterns
])
)
swhid
=
str
(
swhid_of_dir
(
path
,
exclude_patterns
))
elif
obj_type
==
"
origin
"
:
swhid
=
str
(
swhid_of_origin
(
obj
))
elif
obj_type
==
"
snapshot
"
:
...
...
@@ -275,6 +275,9 @@ def identify(
from
functools
import
partial
import
logging
if
exclude_patterns
:
exclude_patterns
=
set
(
pattern
.
encode
()
for
pattern
in
exclude_patterns
)
if
verify
and
len
(
objects
)
!=
1
:
raise
click
.
BadParameter
(
"
verification requires a single object
"
)
...
...
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