mercurial/dispatch.py
changeset 10402 d216fa04e48a
parent 10364 de1e7099d100
child 10564 6ded6243bde2
equal deleted inserted replaced
10401:6252852b4332 10402:d216fa04e48a
   160                % ", ".join([x[0] for x in extensions.extensions()]))
   160                % ", ".join([x[0] for x in extensions.extensions()]))
   161         raise
   161         raise
   162 
   162 
   163     return -1
   163     return -1
   164 
   164 
   165 def _findrepo(p):
       
   166     while not os.path.isdir(os.path.join(p, ".hg")):
       
   167         oldp, p = p, os.path.dirname(p)
       
   168         if p == oldp:
       
   169             return None
       
   170 
       
   171     return p
       
   172 
       
   173 def aliasargs(fn):
   165 def aliasargs(fn):
   174     if hasattr(fn, 'args'):
   166     if hasattr(fn, 'args'):
   175         return fn.args
   167         return fn.args
   176     return []
   168     return []
   177 
   169 
   358     cwd = _earlygetopt(['--cwd'], args)
   350     cwd = _earlygetopt(['--cwd'], args)
   359     if cwd:
   351     if cwd:
   360         os.chdir(cwd[-1])
   352         os.chdir(cwd[-1])
   361 
   353 
   362     # read the local repository .hgrc into a local ui object
   354     # read the local repository .hgrc into a local ui object
   363     path = _findrepo(os.getcwd()) or ""
   355     path = cmdutil.findrepo(os.getcwd()) or ""
   364     if not path:
   356     if not path:
   365         lui = ui
   357         lui = ui
   366     else:
   358     else:
   367         try:
   359         try:
   368             lui = ui.copy()
   360             lui = ui.copy()
   457                 raise util.Abort(_("repository '%s' is not local") % path)
   449                 raise util.Abort(_("repository '%s' is not local") % path)
   458             ui.setconfig("bundle", "mainreporoot", repo.root)
   450             ui.setconfig("bundle", "mainreporoot", repo.root)
   459         except error.RepoError:
   451         except error.RepoError:
   460             if cmd not in commands.optionalrepo.split():
   452             if cmd not in commands.optionalrepo.split():
   461                 if args and not path: # try to infer -R from command args
   453                 if args and not path: # try to infer -R from command args
   462                     repos = map(_findrepo, args)
   454                     repos = map(cmdutil.findrepo, args)
   463                     guess = repos[0]
   455                     guess = repos[0]
   464                     if guess and repos.count(guess) == len(repos):
   456                     if guess and repos.count(guess) == len(repos):
   465                         return _dispatch(ui, ['--repository', guess] + fullargs)
   457                         return _dispatch(ui, ['--repository', guess] + fullargs)
   466                 if not path:
   458                 if not path:
   467                     raise error.RepoError(_("There is no Mercurial repository"
   459                     raise error.RepoError(_("There is no Mercurial repository"