##// END OF EJS Templates
mq: make init -Q do what qinit -c did
Brendan Cully -
r10402:d216fa04 default
parent child Browse files
Show More
@@ -43,7 +43,7 b' regular patches, possibly losing data in'
43 from mercurial.i18n import _
43 from mercurial.i18n import _
44 from mercurial.node import bin, hex, short, nullid, nullrev
44 from mercurial.node import bin, hex, short, nullid, nullrev
45 from mercurial.lock import release
45 from mercurial.lock import release
46 from mercurial import commands, cmdutil, hg, patch, util
46 from mercurial import commands, cmdutil, dispatch, hg, patch, util
47 from mercurial import repair, extensions, url, error
47 from mercurial import repair, extensions, url, error
48 import os, sys, re, errno
48 import os, sys, re, errno
49
49
@@ -1839,7 +1839,7 b' def init(ui, repo, **opts):'
1839 qcommit to commit changes to this queue repository.
1839 qcommit to commit changes to this queue repository.
1840
1840
1841 This command is deprecated. Without -c, it's implied by other relevant
1841 This command is deprecated. Without -c, it's implied by other relevant
1842 commands. With -c, use hg -Q init instead."""
1842 commands. With -c, use hg init -Q instead."""
1843 q = repo.mq
1843 q = repo.mq
1844 r = q.init(repo, create=opts['create_repo'])
1844 r = q.init(repo, create=opts['create_repo'])
1845 q.save_dirty()
1845 q.save_dirty()
@@ -2620,6 +2620,32 b' def mqimport(orig, ui, repo, *args, **kw'
2620 kwargs.get('force'))
2620 kwargs.get('force'))
2621 return orig(ui, repo, *args, **kwargs)
2621 return orig(ui, repo, *args, **kwargs)
2622
2622
2623 def mqinit(orig, ui, *args, **kwargs):
2624 mq = kwargs['mq']
2625 del kwargs['mq']
2626
2627 if not mq:
2628 return orig(ui, *args, **kwargs)
2629
2630 repopath = cmdutil.findrepo(os.getcwd())
2631 repo = hg.repository(ui, repopath)
2632 q = repo.mq
2633 r = q.init(repo, create=True)
2634 q.save_dirty()
2635
2636 if not os.path.exists(r.wjoin('.hgignore')):
2637 fp = r.wopener('.hgignore', 'w')
2638 fp.write('^\\.hg\n')
2639 fp.write('^\\.mq\n')
2640 fp.write('syntax: glob\n')
2641 fp.write('status\n')
2642 fp.write('guards\n')
2643 fp.close()
2644 if not os.path.exists(r.wjoin('series')):
2645 r.wopener('series', 'w').close()
2646 r.add(['.hgignore', 'series'])
2647 commands.add(ui, r)
2648
2623 def mqcommand(orig, ui, repo, *args, **kwargs):
2649 def mqcommand(orig, ui, repo, *args, **kwargs):
2624 """Add --mq option to operate on patch repository instead of main"""
2650 """Add --mq option to operate on patch repository instead of main"""
2625
2651
@@ -2637,13 +2663,19 b' def mqcommand(orig, ui, repo, *args, **k'
2637 return orig(ui, r, *args, **kwargs)
2663 return orig(ui, r, *args, **kwargs)
2638
2664
2639 def uisetup(ui):
2665 def uisetup(ui):
2666 mqopt = [('Q', 'mq', None, _("operate on patch repository"))]
2667
2640 extensions.wrapcommand(commands.table, 'import', mqimport)
2668 extensions.wrapcommand(commands.table, 'import', mqimport)
2669
2670 entry = extensions.wrapcommand(commands.table, 'init', mqinit)
2671 entry[1].extend(mqopt)
2672
2641 for cmd in commands.table:
2673 for cmd in commands.table:
2642 cmd = cmdutil.parsealiases(cmd)[0]
2674 cmd = cmdutil.parsealiases(cmd)[0]
2643 if cmd in commands.norepo:
2675 if cmd in commands.norepo:
2644 continue
2676 continue
2645 entry = extensions.wrapcommand(commands.table, cmd, mqcommand)
2677 entry = extensions.wrapcommand(commands.table, cmd, mqcommand)
2646 entry[1].extend([('Q', 'mq', None, _("operate on patch repository"))])
2678 entry[1].extend(mqopt)
2647
2679
2648 seriesopts = [('s', 'summary', None, _('print first line of patch header'))]
2680 seriesopts = [('s', 'summary', None, _('print first line of patch header'))]
2649
2681
@@ -62,6 +62,14 b' def findcmd(cmd, table, strict=True):'
62
62
63 raise error.UnknownCommand(cmd)
63 raise error.UnknownCommand(cmd)
64
64
65 def findrepo(p):
66 while not os.path.isdir(os.path.join(p, ".hg")):
67 oldp, p = p, os.path.dirname(p)
68 if p == oldp:
69 return None
70
71 return p
72
65 def bail_if_changed(repo):
73 def bail_if_changed(repo):
66 if repo.dirstate.parents()[1] != nullid:
74 if repo.dirstate.parents()[1] != nullid:
67 raise util.Abort(_('outstanding uncommitted merge'))
75 raise util.Abort(_('outstanding uncommitted merge'))
@@ -162,14 +162,6 b' def _runcatch(ui, args):'
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
@@ -360,7 +352,7 b' def _dispatch(ui, args):'
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:
@@ -459,7 +451,7 b' def _dispatch(ui, args):'
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)
General Comments 0
You need to be logged in to leave comments. Login now