# HG changeset patch # User Dirkjan Ochtman # Date 2009-06-19 11:58:22 # Node ID 14639c050251b10800ad1d30614f8b3de96557e2 # Parent 6e6f5b80e0561440368761985928615fde085cc0 mq: unify code for qdel -r and qfin diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -616,47 +616,51 @@ class queue(object): break return (err, n) - def _clean_series(self, patches): + def _cleanup(self, patches, numrevs, keep=False): + if not keep: + r = self.qrepo() + if r: + r.remove(patches, True) + else: + for p in patches: + os.unlink(self.join(p)) + + if numrevs: + del self.applied[:numrevs] + self.applied_dirty = 1 + for i in sorted([self.find_series(p) for p in patches], reverse=True): del self.full_series[i] self.parse_series() self.series_dirty = 1 - def finish(self, repo, revs): + def _revpatches(self, repo, revs): firstrev = repo[self.applied[0].rev].rev() - appliedbase = 0 patches = [] - for rev in sorted(revs): + for i, rev in enumerate(revs): if rev < firstrev: raise util.Abort(_('revision %d is not managed') % rev) - base = bin(self.applied[appliedbase].rev) ctx = repo[rev] + base = bin(self.applied[i].rev) if ctx.node() != base: msg = _('cannot delete revision %d above applied patches') raise util.Abort(msg % rev) - patch = self.applied[appliedbase].name + patch = self.applied[i].name for fmt in ('[mq]: %s', 'imported patch %s'): if ctx.description() == fmt % patch: msg = _('patch %s finalized without changeset message\n') repo.ui.status(msg % patch) break - patches.append(self.applied[appliedbase].name) - appliedbase += 1 + patches.append(patch) + return patches - r = self.qrepo() - if r: - r.remove(patches, True) - else: - for p in patches: - os.unlink(self.join(p)) - - del self.applied[:appliedbase] - self.applied_dirty = 1 - self._clean_series(patches) + def finish(self, repo, revs): + patches = self._revpatches(repo, sorted(revs)) + self._cleanup(patches, len(patches)) def delete(self, repo, patches, opts): if not patches and not opts.get('rev'): @@ -673,37 +677,18 @@ class queue(object): raise util.Abort(_("patch %s not in series file") % patch) realpatches.append(patch) - appliedbase = 0 + numrevs = 0 if opts.get('rev'): if not self.applied: raise util.Abort(_('no patches applied')) revs = cmdutil.revrange(repo, opts['rev']) if len(revs) > 1 and revs[0] > revs[1]: revs.reverse() - for rev in revs: - if appliedbase >= len(self.applied): - raise util.Abort(_("revision %d is not managed") % rev) - - base = bin(self.applied[appliedbase].rev) - node = repo.changelog.node(rev) - if node != base: - raise util.Abort(_("cannot delete revision %d above " - "applied patches") % rev) - realpatches.append(self.applied[appliedbase].name) - appliedbase += 1 + revpatches = self._revpatches(repo, revs) + realpatches += revpatches + numrevs = len(revpatches) - if not opts.get('keep'): - r = self.qrepo() - if r: - r.remove(realpatches, True) - else: - for p in realpatches: - os.unlink(self.join(p)) - - if appliedbase: - del self.applied[:appliedbase] - self.applied_dirty = 1 - self._clean_series(realpatches) + self._cleanup(realpatches, numrevs, opts.get('keep')) def check_toppatch(self, repo): if len(self.applied) > 0: diff --git a/tests/test-hardlinks-safety.out b/tests/test-hardlinks-safety.out --- a/tests/test-hardlinks-safety.out +++ b/tests/test-hardlinks-safety.out @@ -15,6 +15,8 @@ bar 430ed4828a74fa4047bc816a25500f7472ab4bfe:foo % foo +patch foo finalized without changeset message +patch bar finalized without changeset message %%% 4e7abb4840c46a910f6d7b4d3c3fc7e5209e684c foo 430ed4828a74fa4047bc816a25500f7472ab4bfe bar diff --git a/tests/test-mq-qdelete.out b/tests/test-mq-qdelete.out --- a/tests/test-mq-qdelete.out +++ b/tests/test-mq-qdelete.out @@ -13,9 +13,12 @@ a b series status +patch a finalized without changeset message 1 [mq]: a 0 base abort: cannot delete revision 3 above applied patches +patch d finalized without changeset message +patch e finalized without changeset message f 4 [mq]: f 3 [mq]: e