summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2010-08-12 22:06:32 +0200
committerGuido Günther <agx@sigxcpu.org>2010-08-12 22:41:39 +0200
commit8d33c923d5e339802118d92a6df7227c0fc09f8e (patch)
tree996f09c852c508ee3db3b287ada8bb1e91b6992b
parent5e3c9d09b0e757f4ae68f82e9c2586c97a6ffbe9 (diff)
downloadgit-buildpackage-8d33c923d5e339802118d92a6df7227c0fc09f8e.tar.gz
git-buildpackage-8d33c923d5e339802118d92a6df7227c0fc09f8e.tar.bz2
git-buildpackage-8d33c923d5e339802118d92a6df7227c0fc09f8e.zip
Guess changelog version number from upstream version
-rw-r--r--gbp/git.py29
-rwxr-xr-xgit-dch33
2 files changed, 54 insertions, 8 deletions
diff --git a/gbp/git.py b/gbp/git.py
index b162bc0d..350f5165 100644
--- a/gbp/git.py
+++ b/gbp/git.py
@@ -3,6 +3,7 @@
# (C) 2006,2007,2008 Guido Guenther <agx@sigxcpu.org>
"""provides git repository related helpers"""
+import re
import subprocess
import os.path
from command_wrappers import (GitAdd, GitRm, GitCheckoutBranch, GitInit, GitCommand, copy_from)
@@ -253,11 +254,16 @@ class GitRepository(object):
raise GitRepositoryError, "Error getting subject of commit %s" % commit
return out[0].strip()
- def find_tag(self, branch):
+ def find_tag(self, commit, pattern=None):
"find the closest tag to a branch's head"
- tag, ret = self.__git_getoutput('describe', [ "--abbrev=0", branch ])
+ args = [ '--abbrev=0' ]
+ if pattern:
+ args += [ '--match' , pattern ]
+ args += [ commit ]
+
+ tag, ret = self.__git_getoutput('describe', args)
if ret:
- raise GitRepositoryError, "can't find tag for %s" % branch
+ raise GitRepositoryError, "can't find tag for %s" % commit
return tag[0].strip()
def rev_parse(self, name):
@@ -493,6 +499,23 @@ def __sanitize_version(version):
return version.replace('~', '_').replace(':', '%')
+def tag_to_version(tag, format):
+ """Extract the version from a tag
+ >>> tag_to_version("upstream/1%2_3-4", "upstream/%(version)s")
+ '1:2~3-4'
+ >>> tag_to_version("foo/2.3.4", "foo/%(version)s")
+ '2.3.4'
+ >>> tag_to_version("foo/2.3.4", "upstream/%(version)s")
+ """
+ version_re = format.replace('%(version)s',
+ '(?P<version>[\w_%+-.]+)')
+ r = re.match(version_re, tag)
+ if r:
+ version = r.group('version').replace('_', '~').replace('%', ':')
+ return version
+ return None
+
+
def rfc822_date_to_git(rfc822_date):
"""Parse a date in RFC822 format, and convert to a 'seconds tz' string.
>>> rfc822_date_to_git('Thu, 1 Jan 1970 00:00:01 +0000')
diff --git a/git-dch b/git-dch
index debb974f..07c8789a 100755
--- a/git-dch
+++ b/git-dch
@@ -25,10 +25,10 @@ import sys
import shutil
import subprocess
import gbp.command_wrappers as gbpc
-from gbp.git import (GitRepositoryError, GitRepository, build_tag)
+from gbp.git import (GitRepositoryError, GitRepository, build_tag, tag_to_version)
from gbp.config import GbpOptionParser, GbpOptionGroup
from gbp.errors import GbpError
-from gbp.deb import parse_changelog, NoChangelogError
+from gbp.deb import parse_changelog, NoChangelogError, is_native, compare_versions
from gbp.command_wrappers import (Command, CommandExecFailed)
snapshot_re = re.compile("\s*\*\* SNAPSHOT build @(?P<commit>[a-z0-9]+)\s+\*\*")
@@ -113,8 +113,25 @@ def add_changelog_entry(msg, author, email, dch_options):
spawn_dch(msg=msg, author=author, email=email, dch_options=dch_options)
-def add_changelog_section(msg, distribution, author=None, email=None, version=None, dch_options=''):
+def add_changelog_section(msg, distribution, repo, options, cp,
+ author=None, email=None, version=None, dch_options=''):
"add a new changelog section"
+ # If no version(change) was specified guess the new version based on the
+ # latest upstream version on the upstream branch
+ if not version and not is_native(cp):
+ pattern = options.upstream_tag.replace('%(version)s', '*')
+ try:
+ tag = repo.find_tag('HEAD', pattern=pattern)
+ upstream = tag_to_version(tag, options.upstream_tag)
+ if upstream:
+ if options.verbose:
+ print "Found %s." % upstream
+ new_version = "%s-1" % upstream
+ if compare_versions(upstream, cp['Version']):
+ version['version'] = new_version
+ except GitRepository:
+ if options.verbose:
+ print "No tag found matching pattern %s." % pattern
spawn_dch(msg=msg, newversion=True, version=version, author=author, email=email,
distribution=distribution, dch_options=dch_options)
@@ -457,7 +474,10 @@ def main(argv):
version=version_change,
author=commit_author,
email=commit_email,
- dch_options=dch_options)
+ dch_options=dch_options,
+ repo=repo,
+ options=options,
+ cp=cp)
# Adding a section only needs to happen once.
add_section = False
else:
@@ -475,7 +495,10 @@ def main(argv):
commit_msg = "UNRELEASED"
add_changelog_section(distribution="UNRELEASED", msg="UNRELEASED",
version=version_change,
- dch_options=dch_options)
+ dch_options=dch_options,
+ repo=repo,
+ options=options,
+ cp=cp)
fixup_trailer(repo, git_author=options.git_author,
dch_options=dch_options)