[PATCH] commands: don't infer repo for commands like update (issue2748)

Siddharth Agarwal sid0 at fb.com
Tue Oct 16 13:51:07 CDT 2012


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1350412995 25200
# Node ID b47eb532b161bd1093bfa50d7d1f75a6b346cc29
# Parent  78d828137d39cc7999631d9e2dc6535e3b4e8a91
commands: don't infer repo for commands like update (issue2748)

Maintain a whitelist of commands to infer the repo for instead. The whitelist
contains those commands that take file(s) in the working dir as arguments.

diff -r 78d828137d39 -r b47eb532b161 hgext/children.py
--- a/hgext/children.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/children.py	Tue Oct 16 11:43:15 2012 -0700
@@ -14,7 +14,7 @@
 "children(REV)"` instead.
 '''
 
-from mercurial import cmdutil
+from mercurial import cmdutil, commands
 from mercurial.commands import templateopts
 from mercurial.i18n import _
 
@@ -48,3 +48,5 @@
          ] + templateopts,
          _('hg children [-r REV] [FILE]')),
 }
+
+commands.inferrepo += " children"
diff -r 78d828137d39 -r b47eb532b161 hgext/churn.py
--- a/hgext/churn.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/churn.py	Tue Oct 16 11:43:15 2012 -0700
@@ -197,3 +197,5 @@
           ] + commands.walkopts,
          _("hg churn [-d DATE] [-r REV] [--aliases FILE] [FILE]")),
 }
+
+commands.inferrepo += " churn"
diff -r 78d828137d39 -r b47eb532b161 hgext/extdiff.py
--- a/hgext/extdiff.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/extdiff.py	Tue Oct 16 11:43:15 2012 -0700
@@ -329,3 +329,5 @@
         cmdtable[cmd] = (save(cmd, path, diffopts),
                          cmdtable['extdiff'][1][1:],
                          _('hg %s [OPTION]... [FILE]...') % cmd)
+
+commands.inferrepo += " extdiff"
diff -r 78d828137d39 -r b47eb532b161 hgext/graphlog.py
--- a/hgext/graphlog.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/graphlog.py	Tue Oct 16 11:43:15 2012 -0700
@@ -52,3 +52,5 @@
     directory.
     """
     return cmdutil.graphlog(ui, repo, *pats, **opts)
+
+commands.inferrepo += " glog"
diff -r 78d828137d39 -r b47eb532b161 hgext/hgk.py
--- a/hgext/hgk.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/hgk.py	Tue Oct 16 11:43:15 2012 -0700
@@ -350,3 +350,5 @@
           ('n', 'max-count', 0, _('max-count'))],
          _('hg debug-rev-list [OPTION]... REV...')),
 }
+
+commands.inferrepo += " debug-diff-tree debug-cat-file"
diff -r 78d828137d39 -r b47eb532b161 hgext/keyword.py
--- a/hgext/keyword.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/keyword.py	Tue Oct 16 11:43:15 2012 -0700
@@ -728,3 +728,5 @@
             pass
 
     repo.__class__ = kwrepo
+
+commands.inferrepo += " kwexpand kwfiles kwshrink"
diff -r 78d828137d39 -r b47eb532b161 hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/largefiles/lfcommands.py	Tue Oct 16 11:43:15 2012 -0700
@@ -12,7 +12,7 @@
 import shutil
 
 from mercurial import util, match as match_, hg, node, context, error, \
-    cmdutil, scmutil
+    cmdutil, scmutil, commands
 from mercurial.i18n import _
 from mercurial.lock import release
 
@@ -549,3 +549,5 @@
                   ],
                   _('hg lfconvert SOURCE DEST [FILE ...]')),
     }
+
+commands.inferrepo += " lfconvert"
diff -r 78d828137d39 -r b47eb532b161 hgext/mq.py
--- a/hgext/mq.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/mq.py	Tue Oct 16 11:43:15 2012 -0700
@@ -3602,3 +3602,5 @@
               'qseries.guarded': 'black bold',
               'qseries.missing': 'red bold',
               'qseries.unapplied': 'black bold'}
+
+commands.inferrepo += " qnew qrefresh qdiff qcommit"
diff -r 78d828137d39 -r b47eb532b161 hgext/record.py
--- a/hgext/record.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/record.py	Tue Oct 16 11:43:15 2012 -0700
@@ -667,3 +667,5 @@
 def _wrapcmd(cmd, table, wrapfn, msg):
     entry = extensions.wrapcommand(table, cmd, wrapfn)
     entry[1].append(('i', 'interactive', None, msg))
+
+commands.inferrepo += " record qrecord"
diff -r 78d828137d39 -r b47eb532b161 mercurial/commands.py
--- a/mercurial/commands.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/mercurial/commands.py	Tue Oct 16 11:43:15 2012 -0700
@@ -5911,3 +5911,5 @@
           " debugknown debuggetbundle debugbundle")
 optionalrepo = ("identify paths serve showconfig debugancestor debugdag"
                 " debugdata debugindex debugindexdot debugrevlog")
+inferrepo = ("add addremove annotate cat commit diff grep forget log parents"
+             " remove resolve status debugwalk")
diff -r 78d828137d39 -r b47eb532b161 mercurial/dispatch.py
--- a/mercurial/dispatch.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/mercurial/dispatch.py	Tue Oct 16 11:43:15 2012 -0700
@@ -715,7 +715,8 @@
                 raise
             except error.RepoError:
                 if cmd not in commands.optionalrepo.split():
-                    if args and not path: # try to infer -R from command args
+                    if (cmd in commands.inferrepo.split() and
+                        args and not path): # try to infer -R from command args
                         repos = map(cmdutil.findrepo, args)
                         guess = repos[0]
                         if guess and repos.count(guess) == len(repos):
diff -r 78d828137d39 -r b47eb532b161 tests/test-update-branches.t
--- a/tests/test-update-branches.t	Mon Oct 15 09:43:34 2012 -0700
+++ b/tests/test-update-branches.t	Tue Oct 16 11:43:15 2012 -0700
@@ -12,6 +12,8 @@
 # |/
 # o  0:b608b9236435
 
+  $ mkdir b1
+  $ cd b1
   $ hg init
   $ echo foo > foo
   $ echo zero > a
@@ -47,6 +49,14 @@
   o  0:60829823a42a
   
 
+Make sure update doesn't assume b1 is a repository if invoked from outside:
+
+  $ cd ..
+  $ hg update b1
+  abort: no repository found in '$TESTTMP' (.hg not found)!
+  [255]
+  $ cd b1
+
 Test helper functions:
 
   $ revtest () {


More information about the Mercurial-devel mailing list