diff options
author | Matthijs Kooijman <matthijs@stdin.nl> | 2010-08-19 12:33:02 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2010-09-17 20:07:16 +0200 |
commit | ee0e9ffe0a69d1ae1080f8087725015ae0ff8bc4 (patch) | |
tree | caf48559cc9cc07b7d201a381e39ae9adc3ff48f | |
parent | 083834b407e2e76e1386f9004e495a88f2906cf4 (diff) | |
download | git-buildpackage-ee0e9ffe0a69d1ae1080f8087725015ae0ff8bc4.tar.gz git-buildpackage-ee0e9ffe0a69d1ae1080f8087725015ae0ff8bc4.tar.bz2 git-buildpackage-ee0e9ffe0a69d1ae1080f8087725015ae0ff8bc4.zip |
Let git-import-orig find the changelog when not on the debian-branch.
When no changelog file is available in the checkout, look for the
changelog in the repository. This allows for using git-import-orig when
the upstream branch is checked out, for example.
-rw-r--r-- | gbp/deb.py | 52 | ||||
-rwxr-xr-x | git-buildpackage | 4 | ||||
-rwxr-xr-x | git-dch | 4 | ||||
-rwxr-xr-x | git-import-dsc | 2 | ||||
-rwxr-xr-x | git-import-orig | 16 |
5 files changed, 62 insertions, 16 deletions
@@ -13,6 +13,7 @@ import sys import glob import command_wrappers as gbpc from errors import GbpError +from gbp.git import GitRepositoryError # When trying to parse a version-number from a dsc or changes file, these are # the valid characters. @@ -171,10 +172,30 @@ def parse_dsc(dscfile): return dsc - -def parse_changelog(changelog): +def parse_changelog_repo(repo, branch, filename): + """ + Parse the changelog file from given branch in the git + repository. """ - parse changelog file changelog + try: + # Note that we could just pass in the branch:filename notation + # to show as well, but we want to check if the branch / filename + # exists first, so we can give a separate error from other + # repository errors. + sha = repo.rev_parse("%s:%s" % (branch, filename), quiet=True) + except GitRepositoryError: + raise NoChangelogError, "Changelog %s not found in branch %s" % (filename, branch) + + lines = repo.show(sha) + return parse_changelog('\n'.join(lines)) + +def parse_changelog(contents=None, filename=None): + """ + Parse the content of a changelog file. Either contents, containing + the contents of a changelog file, or filename, pointing to a + changelog file must be passed. + + Returns: cp['Version']: full version string including epoch cp['Upstream-Version']: upstream version, if not debian native @@ -182,11 +203,26 @@ def parse_changelog(changelog): cp['Epoch']: epoch, if any cp['NoEpoch-Version']: full version string excluding epoch """ - if not os.access(changelog, os.F_OK): - raise NoChangelogError, "Changelog %s not found" % (changelog, ) - status, output = commands.getstatusoutput('dpkg-parsechangelog -l%s' % (changelog, )) - if status: - raise ParseChangeLogError, output + # Check that either contents or filename is passed (but not both) + if (not filename and not contents) or (filename and contents): + raise Exception("Either filename or contents must be passed to parse_changelog") + + # If a filename was passed, check if it exists + if filename and not os.access(filename, os.F_OK): + raise NoChangelogError, "Changelog %s not found" % (filename, ) + + # If no filename was passed, let parse_changelog read from stdin + if not filename: + filename = '-' + + # Note that if contents is None, stdin will just be closed right + # away by communicate. + cmd = subprocess.Popen(['dpkg-parsechangelog', '-l%s' % filename], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (output, errors) = cmd.communicate(contents) + if cmd.returncode: + raise ParseChangeLogError, "Failed to parse changelog. dpkg-parsechangelog said:\n%s" % (errors, ) + # Parse the result of dpkg-parsechangelog (which looks like + # email headers) cp = email.message_from_string(output) try: if ':' in cp['Version']: diff --git a/git-buildpackage b/git-buildpackage index cbc310a3..3fe6f913 100755 --- a/git-buildpackage +++ b/git-buildpackage @@ -326,7 +326,7 @@ def main(argv): raise GbpError, "Use --git-ignore-branch to ignore or --git-debian-branch to set the branch name." try: - cp = du.parse_changelog(changelog) + cp = du.parse_changelog(filename=changelog) version = cp['Version'] version_no_epoch = cp['NoEpoch-Version'] if du.is_native(cp): @@ -385,7 +385,7 @@ def main(argv): print "Exporting '%s' to '%s'" % (options.export, tmp_dir) dump_tree(tmp_dir, tree) - cp = du.parse_changelog(os.path.join(tmp_dir, 'debian', 'changelog')) + cp = du.parse_changelog(filename=os.path.join(tmp_dir, 'debian', 'changelog')) export_dir = os.path.join(output_dir, "%s-%s" % (cp['Source'], major)) print "Moving '%s' to '%s'" % (tmp_dir, export_dir) move_old_export(export_dir) @@ -232,7 +232,7 @@ def do_snapshot(changelog, repo, next_snapshot): """ commit = head_commit(repo) - cp = parse_changelog(changelog) + cp = parse_changelog(filename=changelog) (release, snapshot) = snapshot_version(cp['Version']) snapshot = int(eval(next_snapshot)) @@ -417,7 +417,7 @@ def main(argv): print >>sys.stderr, "You are not on branch '%s' but on '%s'" % (options.debian_branch, branch) raise GbpError, "Use --ignore-branch to ignore or --debian-branch to set the branch name." - cp = parse_changelog(changelog) + cp = parse_changelog(filename=changelog) if options.since: since = options.since diff --git a/git-import-dsc b/git-import-dsc index f51dc1e1..d9de908d 100755 --- a/git-import-dsc +++ b/git-import-dsc @@ -98,7 +98,7 @@ def apply_debian_patch(repo, unpack_dir, src, options, parents): os.chmod('debian/rules', 0755) os.chdir(repo.path) - dch = parse_changelog(os.path.join(unpack_dir, 'debian/changelog')) + dch = parse_changelog(filename=os.path.join(unpack_dir, 'debian/changelog')) date= rfc822_date_to_git(dch['Date']) author, email = parseaddr(dch['Maintainer']) if not (author and email): diff --git a/git-import-orig b/git-import-orig index 031198d7..32309ba7 100755 --- a/git-import-orig +++ b/git-import-orig @@ -309,10 +309,17 @@ on howto create it otherwise use --upstream-branch to specify it. # Try to find the source package name try: - cp = parse_changelog('debian/changelog') + cp = parse_changelog(filename='debian/changelog') sourcepackage = cp['Source'] except NoChangelogError: - sourcepackage = ask_package_name(guessed_package) + try: + # Check the changelog file from the repository, in case + # we're not on the debian-branch (but upstream, for + # example). + cp = parse_changelog_repo(repo, options.debian_branch, 'debian/changelog') + sourcepackage = cp['Source'] + except NoChangelogError: + sourcepackage = ask_package_name(guessed_package) # Try to find the version. if options.version: @@ -396,7 +403,10 @@ on howto create it otherwise use --upstream-branch to specify it. if options.postimport: epoch = '' if os.access('debian/changelog', os.R_OK): - cp = parse_changelog('debian/changelog') + # No need to check the changelog file from the + # repository, since we're certain that we're on + # the debian-branch + cp = parse_changelog(filename='debian/changelog') if has_epoch(cp): epoch = '%s:' % cp['Epoch'] info = { 'version': "%s%s-1" % (epoch, version) } |