--- a/hgext/mq.py Fri Jun 19 12:37:29 2009 +0200
+++ b/hgext/mq.py Fri Jun 19 13:58:22 2009 +0200
@@ -616,47 +616,51 @@
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 @@
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:
--- a/tests/test-hardlinks-safety.out Fri Jun 19 12:37:29 2009 +0200
+++ b/tests/test-hardlinks-safety.out Fri Jun 19 13:58:22 2009 +0200
@@ -15,6 +15,8 @@
430ed4828a74fa4047bc816a25500f7472ab4bfe:foo
%
foo
+patch foo finalized without changeset message
+patch bar finalized without changeset message
%%%
4e7abb4840c46a910f6d7b4d3c3fc7e5209e684c foo
430ed4828a74fa4047bc816a25500f7472ab4bfe bar
--- a/tests/test-mq-qdelete.out Fri Jun 19 12:37:29 2009 +0200
+++ b/tests/test-mq-qdelete.out Fri Jun 19 13:58:22 2009 +0200
@@ -13,9 +13,12 @@
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