mq: rename --check into --keep-changes
authorPatrick Mezard <patrick@mezard.eu>
Sun, 13 May 2012 14:00:58 +0200
changeset 16733 4da10c00a20c
parent 16732 277e2acb7e5c
child 16740 43cfe56121d3
mq: rename --check into --keep-changes I named it --check because it felt like qpush & co were checking *more* things to ensure local changes could not be lost. But it has been pointed on the mailing list that --check is already used by update command with a meaning almost opposite to this one. An alternative was --keep but qfold and qdelete already have such an option to preserve patch files and qfold may be a candidate for --check. - qpush/qpop/qgoto --check becomes --keep-changes. - mq.check becomes mq.keepchanges. - The short option -c is dropped as -k may conflict with existing --keep. The availabilitity of mq.keepchanges should not make this too painful. - Fix minor reST mistake in option description.
hgext/mq.py
tests/test-mq-qpush-fail.t
tests/test-mq.t
--- a/hgext/mq.py	Sun May 13 11:56:50 2012 +0200
+++ b/hgext/mq.py	Sun May 13 14:00:58 2012 +0200
@@ -49,12 +49,12 @@
 
 If the working directory contains uncommitted files, qpush, qpop and
 qgoto abort immediately. If -f/--force is used, the changes are
-discarded. Setting:
+discarded. Setting::
 
   [mq]
