Hi Jonas,
On Mon, Oct 31, 2016 at 03:21:46PM +0100, Jonas Meurer wrote:
> Hi Guido,
> 
> Am 31.10.2016 um 11:21 schrieb Guido Günther:
> >> See attached patch which implements basic version mangling for
> >> '--git-upstream-tag' in a simple substitute fashion: if the provided
> >> format contains the syntax '%(version%OLD%NEW)s', then the version used
> >> for '%(version)s' has 'OLD' replaced by 'NEW'.
> >>
> >> This allows us to let gbp create the upstream tarball from upstream Git
> >> release tag for new releases:
> >>
> >> $ gbp buildpackage --git-upstream-tag="v%(version%.%_)s"
> >>
> >>
> >> In case that you like the approach and agree to add this feature to gbp,
> >> I could write a few corresponding words for the related paragraphs of
> >> gbp documentation.
> >>
> >> If you're not happy with the way it's implmented, just let me know why
> >> and we can search for a better solution :)
> > 
> > The general approach is fine. Thanks for the patch. See my comments below:
> 
> Great :) I  tried to address your comments, see below.
> 
> >> commit f6a7e8f83935d74dc0cd67a5afa26b243357d04f
> >> Author: Jonas Meurer <jo...@freesources.org>
> >> Date:   Sun Oct 30 23:44:34 2016 +0100
> >>
> >>     gbp/deb/git.py: add basic version mangling to version_to_tag()
> >>
> >> diff --git a/gbp/deb/git.py b/gbp/deb/git.py
> >> index 64cd321..3070d93 100644
> >> --- a/gbp/deb/git.py
> >> +++ b/gbp/deb/git.py
> >> @@ -142,12 +142,18 @@ class DebianGitRepository(GitRepository):
> >>          hversion is useful for upstreams with tagging policies that 
> >> prohibit .
> >>          characters.
> >>  
> >> +        %(version%A%B)s provides %(version)s with 'A' replaced by 'B'.
> >> +
> > 
> > Please add tests using docstrings as below (including one that show how
> > to use '%' as a replacement (e.g. 0-1.2.3 -> 0%1.2.3.4 and as replaced
> > pattern 0%1%2%3 -> 0.1.2.3).
> 
> Done.
> 
> >>          >>> DebianGitRepository.version_to_tag("debian/%(version)s", 
> >> "0:0~0")
> >>          'debian/0%0_0'
> >>          >>> DebianGitRepository.version_to_tag("libfoo-%(hversion)s", 
> >> "1.8.1")
> >>          'libfoo-1-8-1'
> >>  
> >>          """
> >> +        r = re.search(r"\%\(version\%([^%s]+)\%([^\%]+)\)s", format)
> >> +        if r:
> >> +            format = re.sub(r"\%\(version\%[^%s]+\%[^\%]+\)s", 
> >> "%(version)s", format)
> >> +            version = version.replace(r.group(1), r.group(2))
> >>          return format_str(format, 
> >> dict(version=DebianGitRepository._sanitize_version(version),
> >>                                         
> >> hversion=DebianGitRepository._sanitize_version(version).replace('.', '-')))
> >>  
> > 
> > Please document the behaviour. The current place that has the most
> > information on how to modify the upstream version is in
> > 
> >      docs/chapters/import.sgml
> 
> Done.
> 
> See the attached updated patch.
> 
> Cheers,
>  jonas
> 

> commit ede717317785e17dfe8bf65ffd833e23295c8b7d
> Author: Jonas Meurer <jo...@freesources.org>
> Date:   Mon Oct 31 15:08:31 2016 +0100
> 
>     buildpackage: add basic version mangling to upstream tag format
> 
> diff --git a/debian/changelog b/debian/changelog
> index fce657d..41095ed 100644
> --- a/debian/changelog
> +++ b/debian/changelog
> @@ -1,3 +1,11 @@
> +git-buildpackage (0.8.6+nmu1) UNRELEASED; urgency=medium
> +
> +  * Non-maintainer upload.
> +  * buildpackage: add basic version mangling to upstream tag format.
> +    (Closes: #842638)
> +
> + -- Jonas Meurer <m...@debian.org>  Mon, 31 Oct 2016 14:38:11 +0100
> +
>  git-buildpackage (0.8.6) unstable; urgency=medium
>  
>    * [a35d7d6] buildpackage: handle <vendor>/master
> diff --git a/docs/chapters/import.sgml b/docs/chapters/import.sgml
> index e58cca9..559a14a 100644
> --- a/docs/chapters/import.sgml
> +++ b/docs/chapters/import.sgml
> @@ -260,6 +260,31 @@ upstream-tag = v%(version)s
>       </para>
>  
>       <sect3>
> +       <title>Upstream tag version mangling</title>
> +     <para>
> +       Since version 0.8.7, &gbp-buildpackage; supports basic version 
> mangling for upstream tags via
> +       substitution. The substitution syntax is as follows:
> +     </para>
> +<programlisting>
> +[git-buildpackage]
> +upstream-tag = v%(version%A%B)s
> +</programlisting>
> +     <para>
> +       In this example, each occurrence of <replaceable>A</replaceable> will 
> be replaced by <replaceable>B</replaceable>
> +       in the upstream version number. An occasional upstream format is to 
> use tag <replaceable>v1_2_3</replaceable>
> +       for release <replaceable>1.2.3</replaceable>. Use 
> <replaceable>v%(version%.%_)s</replaceable> to transform
> +       <replaceable>1.2.3</replaceable> into 
> <replaceable>v1_2_3</replaceable>.
> +     </para>
> +     <para>
> +       If you need to use the <replaceable>%</replaceable> character in 
> either of the substitution strings,
> +       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>.
> +       <replaceable>%(version%\%%.)s</replaceable> on the other hand will 
> replace <replaceable>%</replaceable> with
> +       <replaceable>.</replaceable>, turning 
> <replaceable>X%Y%Z</replaceable> into <replaceable>X.Y.Z</replaceable>.
> +     </para>
> +     </sect3>
> +
> +     <sect3>
>         <title>Step by step</title>
>       <para>To not make any assumptions about &gbp;'s configuration, the 
> following steps have all options given
>         in its long versions on the command line. You can add these
> diff --git a/gbp/deb/git.py b/gbp/deb/git.py
> index 64cd321..02c7c28 100644
> --- a/gbp/deb/git.py
> +++ b/gbp/deb/git.py
> @@ -142,12 +142,26 @@ class DebianGitRepository(GitRepository):
>          hversion is useful for upstreams with tagging policies that prohibit 
> .
>          characters.
>  
> +        %(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
> +        examples below.
> +
>          >>> DebianGitRepository.version_to_tag("debian/%(version)s", "0:0~0")
>          'debian/0%0_0'
>          >>> DebianGitRepository.version_to_tag("libfoo-%(hversion)s", 
> "1.8.1")
>          'libfoo-1-8-1'
> -
> -        """
> +        >>> DebianGitRepository.version_to_tag("v%(version%.%_)s", "1.2.3")
> +        '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)
> +        if r:
> +            format = 
> re.sub(r"%\(version%([^%]+|.*\\%.*)%([^%]|.*\\%.*)+\)s", "%(version)s", 
> format)
> +            version = version.replace(r.group(1).replace('\%', '%'), 
> r.group(2).replace('\%', '%'))
>          return format_str(format, 
> dict(version=DebianGitRepository._sanitize_version(version),
>                                         
> hversion=DebianGitRepository._sanitize_version(version).replace('.', '-')))
>  

Applied now. Thanks!
 -- Guido

Reply via email to