diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -43,7 +43,7 @@ regular patches, possibly losing data in from mercurial.i18n import _ from mercurial.node import bin, hex, short, nullid, nullrev from mercurial.lock import release -from mercurial import commands, cmdutil, hg, patch, util +from mercurial import commands, cmdutil, dispatch, hg, patch, util from mercurial import repair, extensions, url, error import os, sys, re, errno @@ -1839,7 +1839,7 @@ def init(ui, repo, **opts): qcommit to commit changes to this queue repository. This command is deprecated. Without -c, it's implied by other relevant - commands. With -c, use hg -Q init instead.""" + commands. With -c, use hg init -Q instead.""" q = repo.mq r = q.init(repo, create=opts['create_repo']) q.save_dirty() @@ -2620,6 +2620,32 @@ def mqimport(orig, ui, repo, *args, **kw kwargs.get('force')) return orig(ui, repo, *args, **kwargs) +def mqinit(orig, ui, *args, **kwargs): + mq = kwargs['mq'] + del kwargs['mq'] + + if not mq: + return orig(ui, *args, **kwargs) + + repopath = cmdutil.findrepo(os.getcwd()) + repo = hg.repository(ui, repopath) + q = repo.mq + r = q.init(repo, create=True) + q.save_dirty() + + if not os.path.exists(r.wjoin('.hgignore')): + fp = r.wopener('.hgignore', 'w') + fp.write('^\\.hg\n') + fp.write('^\\.mq\n') + fp.write('syntax: glob\n') + fp.write('status\n') + fp.write('guards\n') + fp.close() + if not os.path.exists(r.wjoin('series')): + r.wopener('series', 'w').close() + r.add(['.hgignore', 'series']) + commands.add(ui, r) + def mqcommand(orig, ui, repo, *args, **kwargs): """Add --mq option to operate on patch repository instead of main""" @@ -2637,13 +2663,19 @@ def mqcommand(orig, ui, repo, *args, **k return orig(ui, r, *args, **kwargs) def uisetup(ui): + mqopt = [('Q', 'mq', None, _("operate on patch repository"))] + extensions.wrapcommand(commands.table, 'import', mqimport) + + entry = extensions.wrapcommand(commands.table, 'init', mqinit) + entry[1].extend(mqopt) + for cmd in commands.table: cmd = cmdutil.parsealiases(cmd)[0] if cmd in commands.norepo: continue entry = extensions.wrapcommand(commands.table, cmd, mqcommand) - entry[1].extend([('Q', 'mq', None, _("operate on patch repository"))]) + entry[1].extend(mqopt) seriesopts = [('s', 'summary', None, _('print first line of patch header'))] diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -62,6 +62,14 @@ def findcmd(cmd, table, strict=True): raise error.UnknownCommand(cmd) +def findrepo(p): + while not os.path.isdir(os.path.join(p, ".hg")): + oldp, p = p, os.path.dirname(p) + if p == oldp: + return None + + return p + def bail_if_changed(repo): if repo.dirstate.parents()[1] != nullid: raise util.Abort(_('outstanding uncommitted merge')) diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -162,14 +162,6 @@ def _runcatch(ui, args): return -1 -def _findrepo(p): - while not os.path.isdir(os.path.join(p, ".hg")): - oldp, p = p, os.path.dirname(p) - if p == oldp: - return None - - return p - def aliasargs(fn): if hasattr(fn, 'args'): return fn.args @@ -360,7 +352,7 @@ def _dispatch(ui, args): os.chdir(cwd[-1]) # read the local repository .hgrc into a local ui object - path = _findrepo(os.getcwd()) or "" + path = cmdutil.findrepo(os.getcwd()) or "" if not path: lui = ui else: @@ -459,7 +451,7 @@ def _dispatch(ui, args): except error.RepoError: if cmd not in commands.optionalrepo.split(): if args and not path: # try to infer -R from command args - repos = map(_findrepo, args) + repos = map(cmdutil.findrepo, args) guess = repos[0] if guess and repos.count(guess) == len(repos): return _dispatch(ui, ['--repository', guess] + fullargs)