-  check = True
-
-make them behave as if -c/--check were passed, and non-conflicting
+  keepchanges = True
+
+make them behave as if --keep-changes were passed, and non-conflicting
 local changes will be tolerated and preserved. If incompatible options
 such as -f/--force or --exact are passed, this setting is ignored.
 '''
@@ -695,7 +695,7 @@
 
     def apply(self, repo, series, list=False, update_status=True,
               strict=False, patchdir=None, merge=None, all_files=None,
-              tobackup=None, check=False):
+              tobackup=None, keepchanges=False):
         wlock = lock = tr = None
         try:
             wlock = repo.wlock()
@@ -704,7 +704,7 @@
             try:
                 ret = self._apply(repo, series, list, update_status,
                                   strict, patchdir, merge, all_files=all_files,
-                                  tobackup=tobackup, check=check)
+                                  tobackup=tobackup, keepchanges=keepchanges)
                 tr.close()
                 self.savedirty()
                 return ret
@@ -726,7 +726,7 @@
 
     def _apply(self, repo, series, list=False, update_status=True,
                strict=False, patchdir=None, merge=None, all_files=None,
-               tobackup=None, check=False):
+               tobackup=None, keepchanges=False):
         """returns (error, hash)
 
         error = 1 for unable to read, 2 for patch failed, 3 for patch
@@ -767,7 +767,7 @@
                 if tobackup:
                     touched = patchmod.changedfiles(self.ui, repo, pf)
                     touched = set(touched) & tobackup
-                    if touched and check:
+                    if touched and keepchanges:
                         raise AbortNoCleanup(
                             _("local changes found, refresh first"))
                     self.backup(repo, touched, copy=True)
@@ -980,9 +980,9 @@
             else:
                 raise util.Abort(_('patch "%s" already exists') % name)
 
-    def checkforcecheck(self, check, force):
-        if force and check:
-            raise util.Abort(_('cannot use both --force and --check'))
+    def checkkeepchanges(self, keepchanges, force):
+        if force and keepchanges:
+            raise util.Abort(_('cannot use both --force and --keep-changes'))
 
     def new(self, repo, patchfn, *pats, **opts):
         """options:
@@ -1182,8 +1182,9 @@
         raise util.Abort(_("patch %s not in series") % patch)
 
     def push(self, repo, patch=None, force=False, list=False, mergeq=None,
-             all=False, move=False, exact=False, nobackup=False, check=False):
-        self.checkforcecheck(check, force)
+             all=False, move=False, exact=False, nobackup=False,
+             keepchanges=False):
+        self.checkkeepchanges(keepchanges, force)
         diffopts = self.diffopts()
         wlock = repo.wlock()
         try:
@@ -1238,13 +1239,13 @@
             if start == len(self.series):
                 self.ui.warn(_('patch series already fully applied\n'))
                 return 1
-            if not force and not check:
+            if not force and not keepchanges:
                 self.checklocalchanges(repo, refresh=self.applied)
 
             if exact:
-                if check:
+                if keepchanges:
                     raise util.Abort(
-                        _("cannot use --exact and --check together"))
+                        _("cannot use --exact and --keep-changes together"))
                 if move:
                     raise util.Abort(_('cannot use --exact and --move '
                                        'together'))
@@ -1288,9 +1289,9 @@
                 end = self.series.index(patch, start) + 1
 
             tobackup = set()
-            if (not nobackup and force) or check:
+            if (not nobackup and force) or keepchanges:
                 m, a, r, d = self.checklocalchanges(repo, force=True)
-                if check:
+                if keepchanges:
                     tobackup.update(m + a + r + d)
                 else:
                     tobackup.update(m + a)
@@ -1302,7 +1303,7 @@
                     ret = self.mergepatch(repo, mergeq, s, diffopts)
                 else:
                     ret = self.apply(repo, s, list, all_files=all_files,
-                                     tobackup=tobackup, check=check)
+                                     tobackup=tobackup, keepchanges=keepchanges)
             except: # re-raises
                 self.ui.warn(_('cleaning up working directory...'))
                 node = repo.dirstate.p1()
@@ -1333,8 +1334,8 @@
             wlock.release()
 
     def pop(self, repo, patch=None, force=False, update=True, all=False,
-            nobackup=False, check=False):
-        self.checkforcecheck(check, force)
+            nobackup=False, keepchanges=False):
+        self.checkkeepchanges(keepchanges, force)
         wlock = repo.wlock()
         try:
             if patch:
@@ -1381,11 +1382,12 @@
 
             tobackup = set()
             if update:
-                m, a, r, d = self.checklocalchanges(repo, force=force or check)
+                m, a, r, d = self.checklocalchanges(
+                    repo, force=force or keepchanges)
                 if force:
                     if not nobackup:
                         tobackup.update(m + a)
-                elif check:
+                elif keepchanges:
                     tobackup.update(m + a + r + d)
 
             self.applieddirty = True
@@ -1418,7 +1420,7 @@
                     raise util.Abort(_("deletions found between repo revs"))
 
                 tobackup = set(a + m + r) & tobackup
-                if check and tobackup:
+                if keepchanges and tobackup:
                     self.localchangesfound()
                 self.backup(repo, tobackup)
 
@@ -1999,12 +2001,12 @@
         self.removeundo(repo)
         return imported
 
-def fixcheckopts(ui, opts):
-    if (not ui.configbool('mq', 'check') or opts.get('force')
+def fixkeepchangesopts(ui, opts):
+    if (not ui.configbool('mq', 'keepchanges') or opts.get('force')
         or opts.get('exact')):
         return opts
     opts = dict(opts)
-    opts['check'] = True
+    opts['keep_changes'] = True
     return opts
 
 @command("qdelete|qremove|qrm",
@@ -2548,7 +2550,8 @@
         wlock.release()
 
 @command("qgoto",
-         [('c', 'check', None, _('tolerate non-conflicting local changes')),
+         [('', 'keep-changes', None,
+           _('tolerate non-conflicting local changes')),
           ('f', 'force', None, _('overwrite any local changes')),
           ('', 'no-backup', None, _('do not save backup copies of files'))],
          _('hg qgoto [OPTION]... PATCH'))
@@ -2556,17 +2559,17 @@
     '''push or pop patches until named patch is at top of stack
 
     Returns 0 on success.'''
-    opts = fixcheckopts(ui, opts)
+    opts = fixkeepchangesopts(ui, opts)
     q = repo.mq
     patch = q.lookup(patch)
     nobackup = opts.get('no_backup')
-    check = opts.get('check')
+    keepchanges = opts.get('keep_changes')
     if q.isapplied(patch):
         ret = q.pop(repo, patch, force=opts.get('force'), nobackup=nobackup,
-                    check=check)
+                    keepchanges=keepchanges)
     else:
         ret = q.push(repo, patch, force=opts.get('force'), nobackup=nobackup,
-                     check=check)
+                     keepchanges=keepchanges)
     q.savedirty()
     return ret
 
@@ -2687,7 +2690,8 @@
     return newpath
 
 @command("^qpush",
-         [('c', 'check', None, _('tolerate non-conflicting local changes')),
+         [('', 'keep-changes', None,
+           _('tolerate non-conflicting local changes')),
           ('f', 'force', None, _('apply on top of local changes')),
           ('e', 'exact', None,
            _('apply the target patch to its recorded parent')),
@@ -2704,7 +2708,7 @@
     """push the next patch onto the stack
 
     By default, abort if the working directory contains uncommitted
-    changes. With -c/--check, abort only if the uncommitted files
+    changes. With --keep-changes, abort only if the uncommitted files
     overlap with patched files. With -f/--force, backup and patch over
     uncommitted changes.
 
@@ -2713,7 +2717,7 @@
     q = repo.mq
     mergeq = None
 
-    opts = fixcheckopts(ui, opts)
+    opts = fixkeepchangesopts(ui, opts)
     if opts.get('merge'):
         if opts.get('name'):
             newpath = repo.join(opts.get('name'))
@@ -2727,14 +2731,15 @@
     ret = q.push(repo, patch, force=opts.get('force'), list=opts.get('list'),
                  mergeq=mergeq, all=opts.get('all'), move=opts.get('move'),
                  exact=opts.get('exact'), nobackup=opts.get('no_backup'),
-                 check=opts.get('check'))
+                 keepchanges=opts.get('keep_changes'))
     return ret
 
 @command("^qpop",
          [('a', 'all', None, _('pop all patches')),
           ('n', 'name', '',
            _('queue name to pop (DEPRECATED)'), _('NAME')),
-          ('c', 'check', None, _('tolerate non-conflicting local changes')),
+          ('', 'keep-changes', None,
+           _('tolerate non-conflicting local changes')),
           ('f', 'force', None, _('forget any local changes to patched files')),
           ('', 'no-backup', None, _('do not save backup copies of files'))],
          _('hg qpop [-a] [-f] [PATCH | INDEX]'))
@@ -2746,13 +2751,13 @@
     the top of the stack.
 
     By default, abort if the working directory contains uncommitted
-    changes. With -c/--check, abort only if the uncommitted files
+    changes. With --keep-changes, abort only if the uncommitted files
     overlap with patched files. With -f/--force, backup and discard
     changes made to such files.
 
     Return 0 on success.
     """
-    opts = fixcheckopts(ui, opts)
+    opts = fixkeepchangesopts(ui, opts)
     localupdate = True
     if opts.get('name'):
         q = queue(ui, repo.path, repo.join(opts.get('name')))
@@ -2762,7 +2767,7 @@
         q = repo.mq
     ret = q.pop(repo, patch, force=opts.get('force'), update=localupdate,
                 all=opts.get('all'), nobackup=opts.get('no_backup'),
-                check=opts.get('check'))
+                keepchanges=opts.get('keep_changes'))
     q.savedirty()
     return ret
 
--- a/tests/test-mq-qpush-fail.t	Sun May 13 11:56:50 2012 +0200
+++ b/tests/test-mq-qpush-fail.t	Sun May 13 14:00:58 2012 +0200
@@ -202,37 +202,37 @@
   $ test -f a.orig && echo 'error: backup with --no-backup'
   [1]
 
-test qpop --check
+test qpop --keep-changes
 
   $ hg qpush
   applying p1
   now at: p1
-  $ hg qpop --check --force
-  abort: cannot use both --force and --check
+  $ hg qpop --keep-changes --force
+  abort: cannot use both --force and --keep-changes
   [255]
   $ echo a >> a
-  $ hg qpop --check
+  $ hg qpop --keep-changes
   abort: local changes found, refresh first
   [255]
   $ hg revert -qa a
   $ rm a
-  $ hg qpop --check
+  $ hg qpop --keep-changes
   abort: local changes found, refresh first
   [255]
   $ hg rm -A a
-  $ hg qpop --check
+  $ hg qpop --keep-changes
   abort: local changes found, refresh first
   [255]
   $ hg revert -qa a
   $ echo b > b
   $ hg add b
-  $ hg qpop --check
+  $ hg qpop --keep-changes
   abort: local changes found, refresh first
   [255]
   $ hg forget b
   $ echo d > d
   $ hg add d
-  $ hg qpop --check
+  $ hg qpop --keep-changes
   popping p1
   patch queue now empty
   $ hg forget d
@@ -318,33 +318,33 @@
   $ test -f a.orig && echo 'error: backup with --no-backup'
   [1]
 
-test qpush --check
+test qpush --keep-changes
 
-  $ hg qpush --check --force
-  abort: cannot use both --force and --check
+  $ hg qpush --keep-changes --force
+  abort: cannot use both --force and --keep-changes
   [255]
-  $ hg qpush --check --exact
-  abort: cannot use --exact and --check together
+  $ hg qpush --keep-changes --exact
+  abort: cannot use --exact and --keep-changes together
   [255]
   $ echo b >> b
-  $ hg qpush --check
+  $ hg qpush --keep-changes
   applying p3
   errors during apply, please fix and refresh p2
   [2]
   $ rm b
-  $ hg qpush --check
+  $ hg qpush --keep-changes
   applying p3
   errors during apply, please fix and refresh p2
   [2]
   $ hg rm -A b
-  $ hg qpush --check
+  $ hg qpush --keep-changes
   applying p3
   errors during apply, please fix and refresh p2
   [2]
   $ hg revert -aq b
   $ echo d > d
   $ hg add d
-  $ hg qpush --check
+  $ hg qpush --keep-changes
   applying p3
   errors during apply, please fix and refresh p2
   [2]
@@ -354,7 +354,7 @@
   popping p2
   patch queue now empty
   $ echo b >> b
-  $ hg qpush -a --check
+  $ hg qpush -a --keep-changes
   applying p2
   applying p3
   errors during apply, please fix and refresh p2
@@ -369,48 +369,48 @@
   b
   b
 
-test qgoto --check
+test qgoto --keep-changes
 
   $ hg revert -aq b
   $ rm e
-  $ hg qgoto --check --force p3
-  abort: cannot use both --force and --check
+  $ hg qgoto --keep-changes --force p3
+  abort: cannot use both --force and --keep-changes
   [255]
   $ echo a >> a
-  $ hg qgoto --check p3
+  $ hg qgoto --keep-changes p3
   applying p3
   now at: p3
   $ hg st a
   M a
-  $ hg qgoto --check p2
+  $ hg qgoto --keep-changes p2
   popping p3
   now at: p2
   $ hg st a
   M a
 
-test mq.check setting
+test mq.keepchanges setting
 
-  $ hg --config mq.check=1 qpush
+  $ hg --config mq.keepchanges=1 qpush
   applying p3
   now at: p3
   $ hg st a
   M a
-  $ hg --config mq.check=1 qpop
+  $ hg --config mq.keepchanges=1 qpop
   popping p3
   now at: p2
   $ hg st a
   M a
-  $ hg --config mq.check=1 qgoto p3
+  $ hg --config mq.keepchanges=1 qgoto p3
   applying p3
   now at: p3
   $ hg st a
   M a
   $ echo b >> b
-  $ hg --config mq.check=1 qpop --force
+  $ hg --config mq.keepchanges=1 qpop --force
   popping p3
   now at: p2
   $ hg st b
-  $ hg --config mq.check=1 qpush --exact
+  $ hg --config mq.keepchanges=1 qpush --exact
   abort: local changes found, refresh first
   [255]
   $ hg revert -qa a
@@ -418,7 +418,7 @@
   popping p2
   patch queue now empty
   $ echo a >> a
-  $ hg --config mq.check=1 qpush --force
+  $ hg --config mq.keepchanges=1 qpush --force
   applying p2
   now at: p2
   $ hg st a
--- a/tests/test-mq.t	Sun May 13 11:56:50 2012 +0200
+++ b/tests/test-mq.t	Sun May 13 14:00:58 2012 +0200
@@ -62,9 +62,10 @@
   If the working directory contains uncommitted files, qpush, qpop and qgoto
   abort immediately. If -f/--force is used, the changes are discarded. Setting:
   
-    [mq] check = True
+    [mq]
+    keepchanges = True
   
-  make them behave as if -c/--check were passed, and non-conflicting local
+  make them behave as if --keep-changes were passed, and non-conflicting local
   changes will be tolerated and preserved. If incompatible options such as
   -f/--force or --exact are passed, this setting is ignored.