changeset 10402:d216fa04e48a

mq: make init -Q do what qinit -c did
author Brendan Cully <brendan@kublai.com>
date Mon, 08 Feb 2010 10:50:00 +0100
parents 6252852b4332
children b8acd325773e
files hgext/mq.py mercurial/cmdutil.py mercurial/dispatch.py
diffstat 3 files changed, 45 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Mon Feb 08 10:23:44 2010 +0100
+++ b/hgext/mq.py	Mon Feb 08 10:50:00 2010 +0100
@@ -43,7 +43,7 @@
 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 @@
     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 @@
                                    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 @@
     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'))]
 
--- a/mercurial/cmdutil.py	Mon Feb 08 10:23:44 2010 +0100
+++ b/mercurial/cmdutil.py	Mon Feb 08 10:50:00 2010 +0100
@@ -62,6 +62,14 @@
 
     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'))
--- a/mercurial/dispatch.py	Mon Feb 08 10:23:44 2010 +0100
+++ b/mercurial/dispatch.py	Mon Feb 08 10:50:00 2010 +0100
@@ -162,14 +162,6 @@
 
     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 @@
         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 @@
         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)