def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions): # run pre-hook, and abort if it fails hook.hook(lui, repo, "pre-%s" % cmd, True, args=" ".join(fullargs), pats=cmdpats, opts=cmdoptions) ret = _runcommand(ui, options, cmd, d) # run post-hook, passing command result hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), result=ret, pats=cmdpats, opts=cmdoptions) return ret
def runcommand(lui, repo, cmd, fullargs, ui, options, d): # run pre-hook, and abort if it fails ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) if ret: return ret ret = _runcommand(ui, options, cmd, d) # run post-hook, passing command result hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), result = ret) return ret
def runcommand(lui, repo, cmd, fullargs, ui, options, d): # run pre-hook, and abort if it fails ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) if ret: return ret ret = _runcommand(ui, options, cmd, d) # run post-hook, passing command result hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), result=ret) return ret
def _dispatch(ui, args): # read --config before doing anything else # (e.g. to change trust settings for reading .hg/hgrc) config = _earlygetopt(['--config'], args) if config: ui.updateopts(config=_parseconfig(config)) # check for cwd cwd = _earlygetopt(['--cwd'], args) if cwd: os.chdir(cwd[-1]) # read the local repository .hgrc into a local ui object path = _findrepo(os.getcwd()) or "" if not path: lui = ui if path: try: lui = _ui.ui(parentui=ui) lui.readconfig(os.path.join(path, ".hg", "hgrc")) except IOError: pass # now we can expand paths, even ones in .hg/hgrc rpath = _earlygetopt(["-R", "--repository", "--repo"], args) if rpath: path = lui.expandpath(rpath[-1]) lui = _ui.ui(parentui=ui) lui.readconfig(os.path.join(path, ".hg", "hgrc")) extensions.loadall(lui) for name, module in extensions.extensions(): if name in _loaded: continue # setup extensions # TODO this should be generalized to scheme, where extensions can # redepend on other extensions. then we should toposort them, and # do initialization in correct order extsetup = getattr(module, 'extsetup', None) if extsetup: extsetup() cmdtable = getattr(module, 'cmdtable', {}) overrides = [cmd for cmd in cmdtable if cmd in commands.table] if overrides: ui.warn(_("extension '%s' overrides commands: %s\n") % (name, " ".join(overrides))) commands.table.update(cmdtable) _loaded[name] = 1 # check for fallback encoding fallback = lui.config('ui', 'fallbackencoding') if fallback: util._fallbackencoding = fallback fullargs = args cmd, func, args, options, cmdoptions = _parse(lui, args) if options["config"]: raise util.Abort(_("Option --config may not be abbreviated!")) if options["cwd"]: raise util.Abort(_("Option --cwd may not be abbreviated!")) if options["repository"]: raise util.Abort(_( "Option -R has to be separated from other options (i.e. not -qR) " "and --repository may only be abbreviated as --repo!")) if options["encoding"]: util._encoding = options["encoding"] if options["encodingmode"]: util._encodingmode = options["encodingmode"] if options["time"]: def get_times(): t = os.times() if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() t = (t[0], t[1], t[2], t[3], time.clock()) return t s = get_times() def print_time(): t = get_times() ui.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) atexit.register(print_time) ui.updateopts(options["verbose"], options["debug"], options["quiet"], not options["noninteractive"], options["traceback"]) if options['help']: return commands.help_(ui, cmd, options['version']) elif options['version']: return commands.version_(ui) elif not cmd: return commands.help_(ui, 'shortlist') repo = None if cmd not in commands.norepo.split(): try: repo = hg.repository(ui, path=path) ui = repo.ui if not repo.local(): raise util.Abort(_("repository '%s' is not local") % path) ui.setconfig("bundle", "mainreporoot", repo.root) except RepoError: if cmd not in commands.optionalrepo.split(): if args and not path: # try to infer -R from command args repos = map(_findrepo, args) guess = repos[0] if guess and repos.count(guess) == len(repos): return _dispatch(ui, ['--repository', guess] + fullargs) if not path: raise RepoError(_("There is no Mercurial repository here" " (.hg not found)")) raise d = lambda: func(ui, repo, *args, **cmdoptions) else: d = lambda: func(ui, *args, **cmdoptions) # run pre-hook, and abort if it fails ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) if ret: return ret ret = _runcommand(ui, options, cmd, d) # run post-hook, passing command result hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), result = ret) return ret