Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
klaus
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
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
GitHub Mirror
jonashaag
klaus
Commits
39cd6077
Commit
39cd6077
authored
6 years ago
by
Jonas Haag
Browse files
Options
Downloads
Patches
Plain Diff
Tarball names: Account for 'v[a-z]+', refactoring
parent
fc9601d4
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
klaus/utils.py
+25
-18
25 additions, 18 deletions
klaus/utils.py
tests/test_utils.py
+1
-0
1 addition, 0 deletions
tests/test_utils.py
with
26 additions
and
18 deletions
klaus/utils.py
+
25
−
18
View file @
39cd6077
...
...
@@ -170,8 +170,18 @@ def extract_author_name(email):
return
email
def
is_hex_prefix
(
s
):
if
len
(
s
)
%
2
:
s
+=
'
0
'
try
:
binascii
.
unhexlify
(
s
)
return
True
except
binascii
.
Error
:
return
False
def
shorten_sha1
(
sha1
):
if
re
.
match
(
r
'
[a-z\d]{20,40}
'
,
sha1
):
if
20
<=
len
(
sha1
)
<=
40
and
is_hex_prefix
(
sha1
):
sha1
=
sha1
[:
7
]
return
sha1
...
...
@@ -212,8 +222,6 @@ def replace_dupes(ls, replacement):
last
=
elem
def
guess_git_revision
():
"""
Try to guess whether this instance of klaus is run directly from a klaus
git checkout. If it is, guess and return the currently checked-out commit
...
...
@@ -247,18 +255,17 @@ def escape_html(s):
def
tarball_basename
(
repo_name
,
rev
):
"""
Determine the name for a tarball.
"""
sanitized_rev
=
sanitize_branch_name
(
rev
,
chars
=
'
/
'
)
# If the rev is a tag name that already starts with the
# repo name, skip it.
if
sanitized_rev
.
startswith
(
repo_name
+
'
-
'
):
return
sanitized_rev
if
sanitized_rev
.
startswith
(
'
v
'
):
return
"
%s-%s
"
%
(
repo_name
,
sanitized_rev
[
1
:])
if
len
(
sanitized_rev
)
==
40
:
try
:
binascii
.
unhexlify
(
sanitized_rev
)
except
binascii
.
Error
:
pass
else
:
return
"
%s@%s
"
%
(
repo_name
,
sanitized_rev
)
return
"
%s-%s
"
%
(
repo_name
,
sanitized_rev
)
rev
=
sanitize_branch_name
(
rev
,
chars
=
'
/
'
)
if
rev
.
startswith
(
repo_name
+
'
-
'
):
# If the rev is a tag name that already starts with the repo name,
# skip it.
return
rev
elif
len
(
rev
)
>=
2
and
rev
[
0
]
==
'
v
'
and
not
rev
[
1
].
isalpha
():
# If the rev is a tag name prefixed by a 'v', skip the 'v'.
# So, v-1.0 -> 1.0, v1.0 -> 1.0, but vanilla -> vanilla.
return
"
%s-%s
"
%
(
repo_name
,
rev
[
1
:])
elif
len
(
rev
)
==
40
and
is_hex_prefix
(
rev
):
# If the rev is a commit hash, simply use that.
return
"
%s@%s
"
%
(
repo_name
,
rev
)
else
:
return
"
%s-%s
"
%
(
repo_name
,
rev
)
This diff is collapsed.
Click to expand it.
tests/test_utils.py
+
1
−
0
View file @
39cd6077
...
...
@@ -30,6 +30,7 @@ class TarballBasenameTests(unittest.TestCase):
(
'
0.1
'
,
'
klaus-0.1
'
),
(
'
b3e70e08344ca3f83cc7033ecdbefa90443d7d2e
'
,
'
klaus@b3e70e08344ca3f83cc7033ecdbefa90443d7d2e
'
),
(
'
vanilla
'
,
'
klaus-vanilla
'
),
]
for
(
rev
,
basename
)
in
examples
:
self
.
assertEqual
(
utils
.
tarball_basename
(
'
klaus
'
,
rev
),
basename
)
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