aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2015-06-01 22:50:50 +0200
committerGuido Günther <agx@sigxcpu.org>2015-06-02 19:58:11 +0200
commit8241459f773607a7c967eb46ca23a1ae3eae31ae (patch)
treedbb0429ee3d5fa8e10d6539cadc23d10f0324486
parent58ea0677d6ef0ea0dfc5bc93c0517967db49c656 (diff)
pq: Allow to preserve the patch name on import/export
Closes: #761161
-rw-r--r--docs/manpages/gbp-pq.sgml11
-rw-r--r--gbp/scripts/common/pq.py13
-rwxr-xr-xgbp/scripts/pq.py20
-rw-r--r--tests/13_test_gbp_pq.py35
4 files changed, 54 insertions, 25 deletions
diff --git a/docs/manpages/gbp-pq.sgml b/docs/manpages/gbp-pq.sgml
index ae1c09f3..9862b0b5 100644
--- a/docs/manpages/gbp-pq.sgml
+++ b/docs/manpages/gbp-pq.sgml
@@ -191,6 +191,17 @@
</listitem>
</varlistentry>
<varlistentry>
+ <term><option>Gbp[-Pq]: Name</option> <replaceable>name</replaceable>
+ </term>
+ <listitem>
+ <para>
+ The name to use for the patch when running <screen>&gbp-pq;
+ export</screen>. If unset it will be formatted
+ like <command>git am</command> would format it.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term><option>Gbp[-Pq]: Topic</option> <replaceable>topic</replaceable>
</term>
<listitem>
diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py
index 62f1c363..a4412184 100644
--- a/gbp/scripts/common/pq.py
+++ b/gbp/scripts/common/pq.py
@@ -1,6 +1,6 @@
# vim: set fileencoding=utf-8 :
#
-# (C) 2011 Guido Günther <agx@sigxcpu.org>
+# (C) 2011,2015 Guido Günther <agx@sigxcpu.org>
# (C) 2012 Intel Corporation <markus.lehtonen@linux.intel.com>
# 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
@@ -175,7 +175,7 @@ def write_patch_file(filename, commit_info, diff):
def format_patch(outdir, repo, commit_info, series, numbered=True,
- path_exclude_regex=None, topic=''):
+ path_exclude_regex=None, topic='', name=None):
"""Create patch of a single commit"""
# Determine filename and path
@@ -186,7 +186,10 @@ def format_patch(outdir, repo, commit_info, series, numbered=True,
suffix = '.patch'
base_maxlen = 63 - len(num_prefix) - len(suffix)
base = commit_info['patchname'][:base_maxlen]
- filename = (num_prefix if numbered else '') + base + suffix
+ if name is not None:
+ filename = name
+ else:
+ filename = (num_prefix if numbered else '') + base + suffix
filepath = os.path.join(outdir, filename)
# Make sure that we don't overwrite existing patches in the series
if filepath in series:
@@ -275,7 +278,7 @@ def apply_single_patch(repo, branch, patch, fallback_author, topic=None):
gbp.log.info("Applied %s" % os.path.basename(patch.path))
-def apply_and_commit_patch(repo, patch, fallback_author, topic=None):
+def apply_and_commit_patch(repo, patch, fallback_author, topic=None, name=None):
"""apply a single patch 'patch', add topic 'topic' and commit it"""
author = {'name': patch.author,
'email': patch.email,
@@ -296,6 +299,8 @@ def apply_and_commit_patch(repo, patch, fallback_author, topic=None):
msg = "%s\n\n%s" % (patch.subject, patch.long_desc)
if topic:
msg += "\nGbp-Pq: Topic %s" % topic
+ if name:
+ msg += "\nGbp-Pq: Name %s" % name
commit = repo.commit_tree(tree, msg, [repo.head], author=author)
repo.update_ref('HEAD', commit, msg="gbp-pq import %s" % patch.path)
diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py
index d3c452c1..c4193163 100755
--- a/gbp/scripts/pq.py
+++ b/gbp/scripts/pq.py
@@ -77,26 +77,27 @@ def generate_patches(repo, start, end, outdir, options):
for commit in rev_list:
info = repo.get_commit_info(commit)
# Parse 'gbp-pq-topic:'
- topic = parse_old_style_topic(info)
- cmds ={'topic': topic } if topic else {}
+ topic = parse_old_style_topic(info)
+ cmds = {'topic': topic} if topic else {}
# Parse 'Gbp: ' style commands
(cmds_gbp, info['body']) = parse_gbp_commands(info, 'gbp',
('ignore'),
- ('topic'),
- ('topic'))
+ ('topic', 'name'),
+ ('topic', 'name'))
cmds.update(cmds)
# Parse 'Gbp-Pq: ' style commands
(cmds_gbp_pq, info['body']) = parse_gbp_commands(info,
'gbp-pq',
('ignore'),
- ('topic'),
- ('topic'))
+ ('topic', 'name'),
+ ('topic', 'name'))
cmds.update(cmds_gbp_pq)
- if not 'ignore' in cmds:
+ if 'ignore' not in cmds:
if 'topic' in cmds:
topic = cmds['topic']
+ name = cmds.get('name', None)
format_patch(outdir, repo, info, patches, options.patch_numbers,
- topic=topic)
+ topic=topic, name=name)
else:
gbp.log.info('Ignoring commit %s' % info['id'])
@@ -286,7 +287,8 @@ def import_quilt_patches(repo, branch, series, tries, force):
for patch in queue:
gbp.log.debug("Applying %s" % patch.path)
try:
- apply_and_commit_patch(repo, patch, maintainer, patch.topic)
+ name = os.path.basename(patch.path)
+ apply_and_commit_patch(repo, patch, maintainer, patch.topic, name)
except (GbpError, GitRepositoryError) as e:
gbp.log.err("Failed to apply '%s': %s" % (patch.path, e))
repo.force_head('HEAD', hard=True)
diff --git a/tests/13_test_gbp_pq.py b/tests/13_test_gbp_pq.py
index f7a9bc77..4e729cae 100644
--- a/tests/13_test_gbp_pq.py
+++ b/tests/13_test_gbp_pq.py
@@ -19,7 +19,6 @@ from . import context
from . import testutils
import os
-import logging
import unittest
from gbp.scripts.pq import generate_patches, export_patches
@@ -49,6 +48,14 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo):
info = self.repo.get_commit_info('HEAD')
self.assertIn('Gbp-Pq: Topic foobar', info['body'])
+ def test_name(self):
+ """Test if setting a name works"""
+ patch = gbp.patch_series.Patch(_patch_path('foo.patch'))
+
+ pq.apply_and_commit_patch(self.repo, patch, None, name='foobar')
+ info = self.repo.get_commit_info('HEAD')
+ self.assertIn('Gbp-Pq: Name foobar', info['body'])
+
@unittest.skipIf(not os.path.exists('/usr/bin/dpkg'), 'Dpkg not found')
def test_debian_missing_author(self):
"""
@@ -112,26 +119,30 @@ class TestWritePatch(testutils.DebianGitTestRepo):
class opts:
patch_numbers = False
+ d = context.new_tmpdir(__name__)
+ expected_paths = [os.path.join(str(d), 'gbptest', n) for n in
+ ['added-foo.patch', 'patchname.diff']]
# Add test file with topic:
msg = ("added foo\n\n"
"Gbp-Pq: Topic gbptest")
self.add_file('foo', 'foo', msg)
+ msg = ("added bar\n\n"
+ "Gbp-Pq: Topic gbptest\n"
+ "Gbp-Pq: Name patchname.diff")
+ self.add_file('baz', 'baz', msg)
# Write it out as patch and check it's existence
- d = context.new_tmpdir(__name__)
- patchfile = generate_patches(self.repo, 'HEAD^', 'HEAD', str(d),
- opts)[0]
- expected = os.path.join(str(d), 'gbptest', 'added-foo.patch')
-
- self.assertEqual(os.path.basename(patchfile),
- 'added-foo.patch')
- self.assertTrue(os.path.exists(expected))
- logging.debug(open(expected).read())
+ patchfiles = generate_patches(self.repo, 'HEAD^^', 'HEAD', str(d),
+ opts)
+ for expected in expected_paths:
+ self.assertIn(expected, patchfiles)
+ self.assertTrue(os.path.exists(expected))
# Reapply the patch to a new branch
- self.repo.create_branch('testapply', 'HEAD^')
+ self.repo.create_branch('testapply', 'HEAD^^')
self.repo.set_branch('testapply')
- self.repo.apply_patch(expected)
+ for expected in expected_paths:
+ self.repo.apply_patch(expected)
self.repo.commit_all("foo")
diff = self.repo.diff('master', 'testapply')
# Branches must be identical afterwards