diff options
-rw-r--r-- | debian/git-buildpackage.install | 1 | ||||
-rw-r--r-- | debian/git-buildpackage.manpages | 1 | ||||
-rw-r--r-- | docs/Makefile | 1 | ||||
-rw-r--r-- | docs/common.ent | 3 | ||||
-rw-r--r-- | docs/man.gbp-pristine-tar.sgml | 11 | ||||
-rw-r--r-- | docs/manpages/gbp-pristine-tar.sgml | 112 | ||||
-rw-r--r-- | docs/manpages/gbp.sgml | 1 | ||||
-rw-r--r-- | docs/manpages/manpages.ent | 1 | ||||
-rw-r--r-- | docs/manual.sgml | 1 | ||||
-rw-r--r-- | gbp/scripts/common/__init__.py | 23 | ||||
-rw-r--r-- | gbp/scripts/import_orig.py | 22 | ||||
-rw-r--r-- | gbp/scripts/pristine_tar.py | 120 | ||||
-rw-r--r-- | packaging/git-buildpackage.spec | 2 | ||||
-rw-r--r-- | tests/01_test_help.py | 1 | ||||
-rw-r--r-- | tests/component/deb/test_pristine_tar.py | 71 |
15 files changed, 349 insertions, 22 deletions
diff --git a/debian/git-buildpackage.install b/debian/git-buildpackage.install index a53a8aa5..589d7efb 100644 --- a/debian/git-buildpackage.install +++ b/debian/git-buildpackage.install @@ -24,6 +24,7 @@ usr/lib/python2.?/dist-packages/gbp/scripts/import_dscs.py usr/lib/python2.?/dist-packages/gbp/scripts/import_orig.py usr/lib/python2.?/dist-packages/gbp/scripts/__init__.py usr/lib/python2.?/dist-packages/gbp/scripts/pq.py +usr/lib/python2.?/dist-packages/gbp/scripts/pristine_tar.py usr/lib/python2.?/dist-packages/gbp/scripts/pull.py usr/lib/python2.?/dist-packages/gbp/scripts/supercommand.py usr/lib/python2.?/dist-packages/gbp/tmpfile.py diff --git a/debian/git-buildpackage.manpages b/debian/git-buildpackage.manpages index 9dd9cc36..de40bfd2 100644 --- a/debian/git-buildpackage.manpages +++ b/debian/git-buildpackage.manpages @@ -9,5 +9,6 @@ docs/gbp-import-dsc.1 docs/gbp-import-dscs.1 docs/gbp-import-orig.1 docs/gbp-pq.1 +docs/gbp-pristine-tar.1 docs/gbp-pull.1 docs/git-pbuilder.1 diff --git a/docs/Makefile b/docs/Makefile index 58d21462..cb226582 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -11,6 +11,7 @@ MAN1S = \ gbp-import-dscs \ gbp-import-orig \ gbp-pq \ + gbp-pristine-tar \ gbp-pull \ gbp-buildpackage-rpm \ gbp-import-srpm \ diff --git a/docs/common.ent b/docs/common.ent index 42872d94..955d2f12 100644 --- a/docs/common.ent +++ b/docs/common.ent @@ -15,6 +15,7 @@ <!ENTITY gbp-pull "<command>gbp pull</command>"> <!ENTITY gbp-clone "<command>gbp clone</command>"> <!ENTITY gbp-pq "<command>gbp pq</command>"> + <!ENTITY gbp-pristine-tar "<command>gbp pristine-tar</command>"> <!ENTITY gbp-create-remote-repo "<command>gbp create-remote-repo</command>"> <!ENTITY git-pbuilder "<command>git-pbuilder</command>"> <!ENTITY git-qemubuilder "<command>git-pbuilder</command>"> @@ -62,4 +63,4 @@ <!ENTITY pyformat "<ulink url='https://docs.python.org/2/library/stdtypes.html#string-formatting'><citetitle>Python format string</citetitle></ulink>"> <!ENTITY dep14 "<ulink url='http://dep.debian.net/deps/dep14/'><citetitle>DEP-14</citetitle></ulink>"> <!ENTITY manual "<ulink url='https://honk.sigxcpu.org/piki/projects/git-buildpackage'>here</ulink>"> -
\ No newline at end of file + diff --git a/docs/man.gbp-pristine-tar.sgml b/docs/man.gbp-pristine-tar.sgml new file mode 100644 index 00000000..a1659ca1 --- /dev/null +++ b/docs/man.gbp-pristine-tar.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.gbp.pristine.tar; +</reference> diff --git a/docs/manpages/gbp-pristine-tar.sgml b/docs/manpages/gbp-pristine-tar.sgml new file mode 100644 index 00000000..93a1db3d --- /dev/null +++ b/docs/manpages/gbp-pristine-tar.sgml @@ -0,0 +1,112 @@ +<refentry id="man.gbp.pristine.tar"> + <refentryinfo> + <address> + &dhemail; + </address> + <author> + &dhfirstname; + &dhsurname; + </author> + </refentryinfo> + <refmeta> + <refentrytitle>gbp-pristine-tar</refentrytitle> + &dhsection; + </refmeta> + <refnamediv> + <refname>gbp-pristine-tar</refname> + <refpurpose>Manage pristine-tar commits in a git repository</refpurpose> + </refnamediv> + <refsynopsisdiv> + <cmdsynopsis> + &gbp-pristine-tar; + + &man.common.options.synopsis; + <arg><option>--upstream-tag=</option><replaceable>tag-format</replaceable></arg> + <arg rep='repeat'><option>--component=</option><replaceable>component</replaceable></arg> + <group choice="plain"> + <arg><option>commit</option></arg> + </group> + <group choice="plain"> + <arg choice="plain"><replaceable>filename</replaceable></arg> + </group> + </cmdsynopsis> + </refsynopsisdiv> + <refsect1> + <title>DESCRIPTION</title> + <para> + &gbp-pristine-tar; adds the pristine-tar commit for a given + upstream tarball to a &git; repository. This can be useful if a + original tarball has been already imported and the pristine-tar + commits should be added at a later time or if you're tracking + upstream git and want to create pristine-tar commits + nevertheless. + </para> + </refsect1> + <refsect1> + <title>OPTIONS</title> + <variablelist> + &man.common.options.description; + <varlistentry> + <term><option>--upstream-tag=</option><replaceable>tag-format</replaceable> + </term> + <listitem> + <para> + use this tag format when tagging upstream versions, + default is <replaceable>upstream/%(version)s</replaceable> + </para> + </listitem> + </varlistentry> + <varlistentry> + <term><option>--component=</option><replaceable>COMPONENT</replaceable> + </term> + <listitem> + <para> + When creating the pristine-tar commits also look for an additional tarball + with component name <replaceable>COMPONENT</replaceable>. E.g. in + <filename>hello-debhelper_1.0.orig-foo.tar.gz</filename> + the component name would be <replaceable>foo</replaceable>. The additional + tarball is expected to be in the same directory than the upstream tarball + and to use the same compression type. This option can be + given multiple times to add multiple additional tarballs. + </para> + <para> + Using additional original tarballs is a feature of the 3.0 + (quilt) source format. See + the <command>dpkg-source</command> manpage for + details. This is currently considered an experimental + feature and might change incompatibly. + </para> + </listitem> + </varlistentry> + </variablelist> + </refsect1> + <refsect1> + <title>EXAMPLES</title> + <para>Add pristine-tar commits for an upstream tarball:</para> + <screen> + &gbp-pristine-tar; ../upstream-tarball-0.1.tar.gz</screen> + <para>Same as above with an additional + tarball <filename>../upstream-tarball-foo-0.1.tar.gz:</filename></para> + <screen> + &gbp-pristine-tar; --component-tarball=foo ../upstream-tarball-0.1.tar.gz</screen> +</refsect1> + <refsect1> + &man.gbp.config-files; + </refsect1> + <refsect1> + <title>SEE ALSO</title> + <para> + <xref linkend="man.gbp.import.orig"/>, + <xref linkend="man.gbp.conf"/>, + &man.seealso.common; + </para> + </refsect1> + <refsect1> + <title>AUTHOR</title> + <para> + &dhusername; &dhemail; + </para> + </refsect1> +</refentry> +<!-- LocalWords: xz lzma bzip gzip tarball + --> diff --git a/docs/manpages/gbp.sgml b/docs/manpages/gbp.sgml index e6faa458..e54591d4 100644 --- a/docs/manpages/gbp.sgml +++ b/docs/manpages/gbp.sgml @@ -160,6 +160,7 @@ <xref linkend="man.gbp.import.orig"/>, <xref linkend="man.gbp.dch"/>, <xref linkend="man.gbp.pq"/>, + <xref linkend="man.gbp.pristine.tar"/>, <xref linkend="man.gbp.create.remote.repo"/>, <xref linkend="man.gbp.pull"/>, <xref linkend="man.gbp.clone"/>, diff --git a/docs/manpages/manpages.ent b/docs/manpages/manpages.ent index 01700bbd..d2f6f3f4 100644 --- a/docs/manpages/manpages.ent +++ b/docs/manpages/manpages.ent @@ -5,6 +5,7 @@ <!ENTITY man.gbp.config SYSTEM "gbp-config.sgml"> <!ENTITY man.gbp.dch SYSTEM "gbp-dch.sgml"> <!ENTITY man.gbp SYSTEM "gbp.sgml"> +<!ENTITY man.gbp.pristine.tar SYSTEM "gbp-pristine-tar.sgml"> <!ENTITY man.gbp.pull SYSTEM "gbp-pull.sgml"> <!ENTITY man.gbp.clone SYSTEM "gbp-clone.sgml"> <!ENTITY man.gbp.pq SYSTEM "gbp-pq.sgml"> diff --git a/docs/manual.sgml b/docs/manual.sgml index a017194c..d60ecfa4 100644 --- a/docs/manual.sgml +++ b/docs/manual.sgml @@ -37,6 +37,7 @@ &man.gbp.clone; &man.gbp.config; &man.gbp.pull; + &man.gbp.pristine.tar; &man.gbp.pq; &man.gbp.create.remote.repo; &man.gbp.conf; diff --git a/gbp/scripts/common/__init__.py b/gbp/scripts/common/__init__.py index e36cc50b..44dd9298 100644 --- a/gbp/scripts/common/__init__.py +++ b/gbp/scripts/common/__init__.py @@ -17,6 +17,10 @@ """Parts shared between the deb and rpm commands""" import re +import os +from gbp.errors import GbpError +from gbp.deb import DebianPkgPolicy +from gbp.pkg import parse_archive_filename class ExitCodes(object): @@ -38,3 +42,22 @@ def is_download(args): if args and re.match("https?://", args[0]): return True return False + + +def get_component_tarballs(name, version, tarball, components): + """ + Figure out the paths to the component tarballs based on the main + tarball. + """ + tarballs = [] + (_, _, comp_type) = parse_archive_filename(tarball) + for component in components: + cname = DebianPkgPolicy.build_tarball_name(name, + version, + comp_type, + os.path.dirname(tarball), + component) + tarballs.append((component, cname)) + if not os.path.exists(cname): + raise GbpError("Can not find component tarball %s" % cname) + return tarballs diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index 3ff6c44d..016ebff9 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -31,11 +31,10 @@ from gbp.deb.changelog import ChangeLog, NoChangeLogError from gbp.deb.git import (GitRepositoryError, DebianGitRepository) from gbp.config import GbpOptionParserDebian, GbpOptionGroup, no_upstream_branch_msg from gbp.errors import GbpError -from gbp.pkg import parse_archive_filename from gbp.format import format_str from gbp.git.vfs import GitVfs import gbp.log -from gbp.scripts.common import ExitCodes, is_download +from gbp.scripts.common import ExitCodes, is_download, get_component_tarballs from gbp.scripts.common.import_orig import (orig_needs_repack, cleanup_tmp_tree, ask_package_name, ask_package_version, repack_source, is_link_target, download_orig) @@ -398,25 +397,6 @@ def debian_branch_merge_by_merge(repo, tag, version, options): repo.set_branch(branch) -def get_component_tarballs(name, version, tarball, components): - """ - Figure out the paths to the component tarballs based on the main - tarball. - """ - tarballs = [] - for component in components: - (_, _, comp_type) = parse_archive_filename(tarball) - cname = DebianPkgPolicy.build_tarball_name(name, - version, - comp_type, - os.path.dirname(tarball), - component) - tarballs.append((component, cname)) - if not os.path.exists(cname): - raise GbpError("Can not find component tarball %s" % cname) - return tarballs - - def unpack_tarballs(sourcepackage, source, version, component_tarballs, options): tmpdir = tempfile.mkdtemp(dir='../') if not source.is_dir(): # Unpack main tarball diff --git a/gbp/scripts/pristine_tar.py b/gbp/scripts/pristine_tar.py new file mode 100644 index 00000000..909d2411 --- /dev/null +++ b/gbp/scripts/pristine_tar.py @@ -0,0 +1,120 @@ +# vim: set fileencoding=utf-8 : +# +# (C) 2017 Guido Günther <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, please see +# <http://www.gnu.org/licenses/> +# +"""Perform pristine-tar import into a Git repository""" + +import os +import sys +import gbp.log +from gbp.command_wrappers import CommandExecFailed +from gbp.config import GbpOptionParserDebian +from gbp.deb.git import (GitRepositoryError, DebianGitRepository) +from gbp.deb.source import DebianSource +from gbp.errors import GbpError +from gbp.scripts.common import ExitCodes, get_component_tarballs + + +def usage_msg(): + return """%prog [action] [options] /path/to/upstream-version.tar.gz + +Actions: + commit recreate the pristine-tar commits on the pristine-tar branch +""" + + +def build_parser(name): + try: + parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='', + usage=usage_msg()) + except GbpError as err: + gbp.log.err(err) + return None + + parser.add_config_file_option(option_name="upstream-tag", + dest="upstream_tag") + parser.add_config_file_option("component", action="append", metavar='COMPONENT', + dest="components") + parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + parser.add_config_file_option(option_name="color", dest="color", type='tristate') + parser.add_config_file_option(option_name="color-scheme", + dest="color_scheme") + return parser + + +def parse_args(argv): + """Parse the command line arguments + @return: options and arguments + """ + + parser = build_parser(argv[0]) + if not parser: + return None, None + + (options, args) = parser.parse_args(argv[1:]) + gbp.log.setup(options.color, options.verbose, options.color_scheme) + return options, args + + +def main(argv): + ret = 0 + repo = None + + (options, args) = parse_args(argv) + if not options: + return ExitCodes.parse_error + + if len(args) != 2 or args[0] not in ['commit']: + gbp.log.err("No action given") + return 1 + else: + tarball = args[1] + + try: + try: + repo = DebianGitRepository('.') + except GitRepositoryError: + raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) + + source = DebianSource('.') + component_tarballs = get_component_tarballs(source.sourcepkg, + source.upstream_version, + tarball, + options.components) + upstream_tag = repo.version_to_tag(options.upstream_tag, + source.upstream_version) + repo.create_pristinetar_commits(upstream_tag, + tarball, + component_tarballs) + except (GbpError, CommandExecFailed) as err: + if str(err): + gbp.log.err(err) + ret = 1 + + if not ret: + comp_msg = ('with additional tarballs for %s' + % ", ".join([os.path.basename(t[1]) for t in component_tarballs])) if component_tarballs else '' + gbp.log.info("Successfully committed pristine-tar data for version %s of %s%s" % (source.version, + tarball, + comp_msg)) + return ret + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) + +# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/packaging/git-buildpackage.spec b/packaging/git-buildpackage.spec index a3ee87b5..abae4436 100644 --- a/packaging/git-buildpackage.spec +++ b/packaging/git-buildpackage.spec @@ -226,6 +226,7 @@ done %{python_sitelib}/gbp/scripts/__init__.py* %{python_sitelib}/gbp/scripts/clone.py* %{python_sitelib}/gbp/scripts/config.py* +%{python_sitelib}/gbp/scripts/pristine_tar.py* %{python_sitelib}/gbp/scripts/pull.py* %{python_sitelib}/gbp/scripts/supercommand.py* %{python_sitelib}/gbp/scripts/common/*.py* @@ -236,6 +237,7 @@ done %{_mandir}/man1/gbp.1* %{_mandir}/man1/gbp-clone.1* %{_mandir}/man1/gbp-config.1* +%{_mandir}/man1/gbp-pristine-tar.1* %{_mandir}/man1/gbp-pull.1* %{_mandir}/man5/*.5* %endif diff --git a/tests/01_test_help.py b/tests/01_test_help.py index 8cfa3d24..c4cc34ea 100644 --- a/tests/01_test_help.py +++ b/tests/01_test_help.py @@ -16,6 +16,7 @@ class TestHelp(TestCaseWithData): 'dch', 'import_orig', 'import_dsc', + 'pristine_tar', 'pull', 'pq'] diff --git a/tests/component/deb/test_pristine_tar.py b/tests/component/deb/test_pristine_tar.py new file mode 100644 index 00000000..68148c6f --- /dev/null +++ b/tests/component/deb/test_pristine_tar.py @@ -0,0 +1,71 @@ +# vim: set fileencoding=utf-8 : +# +# (C) 2017 Guido Günther <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, please see +# <http://www.gnu.org/licenses/> + +import os + +from tests.component import ComponentTestBase +from tests.component.deb.fixtures import RepoFixtures +from tests.component.deb import DEB_TEST_DATA_DIR + +from gbp.scripts.pristine_tar import main as pristine_tar + +from nose.tools import ok_, eq_ + + +def _dsc_file(pkg, version, dir='dsc-3.0'): + return os.path.join(DEB_TEST_DATA_DIR, dir, '%s_%s.dsc' % (pkg, version)) + + +DEFAULT_DSC = _dsc_file('hello-debhelper', '2.6-2') + + +class TestPristineTar(ComponentTestBase): + """Test pristine-tar commit tool""" + pkg = "hello-debhelper" + def_branches = ['master', 'upstream', 'pristine-tar'] + + def _orig(self, version, dir='dsc-3.0'): + return os.path.join(DEB_TEST_DATA_DIR, + dir, + '%s_%s.orig.tar.gz' % (self.pkg, version)) + + @RepoFixtures.quilt30(DEFAULT_DSC, opts=['--no-pristine-tar']) + def test_run(self, repo): + """ + Test that adding pristine-tar commit wotks + """ + orig = self._orig('2.6') + ok_(pristine_tar(['arg0', 'commit', orig]) == 0) + self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar']) + + @RepoFixtures.quilt30(_dsc_file('hello-debhelper', + '2.8-1', + dir='dsc-3.0-additional-tarballs'), + opts=['--no-pristine-tar']) + def test_run_component_tarball(self, repo): + """ + Test that adding pristine-tar commits with additional tarballs works + """ + orig = self._orig('2.8', dir='dsc-3.0-additional-tarballs') + ok_(pristine_tar(['arg0', 'commit', '--component=foo', orig]) == 0) + self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar']) + + ptars = [('hello-debhelper_2.8.orig.tar.gz', 'pristine-tar'), + ('hello-debhelper_2.8.orig-foo.tar.gz', 'pristine-tar^')] + for f, w in ptars: + eq_(repo.get_subject(w), 'pristine-tar data for %s' % f) |