summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-01-04 14:42:25 +0200
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-04-03 10:11:41 +0300
commit47b92482997f6d8f784443ff2eeef4c7d6738dc8 (patch)
treec96ffc28e58e15d203ae4c361f12871f81781759
parent747fe85405214816087536047d15da05668c36fd (diff)
downloadgit-buildpackage-47b92482997f6d8f784443ff2eeef4c7d6738dc8.tar.gz
git-buildpackage-47b92482997f6d8f784443ff2eeef4c7d6738dc8.tar.bz2
git-buildpackage-47b92482997f6d8f784443ff2eeef4c7d6738dc8.zip
rpm: make SpecFile.update_patches() use new tag/macro methods
Use new set/delete methods for updating the patches in the spec file. The internal patches structure is not updated and now only used when importing patches. Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r--gbp/rpm/__init__.py102
1 files changed, 43 insertions, 59 deletions
diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py
index b1152384..059a8169 100644
--- a/gbp/rpm/__init__.py
+++ b/gbp/rpm/__init__.py
@@ -573,99 +573,83 @@ class SpecFile(object):
def update_patches(self, patchfilenames):
"""Update spec with new patch tags and patch macros"""
# Remove non-ignored patches
- last_removed_tag_line = None
- last_removed_macro_line = None
- for num, patch in self.patches.items():
- if patch['autoupdate']:
+ tag_prev = None
+ macro_prev = None
+ ignored = self.ignorepatches
+ # Remove 'Patch:̈́' tags
+ for tag in self._tags['patch']['lines']:
+ if not tag['num'] in ignored:
+ tag_prev = self._delete_tag('patch', tag['num'])
# Remove a preceding comment if it seems to originate from GBP
- prev_line = patch['tag_line'].prev
if re.match("^\s*#.*patch.*auto-generated",
- str(prev_line), flags=re.I):
- self._content.delete(prev_line)
- last_removed_tag_line = patch['tag_line'].prev
- self._content.delete(patch['tag_line'])
- if patch['macro_line']:
- # Remove a preceding comment line if it ends with
- # '.patch' or '.diff' plus an optional compression suffix
- prev_line = patch['macro_line'].prev
- if re.match("^\s*#.+(patch|diff)(\.(gz|bz2|xz|lzma))?\s*$",
- str(prev_line), flags=re.I):
- self._content.delete(prev_line)
- last_removed_macro_line = patch['macro_line'].prev
- self._content.delete(patch['macro_line'])
- # Remove from the patch list
- self.patches.pop(num)
+ str(tag_prev), flags=re.I):
+ tag_prev = self._content.delete(tag_prev)
+
+ # Remove '%patch:' macros
+ for macro in self._special_directives['patch']:
+ if not macro['id'] in ignored:
+ # Remove a preceding comment line if it ends with '.patch' or
+ # '.diff' plus an optional compression suffix
+ macro_prev = self._delete_special_macro('patch', macro['id'])
+ if re.match("^\s*#.+(patch|diff)(\.(gz|bz2|xz|lzma))?\s*$",
+ str(macro_prev), flags=re.I):
+ macro_prev = self._content.delete(macro_prev)
if len(patchfilenames) == 0:
return
- # Add new patches to the patch list
- patchnum = sorted(self.patches.keys())[-1] + 1 if self.patches else 0
- gbp.log.debug("Starting autoupdate patch numbering from %s" % patchnum)
- for ind, name in enumerate(patchfilenames):
- self.patches[patchnum + ind] = {
- 'name': name, 'filename': name, 'apply': True, 'strip': '1',
- 'macro_line': None, 'autoupdate': True, 'tag_line': None}
-
# Determine where to add Patch tag lines
- if last_removed_tag_line:
+ if tag_prev:
gbp.log.info("Adding 'Patch' tags in place of the removed tags")
- line = last_removed_tag_line
+ tag_line = tag_prev
elif 'patch' in self._tags:
gbp.log.info("Adding new 'Patch' tags after the last 'Patch' tag")
- line = self._tags['patch']['lines'][-1]['line']
+ tag_line = self._tags['patch']['lines'][-1]['line']
elif 'source' in self._tags:
gbp.log.info("Didn't find any old 'Patch' tags, adding new "
"patches after the last 'Source' tag.")
- line = self._tags['source']['lines'][-1]['line']
+ tag_line = self._tags['source']['lines'][-1]['line']
else:
gbp.log.info("Didn't find any old 'Patch' or 'Source' tags, "
"adding new patches after the last 'Name' tag.")
- line = self._tags['name']['lines'][-1]['line']
-
- # Add all patch tag lines to content, in reversed order
- for n in reversed(sorted(self.patches.keys())):
- patch = self.patches[n]
- if patch['autoupdate']:
- # "PatchXYZ:" text 12 chars wide, left aligned
- text = "%-12s%s\n" % ("Patch%d:" % n, patch['name'])
- patch['tag_line'] = self._content.insert_after(line, text)
- # Finally, add a comment indicating gbp generated patches
- self._content.insert_after(line, "# Patches auto-generated by "
- "git-buildpackage:\n")
+ tag_line = self._tags['name']['lines'][-1]['line']
# Determine where to add %patch macro lines
if 'patch-macros' in self._gbp_tags:
gbp.log.info("Adding '%patch' macros after the start marker")
- line = self._gbp_tags['patch-macros'][-1]['line']
- elif last_removed_macro_line:
+ macro_line = self._gbp_tags['patch-macros'][-1]['line']
+ elif macro_prev:
gbp.log.info("Adding '%patch' macros in place of the removed "
"macros")
- line = last_removed_macro_line
+ macro_line = macro_prev
elif self._special_directives['patch']:
gbp.log.info("Adding new '%patch' macros after the last existing"
"'%patch' macro")
- line = self._special_directives['patch'][-1]['line']
+ macro_line = self._special_directives['patch'][-1]['line']
elif self._special_directives['setup']:
gbp.log.info("Didn't find any old '%patch' macros, adding new "
"patches after the last '%setup' macro")
- line = self._special_directives['setup'][-1]['line']
+ macro_line = self._special_directives['setup'][-1]['line']
elif self._special_directives['prep']:
gbp.log.warn("Didn't find any old '%patch' or '%setup' macros, "
"adding new patches directly after '%prep' directive")
- line = self._special_directives['prep'][-1]['line']
+ macro_line = self._special_directives['prep'][-1]['line']
else:
raise GbpError("Couldn't determine where to add '%patch' macros")
- # Add all patch macro lines to content, in reversed order
- for n in reversed(sorted(self.patches.keys())):
- patch = self.patches[n]
- if patch['autoupdate'] and patch['apply']:
- # We're adding from bottom to top...
- text = "%%patch%d -p%s\n" % (n, patch['strip'])
- patch['macro_line'] = self._content.insert_after(line, text)
- # Use 'name', that is filename with macros not expanded
- self._content.insert_after(line, "# %s\n" % patch['name'])
+ startnum = sorted(ignored)[-1] + 1 if ignored else 0
+ gbp.log.debug("Starting autoupdate patch numbering from %s" % startnum)
+ # Add a comment indicating gbp generated patch tags
+ comment_text = "# Patches auto-generated by git-buildpackage:\n"
+ tag_line = self._content.insert_after(tag_line, comment_text)
+ for ind, name in enumerate(patchfilenames):
+ patchnum = startnum + ind
+ tag_line = self._set_tag("Patch", patchnum, name, tag_line)
+ # Add '%patch' macro and a preceding comment line
+ comment_text = "# %s\n" % name
+ macro_line = self._content.insert_after(macro_line, comment_text)
+ macro_line = self._set_special_macro('patch', patchnum, '-p1',
+ macro_line)
def patchseries(self):
"""