# HG changeset patch # User Bryan O'Sullivan # Date 1203543496 28800 # Node ID 8bc4fe428103ab2b5a332b9c92589247b7f455e5 # Parent aafdea37f7968088508ea53cfc53a79625655e7b# Parent b023915aa1bc5980e7048c36ad74c8520d220864 Merge with crew diff -r b023915aa1bc -r 8bc4fe428103 mercurial/dispatch.py --- a/mercurial/dispatch.py Wed Feb 20 10:50:10 2008 +0100 +++ b/mercurial/dispatch.py Wed Feb 20 13:38:16 2008 -0800 @@ -150,8 +150,7 @@ return -1 -def _findrepo(): - p = os.getcwd() +def _findrepo(p): while not os.path.isdir(os.path.join(p, ".hg")): oldp, p = p, os.path.dirname(p) if p == oldp: @@ -254,7 +253,7 @@ os.chdir(cwd[-1]) # read the local repository .hgrc into a local ui object - path = _findrepo() or "" + path = _findrepo(os.getcwd()) or "" if not path: lui = ui if path: @@ -345,6 +344,11 @@ ui.setconfig("bundle", "mainreporoot", repo.root) except hg.RepoError: if cmd not in commands.optionalrepo.split(): + if args and not path: # try to infer -R from command args + repos = map(_findrepo, args) + guess = repos[0] + if guess and repos.count(guess) == len(repos): + return _dispatch(ui, ['--repository', guess] + fullargs) if not path: raise hg.RepoError(_("There is no Mercurial repository here" " (.hg not found)")) diff -r b023915aa1bc -r 8bc4fe428103 tests/test-globalopts --- a/tests/test-globalopts Wed Feb 20 10:50:10 2008 +0100 +++ b/tests/test-globalopts Wed Feb 20 13:38:16 2008 -0800 @@ -25,6 +25,13 @@ hg -R a tip hg --repository b tip +echo %% implicit -R +hg ann a/a +hg ann a/a a/a +hg ann a/a b/b +hg -R b ann a/a +hg log + echo %% abbrev of long option hg --repo c tip diff -r b023915aa1bc -r 8bc4fe428103 tests/test-globalopts.out --- a/tests/test-globalopts.out Wed Feb 20 10:50:10 2008 +0100 +++ b/tests/test-globalopts.out Wed Feb 20 13:38:16 2008 -0800 @@ -24,6 +24,12 @@ date: Thu Jan 01 00:00:01 1970 +0000 summary: b +%% implicit -R +0: a +0: a +abort: There is no Mercurial repository here (.hg not found)! +abort: a/a not under root +abort: There is no Mercurial repository here (.hg not found)! %% abbrev of long option changeset: 1:b6c483daf290 tag: tip