[PATCH] support -k for qfinish

Weijun Wang weijun.wang at oracle.com
Mon Oct 24 00:51:04 CDT 2011

mq: keep the patch file after it's committed

I'd like the patch file(s) kept in .hg/patches even after moved to
repository history. To achieve this, we can add a -k option (as in


# HG changeset patch
# User weijun
# Date 1319435107 -28800
# Node ID 14adf3b3ef067de482ab56707ca4130eca2e27d7
# Parent  48d552eb8d43ee671f5799b191f15c2447e8de68
Support -k for qfinish

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -797,9 +797,9 @@
          return patches

-    def finish(self, repo, revs):
+    def finish(self, repo, revs, keep=False):
          patches = self._revpatches(repo, sorted(revs))
-        self._cleanup(patches, len(patches))
+        self._cleanup(patches, len(patches), keep)

      def delete(self, repo, patches, opts):
          if not patches and not opts.get('rev'):
@@ -2886,8 +2886,9 @@

-         [('a', 'applied', None, _('finish all applied changesets'))],
-         _('hg qfinish [-a] [REV]...'))
+         [('k', 'keep', None, _('keep patch file')),
+          ('a', 'applied', None, _('finish all applied changesets'))],
+         _('hg qfinish [-k] [-a] [REV]...'))
  def finish(ui, repo, *revrange, **opts):
      """move applied patches into repository history

@@ -2898,7 +2899,8 @@
      Accepts a revision range or the -a/--applied option. If --applied
      is specified, all applied mq revisions are removed from mq
      control. Otherwise, the given revisions must be at the base of the
-    stack of applied patches.
+    stack of applied patches.  With -k/--keep, the patch files are
+    preserved in the patch directory.

      This can be especially useful if your changes have been applied to
      an upstream repository, or if you are about to push your changes
@@ -2917,7 +2919,7 @@
          return 0

      revs = scmutil.revrange(repo, revrange)
-    q.finish(repo, revs)
+    q.finish(repo, revs, opts.get('keep'))
      return 0

More information about the Mercurial-devel mailing list