def patchseries(self, unapplied=False, ignored=False): """Return non-ignored patches of the RPM as a gbp patchseries""" series = PatchSeries() if 'patch' in self._tags: tags = self._patches() applied = [] for macro in self._special_directives['patch']: 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 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 test_filename(self): """Get patch information from the filename""" p = Patch(os.path.join(self.data_dir, "doesnotexist.diff")) self.assertEqual('doesnotexist', p.subject) self.assertEqual({}, p.info) p = Patch(os.path.join(self.data_dir, "doesnotexist.patch")) self.assertEqual('doesnotexist', p.subject) p = Patch(os.path.join(self.data_dir, "doesnotexist")) self.assertEqual('doesnotexist', p.subject) self.assertEqual(None, p.author) self.assertEqual(None, p.email) self.assertEqual(None, p.date)
def apply_single_patch(repo, patchfile, options): """Apply a single patch onto the pq branch""" current = repo.get_branch() if not is_pq_branch(current, options): switch_to_pq_branch(repo, current, options) patch = Patch(patchfile) apply_and_commit_patch(repo, patch, fallback_author=None)
def main(argv): retval = 0 (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) if len(args) < 2: gbp.log.err("No action given.") return 1 else: action = args[1] if args[1] in ["export", "import", "rebase", "drop", "switch"]: pass elif args[1] in ["apply"]: if len(args) != 3: gbp.log.err("No patch name given.") return 1 else: patchfile = args[2] else: gbp.log.err("Unknown action '%s'." % args[1]) return 1 try: repo = DebianGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: current = repo.get_branch() if action == "export": export_patches(repo, current, options) elif action == "import": import_pq(repo, current, options) elif action == "drop": drop_pq(repo, current) elif action == "rebase": rebase_pq(repo, current, options) elif action == "apply": patch = Patch(patchfile) maintainer = get_maintainer_from_control(repo) apply_single_patch(repo, current, patch, maintainer, options.topic) elif action == "switch": switch_pq(repo, current, options) except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if str(err): gbp.log.err(err) retval = 1 return retval
def bb_to_patch_series(bbfile): """Get all local patches as a series""" series = PatchSeries() for path in bbfile.localfiles: if path.endswith('.patch'): series.append(Patch(path)) return series
def test_header(self): """Get the patch information from a patch header""" patchfile = os.path.join(self.data_dir, "patch1.diff") self.assertTrue(os.path.exists(patchfile)) p = Patch(patchfile) self.assertEqual('This is patch1', p.subject) self.assertEqual("foo", p.author) self.assertEqual("*****@*****.**", p.email) self.assertEqual( "This is the long description.\n" "It can span several lines.\n", p.long_desc) self.assertEqual('Sat, 24 Dec 2011 12:05:53 +0100', p.date)
def format_series_diff(added, removed, options): """ Format the patch differences into a suitable commit message >>> format_series_diff(['a'], ['b'], None) 'Rediff patches\\n\\nAdded a: <REASON>\\nDropped b: <REASON>\\n' """ if len(added) == 1 and not removed: # Single patch added, create a more thorough commit message patch = Patch(os.path.join('debian', 'patches', added[0])) msg = patch.subject bugs, dummy = extract_bts_cmds(patch.long_desc.split('\n'), options) if bugs: msg += '\n' for k, v in bugs.items(): msg += '\n%s: %s' % (k, ', '.join(v)) else: msg = "Rediff patches\n\n" for p in added: msg += 'Added %s: <REASON>\n' % p for p in removed: msg += 'Dropped %s: <REASON>\n' % p return msg
def main(argv): """Main function for the gbp pq-rpm command""" retval = 0 (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) if len(args) < 2: gbp.log.err("No action given.") return 1 else: action = args[1] if args[1] in ["export", "import", "rebase", "drop", "switch", "convert"]: pass elif args[1] in ["apply"]: if len(args) != 3: gbp.log.err("No patch name given.") return 1 else: patchfile = args[2] else: gbp.log.err("Unknown action '%s'." % args[1]) return 1 try: repo = RpmGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: # Create base temporary directory for this run init_tmpdir(options.tmp_dir, prefix='pq-rpm_') current = repo.get_branch() if action == "export": export_patches(repo, options) elif action == "import": import_spec_patches(repo, options) elif action == "drop": drop_pq(repo, current) elif action == "rebase": rebase_pq(repo, options) elif action == "apply": patch = Patch(patchfile) apply_single_patch(repo, current, patch, fallback_author=None) elif action == "switch": switch_pq(repo, current) except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) retval = 1 except GbpError as err: if str(err): gbp.log.err(err) retval = 1 finally: del_tmpdir() return retval
def main(argv): retval = 0 (options, args) = parse_args(argv) if not options: return 1 gbp.log.setup(options.color, options.verbose, options.color_scheme) if len(args) < 2: gbp.log.err("No action given.") return 1 else: action = args[1] if args[1] in ["export", "import", "rebase", "drop", "switch"]: pass elif args[1] in ["apply"]: if len(args) != 3: gbp.log.err("No patch name given.") return 1 else: patchfile = args[2] else: gbp.log.err("Unknown action '%s'." % args[1]) return 1 try: repo = GitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: current = repo.get_branch() if action == "export": export_patches(repo, current, options) elif action == "import": series = SERIES_FILE tries = options.time_machine if (options.time_machine > 0) else 1 import_quilt_patches(repo, current, series, tries, options.force) current = repo.get_branch() gbp.log.info("Patches listed in '%s' imported on '%s'" % (series, current)) elif action == "drop": drop_pq(repo, current) elif action == "rebase": rebase_pq(repo, current) elif action == "apply": patch = Patch(patchfile) maintainer = get_maintainer_from_control(repo) apply_single_patch(repo, current, patch, maintainer, options.topic) elif action == "switch": switch_pq(repo, current) except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if len(err.__str__()): gbp.log.err(err) retval = 1 return retval