summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-05-15 09:51:54 +0300
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-09-04 17:29:45 +0300
commit96463341a53545f68bdf4a8cf334891f7d806393 (patch)
treedd9959d91c3a631c3e5f5c42f05cc2fee3b5797b
parent6805d692c701862c43aed06034d830eb7f825f73 (diff)
downloadgit-buildpackage-96463341a53545f68bdf4a8cf334891f7d806393.tar.gz
git-buildpackage-96463341a53545f68bdf4a8cf334891f7d806393.tar.bz2
git-buildpackage-96463341a53545f68bdf4a8cf334891f7d806393.zip
rpm: give patches in the order they are applied in the spec
Fixes patch importing in situations when patch tag numbering in the spec differs from the order they are applied. Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r--gbp/rpm/__init__.py29
-rw-r--r--tests/test_rpm.py24
-rw-r--r--tests/test_rpm_data/specs/gbp-test-quirks.spec12
3 files changed, 54 insertions, 11 deletions
diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py
index cab9fc23..3fc9b1c6 100644
--- a/gbp/rpm/__init__.py
+++ b/gbp/rpm/__init__.py
@@ -651,20 +651,29 @@ class SpecFile(object):
series = PatchSeries()
if 'patch' in self._tags:
tags = self._patches()
- macros = {}
+ applied = []
for macro in self._special_directives['patch']:
- macros[macro['id']] = macro['args']
- ignored = [] if ignored else self.ignorepatches
-
- for num, tag in sorted(tags.iteritems()):
- strip = 0
- if num in macros:
- opts = self._patch_macro_opts(macros[num])
+ if macro['id'] in tags:
+ applied.append((macro['id'], macro['args']))
+ ignored = set() if ignored else set(self.ignorepatches)
+
+ # Put all patches that are applied first in the series
+ for num, args in applied:
+ if num not in ignored:
+ opts = self._patch_macro_opts(args)
strip = int(opts.strip) if opts.strip else 0
- if (unapplied or (num in macros)) and num not in ignored:
- filename = os.path.basename(tag['linevalue'])
+ filename = os.path.basename(tags[num]['linevalue'])
series.append(Patch(os.path.join(self.specdir, filename),
strip=strip))
+ # Finally, append all unapplied patches to the series, if requested
+ if unapplied:
+ applied_nums = set([num for num, _args in applied])
+ unapplied = set(tags.keys()).difference(applied_nums)
+ for num in sorted(unapplied):
+ if num not in ignored:
+ filename = os.path.basename(tags[num]['linevalue'])
+ series.append(Patch(os.path.join(self.specdir,
+ filename), strip=0))
return series
def _guess_orig_prefix(self, orig):
diff --git a/tests/test_rpm.py b/tests/test_rpm.py
index 4d430778..eef2a677 100644
--- a/tests/test_rpm.py
+++ b/tests/test_rpm.py
@@ -275,7 +275,29 @@ class TestSpecFile(object):
assert len(spec.patchseries(ignored=True)) == 1
series = spec.patchseries(unapplied=True, ignored=True)
assert len(series) == 2
- assert os.path.basename(series[-1].path) == '4.patch'
+ assert os.path.basename(series[-1].path) == '1.patch'
+
+ def test_patch_series_quirks(self):
+ """Patches are applied in order different from the patch numbering"""
+ spec_filepath = os.path.join(SPEC_DIR, 'gbp-test-quirks.spec')
+ spec = SpecFileTester(spec_filepath)
+
+ # Check series is returned in the order the patches are applied
+ files = [os.path.basename(patch.path) for patch in spec.patchseries()]
+ assert files == ['05.patch', '01.patch']
+ # Also ignored patches are returned in the correct order
+ files = [os.path.basename(patch.path) for patch in
+ spec.patchseries(ignored=True)]
+ assert files == ['05.patch', '02.patch', '01.patch']
+ # Unapplied patches are added to the end of the series
+ files = [os.path.basename(patch.path) for patch in
+ spec.patchseries(unapplied=True)]
+ assert files == ['05.patch', '01.patch', '03.patch']
+ # Return all patches (for which tag is found)
+ files = [os.path.basename(patch.path) for patch in
+ spec.patchseries(unapplied=True, ignored=True)]
+ assert files == ['05.patch', '02.patch', '01.patch', '03.patch',
+ '04.patch']
class TestUtilityFunctions(object):
diff --git a/tests/test_rpm_data/specs/gbp-test-quirks.spec b/tests/test_rpm_data/specs/gbp-test-quirks.spec
index 64db07fb..bb56b008 100644
--- a/tests/test_rpm_data/specs/gbp-test-quirks.spec
+++ b/tests/test_rpm_data/specs/gbp-test-quirks.spec
@@ -8,6 +8,12 @@ Version: 0.1
Release: 1.2
License: GPLv2
Source1: foobar.tar.gz
+# Gbp-Ignore-Patches: 2 4 888
+Patch1: 01.patch
+Patch2: 02.patch
+Patch3: 03.patch
+Patch4: 04.patch
+Patch5: 05.patch
%description
Spec for testing some quirks of spec parsing. No intended for building an RPM.
@@ -16,3 +22,9 @@ Spec for testing some quirks of spec parsing. No intended for building an RPM.
# We don't have Source0 so rpmbuild would fail, but gbp shouldn't crash
%setup -q
+# Patches are applied out-of-order wrt. numbering
+%patch5
+%patch2
+%patch1
+# Patch 999 does not exist, rpmbuild would fail but GBP should not
+%patch999