aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-11-16 14:12:18 +0100
committerGuido Günther <agx@sigxcpu.org>2016-11-16 14:12:18 +0100
commitd360a6d92d744762f9f13555ed03726b6d4ba937 (patch)
tree39b9b22170ea5a0ba69fb6f279136c6a936211b6
parent420e2996bc572e41c78dec5e3762089fbbb551f9 (diff)
DebianGitRepository: simplify version mangling
'%' is not valid in a Debian version number and we only want single character replacements for now.
-rw-r--r--docs/chapters/import.sgml8
-rw-r--r--gbp/deb/git.py19
2 files changed, 16 insertions, 11 deletions
diff --git a/docs/chapters/import.sgml b/docs/chapters/import.sgml
index 89d15b83..c42279c9 100644
--- a/docs/chapters/import.sgml
+++ b/docs/chapters/import.sgml
@@ -274,8 +274,9 @@ upstream-tag = v%(version)s
numbers by dots but rather by
underscore(<replaceable>_</replaceable>),
hyphen(<replaceable>-</replaceable>) or anything else. In
- order to cope with that you can use version mangling via
- substitution. The substitution works as follows:
+ order to cope with that you can use version mangling of these
+ characters via substitution. The substitution works as
+ follows:
</para>
<programlisting>
[buildpackage]
@@ -292,9 +293,10 @@ upstream-tag = v%(version%.%_)s
&gbp-buildpackage;.
</para>
<para>
- If you need to use the <replaceable>%</replaceable> character in either of the substitution strings,
+ If you want the substitution to be the <replaceable>%</replaceable> character
you have to escape it. E.g. <replaceable>%(version%-%\%)s</replaceable> will replace <replaceable>-</replaceable> with
<replaceable>%</replaceable>, transforming <replaceable>1-A.B.C</replaceable> to <replaceable>1%A.B.C</replaceable>.
+ Only a single replacement is supported and it can only replace a single character.
</para>
<para>If you're using &pristine-tar;, you can make &gbp-buildpackage; commit the generated tarball back to the
diff --git a/gbp/deb/git.py b/gbp/deb/git.py
index 80fb23b7..fea919d9 100644
--- a/gbp/deb/git.py
+++ b/gbp/deb/git.py
@@ -27,6 +27,11 @@ import gbp.log
class DebianGitRepository(GitRepository):
"""A git repository that holds the source of a Debian package"""
+ version_mangle_re = (r'%\(version'
+ '%(?P<M>[^%])'
+ '%(?P<R>([^%]|\\%))+'
+ '\)s')
+
def __init__(self, path):
super(DebianGitRepository, self).__init__(path)
self.pristine_tar = DebianPristineTar(self)
@@ -132,8 +137,8 @@ class DebianGitRepository(GitRepository):
version = version.replace('~', '.')
return format % dict(version=version)
- @staticmethod
- def version_to_tag(format, version):
+ @classmethod
+ def version_to_tag(cls, format, version):
"""Generate a tag from a given format and a version
%(version)s provides a clean version that works as a git tag.
@@ -144,7 +149,7 @@ class DebianGitRepository(GitRepository):
%(version%A%B)s provides %(version)s with string 'A' replaced by 'B'.
This way, simple version mangling is possible via substitution.
- Inside either substition string, '%' needs to be escaped. See the
+ Inside the substition string, '%' needs to be escaped. See the
examples below.
>>> DebianGitRepository.version_to_tag("debian/%(version)s", "0:0~0")
@@ -155,13 +160,11 @@ class DebianGitRepository(GitRepository):
'v1_2_3'
>>> DebianGitRepository.version_to_tag("%(version%-%\%)s", "0-1.2.3")
'0%1.2.3'
- >>> DebianGitRepository.version_to_tag("%(version%\%%.)s", "0%1%2%3")
- '0.1.2.3'
"""
- r = re.search(r"%\(version%([^%]+|.*\\%.*)%([^%]+|.*\\%.*)\)s", format)
+ r = re.search(cls.version_mangle_re, format)
if r:
- format = re.sub(r"%\(version%([^%]+|.*\\%.*)%([^%]|.*\\%.*)+\)s", "%(version)s", format)
- version = version.replace(r.group(1).replace('\%', '%'), r.group(2).replace('\%', '%'))
+ format = re.sub(cls.version_mangle_re, "%(version)s", format)
+ version = version.replace(r.group('M'), r.group('R').replace('\%', '%'))
return format_str(format, dict(version=DebianGitRepository._sanitize_version(version),
hversion=DebianGitRepository._sanitize_version(version).replace('.', '-')))