hgext/mq.py
changeset 2757 787e18b84893
parent 2756 caa6d992608b
parent 2752 5dfeda163bb7
child 2765 0327bd1c831c
--- a/hgext/mq.py	Tue Aug 01 15:24:18 2006 -0700
+++ b/hgext/mq.py	Tue Aug 01 15:40:28 2006 -0700
@@ -382,13 +382,19 @@
         tr.close()
         return (err, n)
 
-    def delete(self, repo, patch):
+    def delete(self, repo, patch, force=False):
         patch = self.lookup(patch, strict=True)
         info = self.isapplied(patch)
         if info:
             raise util.Abort(_("cannot delete applied patch %s") % patch)
         if patch not in self.series:
             raise util.Abort(_("patch %s not in series file") % patch)
+        if force:
+            r = self.qrepo()
+            if r:
+                r.remove([patch], True)
+            else:
+                os.unlink(os.path.join(self.path, patch))
         i = self.find_series(patch)
         del self.full_series[i]
         self.read_series(self.full_series)
@@ -1165,9 +1171,12 @@
             qrepo.add(added)
 
 def delete(ui, repo, patch, **opts):
-    """remove a patch from the series file"""
+    """remove a patch from the series file
+
+    The patch must not be applied.
+    With -f, deletes the patch file as well as the series entry."""
     q = repo.mq
-    q.delete(repo, patch)
+    q.delete(repo, patch, force=opts.get('force'))
     q.save_dirty()
     return 0
 
@@ -1448,6 +1457,56 @@
     q.save_dirty()
     return 0
 
+def rename(ui, repo, patch, name=None, **opts):
+    """rename a patch
+
+    With one argument, renames the current patch to PATCH1.
+    With two arguments, renames PATCH1 to PATCH2."""
+
+    q = repo.mq
+
+    if not name:
+        name = patch
+        patch = None
+
+    if name in q.series:
+        raise util.Abort(_('A patch named %s already exists in the series file') % name)
+
+    absdest = os.path.join(q.path, name)
+    if os.path.exists(absdest):
+        raise util.Abort(_('%s already exists') % absdest)
+    
+    if patch:
+        patch = q.lookup(patch)
+    else:
+        if not q.applied:
+            ui.write(_('No patches applied\n'))
+            return
+        patch = q.lookup('qtip')
+
+    if ui.verbose:
+        ui.write('Renaming %s to %s\n' % (patch, name))
+    i = q.find_series(patch)
+    q.full_series[i] = name
+    q.read_series(q.full_series)
+    q.series_dirty = 1
+
+    info = q.isapplied(patch)
+    if info:
+        q.applied[info[0]] = info[1] + ':' + name
+    q.applied_dirty = 1
+
+    util.rename(os.path.join(q.path, patch), absdest)
+    r = q.qrepo()
+    if r:
+        wlock = r.wlock()
+        if r.dirstate.state(name) == 'r':
+            r.undelete([name], wlock)
+        r.copy(patch, name, wlock)
+        r.remove([patch], False, wlock)
+
+    q.save_dirty()
+
 def restore(ui, repo, rev, **opts):
     """restore the queue state saved by a rev"""
     rev = repo.lookup(rev)
@@ -1546,7 +1605,10 @@
          commands.table["^commit|ci"][1],
          'hg qcommit [OPTION]... [FILE]...'),
     "^qdiff": (diff, [], 'hg qdiff [FILE]...'),
-    "qdelete": (delete, [], 'hg qdelete PATCH'),
+    "qdelete":
+        (delete,
+         [('f', 'force', None, _('delete patch file'))],
+          'hg qdelete [-f] PATCH'),
     'qfold':
         (fold,
          [('e', 'edit', None, _('edit patch header')),
@@ -1594,6 +1656,8 @@
           ('l', 'logfile', '', _('change commit message with <file> content')),
           ('s', 'short', None, 'short refresh')],
          'hg qrefresh [-e] [-m TEXT] [-l FILE] [-s]'),
+    'qrename|qmv':
+        (rename, [], 'hg qrename PATCH1 [PATCH2]'),
     "qrestore":
         (restore,
          [('d', 'delete', None, 'delete save entry'),