mercurial/commands.py
changeset 1071 8f0ac653f85e
parent 1068 498456c2e8e5
child 1081 8b7d63489db3
equal deleted inserted replaced
1070:b55c6685c953 1071:8f0ac653f85e
     4 #
     4 #
     5 # This software may be used and distributed according to the terms
     5 # This software may be used and distributed according to the terms
     6 # of the GNU General Public License, incorporated herein by reference.
     6 # of the GNU General Public License, incorporated herein by reference.
     7 
     7 
     8 from demandload import demandload
     8 from demandload import demandload
     9 demandload(globals(), "os re sys signal shutil")
     9 demandload(globals(), "os re sys signal shutil imp")
    10 demandload(globals(), "fancyopts ui hg util lock")
    10 demandload(globals(), "fancyopts ui hg util lock")
    11 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
    11 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
    12 demandload(globals(), "errno socket version struct atexit sets")
    12 demandload(globals(), "errno socket version struct atexit sets")
    13 
    13 
    14 class UnknownCommand(Exception):
    14 class UnknownCommand(Exception):
  1727     try:
  1727     try:
  1728         signal.signal(signal.SIGHUP, catchterm)
  1728         signal.signal(signal.SIGHUP, catchterm)
  1729     except AttributeError:
  1729     except AttributeError:
  1730         pass
  1730         pass
  1731 
  1731 
       
  1732     u = ui.ui()
       
  1733     external = []
       
  1734     for x in u.extensions():
       
  1735         if x[1]:
       
  1736             mod = imp.load_source(x[0], x[1])
       
  1737         else:
       
  1738             def importh(name):
       
  1739                 mod = __import__(name)
       
  1740                 components = name.split('.')
       
  1741                 for comp in components[1:]:
       
  1742                     mod = getattr(mod, comp)
       
  1743                 return mod
       
  1744             mod = importh(x[0])
       
  1745         external.append(mod)
       
  1746     for x in external:
       
  1747         for t in x.cmdtable:
       
  1748             if t in table:
       
  1749                 u.warn("module %s override %s\n" % (x.__name__, t))
       
  1750         table.update(x.cmdtable)
       
  1751 
  1732     try:
  1752     try:
  1733         cmd, func, args, options, cmdoptions = parse(args)
  1753         cmd, func, args, options, cmdoptions = parse(args)
  1734     except ParseError, inst:
  1754     except ParseError, inst:
  1735         u = ui.ui()
       
  1736         if inst.args[0]:
  1755         if inst.args[0]:
  1737             u.warn("hg %s: %s\n" % (inst.args[0], inst.args[1]))
  1756             u.warn("hg %s: %s\n" % (inst.args[0], inst.args[1]))
  1738             help_(u, inst.args[0])
  1757             help_(u, inst.args[0])
  1739         else:
  1758         else:
  1740             u.warn("hg: %s\n" % inst.args[1])
  1759             u.warn("hg: %s\n" % inst.args[1])
  1741             help_(u, 'shortlist')
  1760             help_(u, 'shortlist')
  1742         sys.exit(-1)
  1761         sys.exit(-1)
  1743     except UnknownCommand, inst:
  1762     except UnknownCommand, inst:
  1744         u = ui.ui()
       
  1745         u.warn("hg: unknown command '%s'\n" % inst.args[0])
  1763         u.warn("hg: unknown command '%s'\n" % inst.args[0])
  1746         help_(u, 'shortlist')
  1764         help_(u, 'shortlist')
  1747         sys.exit(1)
  1765         sys.exit(1)
  1748 
  1766 
  1749     if options["time"]:
  1767     if options["time"]:
  1753                 t = (t[0], t[1], t[2], t[3], time.clock())
  1771                 t = (t[0], t[1], t[2], t[3], time.clock())
  1754             return t
  1772             return t
  1755         s = get_times()
  1773         s = get_times()
  1756         def print_time():
  1774         def print_time():
  1757             t = get_times()
  1775             t = get_times()
  1758             u = ui.ui()
       
  1759             u.warn("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n" %
  1776             u.warn("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n" %
  1760                 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
  1777                 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
  1761         atexit.register(print_time)
  1778         atexit.register(print_time)
  1762 
  1779 
  1763     u = ui.ui(options["verbose"], options["debug"], options["quiet"],
  1780     u.updateopts(options["verbose"], options["debug"], options["quiet"],
  1764               not options["noninteractive"])
  1781               not options["noninteractive"])
  1765 
  1782 
  1766     try:
  1783     try:
  1767         try:
  1784         try:
  1768             if options['help']:
  1785             if options['help']:
  1783                     sys.exit(1)
  1800                     sys.exit(1)
  1784 
  1801 
  1785             if cmd not in norepo.split():
  1802             if cmd not in norepo.split():
  1786                 path = options["repository"] or ""
  1803                 path = options["repository"] or ""
  1787                 repo = hg.repository(ui=u, path=path)
  1804                 repo = hg.repository(ui=u, path=path)
       
  1805                 for x in external:
       
  1806                     x.reposetup(u, repo)
  1788                 d = lambda: func(u, repo, *args, **cmdoptions)
  1807                 d = lambda: func(u, repo, *args, **cmdoptions)
  1789             else:
  1808             else:
  1790                 d = lambda: func(u, *args, **cmdoptions)
  1809                 d = lambda: func(u, *args, **cmdoptions)
  1791 
  1810 
  1792             if options['profile']:
  1811             if options['profile']: