comparison hgext/mq.py @ 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 2e8926e9cc32
comparison
equal deleted inserted replaced
10401:6252852b4332 10402:d216fa04e48a
41 ''' 41 '''
42 42
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
50 commands.norepo += " qclone" 50 commands.norepo += " qclone"
51 51
1837 repository for patches (qinit -c may also be run later to convert 1837 repository for patches (qinit -c may also be run later to convert
1838 an unversioned patch repository into a versioned one). You can use 1838 an unversioned patch repository into a versioned one). You can use
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()
1846 if r: 1846 if r:
1847 if not os.path.exists(r.wjoin('.hgignore')): 1847 if not os.path.exists(r.wjoin('.hgignore')):
2618 and not kwargs.get('no_commit', False)): 2618 and not kwargs.get('no_commit', False)):
2619 repo.abort_if_wdir_patched(_('cannot import over an applied patch'), 2619 repo.abort_if_wdir_patched(_('cannot import over an applied patch'),
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
2626 # some commands do not like getting unknown options 2652 # some commands do not like getting unknown options
2627 mq = kwargs['mq'] 2653 mq = kwargs['mq']
2635 if not r: 2661 if not r:
2636 raise util.Abort('no queue repository') 2662 raise util.Abort('no queue repository')
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
2650 cmdtable = { 2682 cmdtable = {
2651 "qapplied": 2683 "qapplied":