diff options
author | Guido Guenther <agx@sigxcpu.org> | 2007-09-30 17:31:59 +0200 |
---|---|---|
committer | Guido Guenther <agx@sigxcpu.org> | 2007-09-30 17:31:59 +0200 |
commit | 2826b13860252e3747349e3c7cc7e2a257596acc (patch) | |
tree | 26eed789f6cca0af97cbf4a744f4ff9b5cade4c7 | |
parent | 350e9b57ac4b243f3849e914235a111ad041a5ef (diff) |
add git-dch
-rwxr-xr-x | debian/rules | 2 | ||||
-rw-r--r-- | docs/common.ent | 1 | ||||
-rw-r--r-- | docs/man.git-dch.sgml | 11 | ||||
-rw-r--r-- | docs/manpages/git-dch.sgml | 88 | ||||
-rw-r--r-- | docs/manpages/manpages.ent | 1 | ||||
-rw-r--r-- | docs/manual.sgml | 1 | ||||
-rwxr-xr-x | git-dch | 129 | ||||
-rw-r--r-- | setup.py | 2 |
8 files changed, 233 insertions, 2 deletions
diff --git a/debian/rules b/debian/rules index eff6c1f..c20b9ef 100755 --- a/debian/rules +++ b/debian/rules @@ -7,7 +7,7 @@ DEB_PYTHON_CLEAN_ARGS = --all include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/python-distutils.mk -COMMANDS=git-buildpackage git-import-dsc git-import-orig +COMMANDS=git-buildpackage git-import-dsc git-import-orig git-dch MANPAGES=$(patsubst %,docs/%.1,$(COMMANDS)) MANUAL=docs/manual-html PYCHECKS=$(patsubst %,%.py,$(COMMANDS)) diff --git a/docs/common.ent b/docs/common.ent index 7c4d38d..31e9835 100644 --- a/docs/common.ent +++ b/docs/common.ent @@ -7,6 +7,7 @@ <!ENTITY git-buildpackage "<command>git-buildpackage</command>"> <!ENTITY git-import-orig "<command>git-import-orig</command>"> <!ENTITY git-import-dsc "<command>git-import-dsc</command>"> + <!ENTITY git-dch "<command>git-dch</command>"> <!ENTITY gitcmd "<command>git</command>"> <!ENTITY gitkcmd "<command>gitk</command>"> <!ENTITY pbuildercmd "<command>pbuilder</command>"> diff --git a/docs/man.git-dch.sgml b/docs/man.git-dch.sgml new file mode 100644 index 0000000..797f372 --- /dev/null +++ b/docs/man.git-dch.sgml @@ -0,0 +1,11 @@ +<!DOCTYPE reference PUBLIC "-//OASIS//DTD DocBook V4.1//EN" [ + <!ENTITY % COMMON SYSTEM "common.ent"> + %COMMON; + <!ENTITY % MANPAGES SYSTEM "manpages/manpages.ent"> + %MANPAGES; +]> + +<reference> +<title>git-buildpackage Manual</title> +&man.git.dch; +</reference> diff --git a/docs/manpages/git-dch.sgml b/docs/manpages/git-dch.sgml new file mode 100644 index 0000000..7abf89c --- /dev/null +++ b/docs/manpages/git-dch.sgml @@ -0,0 +1,88 @@ +<refentry id="gbp.man.git.dch"> + <refentryinfo> + <address> + &dhemail; + </address> + <author> + &dhfirstname; + &dhsurname; + </author> + </refentryinfo> + <refmeta> + <refentrytitle>git-dch</refentrytitle> + &dhsection; + </refmeta> + <refnamediv> + <refname>&git-dch;</refname> + + <refpurpose>Generate Debian changelog from git commit messages</refpurpose> + </refnamediv> + <refsynopsisdiv> + <cmdsynopsis> + &git-dch; + + <arg><option>--verbose</option></arg> + <arg><option>--debian-branch=</option><replaceable>branch_name</replaceable></arg> + <arg><option>--debian-tag=</option><replaceable>tag-format</replaceable></arg> + <arg><option>--since=</option><replaceable>commitish</replaceable></arg> + </cmdsynopsis> + </refsynopsisdiv> + <refsect1> + <title>DESCRIPTION</title> + <para> + &git-dch; reads git commit messages and generates the debian changelog from it. If no arguments + are given &git-dch; starts from the last tagged debian package version up + to the tip of the current tip of the <replaceable>debian-branch</replaceable>. + </para> + </refsect1> + <refsect1> + <title>OPTIONS</title> + + <variablelist> + <varlistentry> + <term><option>--debian-branch</option>=<replaceable>branch_name</replaceable> + </term> + <listitem> + <para>The branch in the Git repository the Debian package is being + developed on, default is <replaceable>master</replaceable>. + </listitem> + </varlistentry> + <varlistentry> + <term><option>--verbose</option></term> + <term><option>-v</option></term> + <listitem> + <para>verbose execution</para> + </listitem> + </varlistentry> + <varlistentry> + <term><option>--debian-tag=</option><replaceable>tag-format</replaceable> + </term> + <listitem> + <para>tag format used, when tagging debian versions</para> + </listitem> + </varlistentry> + <varlistentry> + <term><option>--since=</option><replaceable>committish</replaceable> + </term> + <listitem> + <para>start reading commit messages at <replaceable>committish</replaceable></para> + </listitem> + </varlistentry> + </variablelist> + </refsect1> + <refsect1> + &man.git.config-files; + </refsect1> + <refsect1> + <title>SEE ALSO</title> + + <para>git-buildpackage (1), git-import-dsc (1), git (1), git_load_dirs (1)</para> + + </refsect1> + <refsect1> + <title>AUTHOR</title> + + <para>&dhusername; &dhemail;</para> + + </refsect1> +</refentry> diff --git a/docs/manpages/manpages.ent b/docs/manpages/manpages.ent index 6f76421..7a00f0b 100644 --- a/docs/manpages/manpages.ent +++ b/docs/manpages/manpages.ent @@ -1,6 +1,7 @@ <!ENTITY man.git.importorig SYSTEM "git-import-orig.sgml"> <!ENTITY man.git.importdsc SYSTEM "git-import-dsc.sgml"> <!ENTITY man.git.buildpackage SYSTEM "git-buildpackage.sgml"> +<!ENTITY man.git.dch SYSTEM "git-dch.sgml"> <!ENTITY man.git.config-files " <title>CONFIGURATION FILES</title> <para> Three configuration files are parsed to set defaults for the above diff --git a/docs/manual.sgml b/docs/manual.sgml index 0ffbe3f..246e607 100644 --- a/docs/manual.sgml +++ b/docs/manual.sgml @@ -28,6 +28,7 @@ &man.git.buildpackage; &man.git.importdsc; &man.git.importorig; + &man.git.dch; </appendix> <appendix id="gbp.copyleft"> <title>Copyright</title> @@ -0,0 +1,129 @@ +#!/usr/bin/python +# vim: set fileencoding=utf-8 : +# +# (C) 2007 Guido Guenther <agx@sigxcpu.org> +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +"""Generate Debian changelog entries from git changelogs""" + +import sys +import os +import re +import subprocess +import gbp.command_wrappers as gbpc +from gbp.git_utils import (GitRepositoryError, GitRepository, build_tag) +from gbp.config import GbpOptionParser +from gbp.errors import GbpError +from gbp.deb_utils import parse_changelog + + +def get_log(start, end): + """Get the shortlog from commit start to commit end""" + try: + p1 = subprocess.Popen(["git-log", "--no-merges", "%s...%s" % (start, end)], + stdout=subprocess.PIPE) + p2 = subprocess.Popen(["git-shortlog"], stdin=p1.stdout, stdout=subprocess.PIPE) + changes = p2.communicate()[0].split('\n') + except OSError, err: + raise GbpError, "Cannot get changes: %s" % err + except ValueError, err: + raise GbpError, "Cannot get changes: %s" % err + if p1.wait() or p2.wait(): + raise GbpError, "Cannot get changes, pipe failed." + return changes + + +def shortlog_to_dch(changes, verbose): + """convert the changes in git shortlog format to debian changelog format""" + commit_re = re.compile('\s+(?P<msg>.*)') + author_re = re.compile('(?P<author>.*) \([0-9]+\)') + author = 'Unknown' + ret = 0 + + # FIXME: this isn't flexible enough + ret = os.system("dch --distribution=UNRELEASED -i UNRELEASED") + if ret: + raise GbpError, "Error executing %s: %d" % (cmd, ret) + + for line in changes: + r = commit_re.match(line) + msg = '' + if r: + msg = r.group('msg') + else: + r = author_re.match(line) + if r: + author = r.group('author') + elif line: + print >>sys.stderr, "Unknown changelog line: %s" % line + if msg: + cmd = 'DEBFULLNAME="%s" dch "%s"' % (author, msg.replace('"','\"')) + if verbose: + print cmd + ret = os.system(cmd) + if ret: + raise GbpError, "Error executing %s: %d" % (cmd, ret) + + +def main(argv): + ret = 0 + + parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='') + + parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + parser.add_config_file_option(option_name="debian-branch", dest='debian', + help="branch the debian patch is being developed on, default is '%(debian-branch)s'") + parser.add_option("-s", "--since", dest="from_commit", help="commit to start from") + parser.add_config_file_option(option_name="debian-tag", dest="debian_tag", + help="Format string for debian tags, default is '%(debian-tag)s'") + (options, args) = parser.parse_args(argv[1:]) + + try: + if options.verbose: + gbpc.Command.verbose = True + + if args: + parser.print_help() + raise GbpError + + try: + GitRepository('.') + except GitRepositoryError: + raise GbpError, "%s is not a git repository" % (os.path.abspath('.')) + + if options.from_commit: + start = options.from_commit + else: + cp = parse_changelog('debian/changelog') + start = build_tag(options.debian_tag, cp['Version']) + + changes = get_log(start, options.debian) + if changes: + shortlog_to_dch(changes, options.verbose) + else: + print "No changes detected from %s to %s." % (start, options.debian) + + except GbpError, err: + if len(err.__str__()): + print >>sys.stderr, err + ret = 1 + return ret + +if __name__ == "__main__": + sys.exit(main(sys.argv)) + +# vim:et:ts=4:sw=4: + @@ -21,7 +21,7 @@ from distutils.core import setup setup(name = "git_build_package", author = 'Guido Guenther', author_email = 'agx@sigxcpu.org', - scripts = [ 'git-buildpackage', 'git-import-dsc', 'git-import-orig'], + scripts = [ 'git-buildpackage', 'git-import-dsc', 'git-import-orig', 'git-dch' ], packages = [ 'gbp' ], data_files = [("/etc/git-buildpackage/", ["gbp.conf" ]),], ) |