def instance(ui, path, create): if create: raise util.Abort(_('cannot create new bundle repository')) parentpath = ui.config("bundle", "mainreporoot", "") if not parentpath: # try to find the correct path to the working directory repo parentpath = cmdutil.findrepo(os.getcwd()) if parentpath is None: parentpath = '' if parentpath: # Try to make the full path relative so we get a nice, short URL. # In particular, we don't want temp dir names in test outputs. cwd = os.getcwd() if parentpath == cwd: parentpath = '' else: cwd = os.path.join(cwd, '') if parentpath.startswith(cwd): parentpath = parentpath[len(cwd):] u = util.url(path) path = u.localpath() if u.scheme == 'bundle': s = path.split("+", 1) if len(s) == 1: repopath, bundlename = parentpath, s[0] else: repopath, bundlename = s else: repopath, bundlename = parentpath, path return bundlerepository(ui, repopath, bundlename)
def instance(ui, path, create): if create: raise util.Abort(_('cannot create new union repository')) parentpath = ui.config("bundle", "mainreporoot", "") if not parentpath: # try to find the correct path to the working directory repo parentpath = cmdutil.findrepo(os.getcwd()) if parentpath is None: parentpath = '' if parentpath: # Try to make the full path relative so we get a nice, short URL. # In particular, we don't want temp dir names in test outputs. cwd = os.getcwd() if parentpath == cwd: parentpath = '' else: cwd = os.path.join(cwd,'') if parentpath.startswith(cwd): parentpath = parentpath[len(cwd):] if path.startswith('union:'): s = path.split(":", 1)[1].split("+", 1) if len(s) == 1: repopath, repopath2 = parentpath, s[0] else: repopath, repopath2 = s else: repopath, repopath2 = parentpath, path return unionrepository(ui, repopath, repopath2)
def instance(ui, path, create): if create: raise util.Abort(_('cannot create new bundle repository')) parentpath = ui.config("bundle", "mainreporoot", "") if not parentpath: # try to find the correct path to the working directory repo parentpath = cmdutil.findrepo(os.getcwd()) if parentpath is None: parentpath = '' if parentpath: # Try to make the full path relative so we get a nice, short URL. # In particular, we don't want temp dir names in test outputs. cwd = os.getcwd() if parentpath == cwd: parentpath = '' else: cwd = pathutil.normasprefix(cwd) if parentpath.startswith(cwd): parentpath = parentpath[len(cwd):] u = util.url(path) path = u.localpath() if u.scheme == 'bundle': s = path.split("+", 1) if len(s) == 1: repopath, bundlename = parentpath, s[0] else: repopath, bundlename = s else: repopath, bundlename = parentpath, path return bundlerepository(ui, repopath, bundlename)
def instance(ui, path, create): if create: raise util.Abort(_('cannot create new union repository')) parentpath = ui.config("bundle", "mainreporoot", "") if not parentpath: # try to find the correct path to the working directory repo parentpath = cmdutil.findrepo(os.getcwd()) if parentpath is None: parentpath = '' if parentpath: # Try to make the full path relative so we get a nice, short URL. # In particular, we don't want temp dir names in test outputs. cwd = os.getcwd() if parentpath == cwd: parentpath = '' else: cwd = pathutil.normasprefix(cwd) if parentpath.startswith(cwd): parentpath = parentpath[len(cwd):] if path.startswith('union:'): s = path.split(":", 1)[1].split("+", 1) if len(s) == 1: repopath, repopath2 = parentpath, s[0] else: repopath, repopath2 = s else: repopath, repopath2 = parentpath, path return unionrepository(ui, repopath, repopath2)
def _getlocal(ui, rpath): """Return (path, local ui object) for the given target path. Takes paths in [cwd]/.hg/hgrc into account." """ try: wd = os.getcwd() except OSError as e: raise util.Abort(_("error getting current working directory: %s") % e.strerror) path = cmdutil.findrepo(wd) or "" if not path: lui = ui else: lui = ui.copy() lui.readconfig(os.path.join(path, ".hg", "hgrc"), path) if rpath and rpath[-1]: path = lui.expandpath(rpath[-1]) lui = ui.copy() lui.readconfig(os.path.join(path, ".hg", "hgrc"), path) return path, lui
pats=cmdpats, opts=cmdoptions) return ret def _getlocal(ui, rpath): """Return (path, local ui object) for the given target path. Takes paths in [cwd]/.hg/hgrc into account." """ try: wd = os.getcwd() except OSError, e: raise util.Abort( _("error getting current working directory: %s") % e.strerror) path = cmdutil.findrepo(wd) or "" if not path: lui = ui else: lui = ui.copy() lui.readconfig(os.path.join(path, ".hg", "hgrc"), path) if rpath and rpath[-1]: path = lui.expandpath(rpath[-1]) lui = ui.copy() lui.readconfig(os.path.join(path, ".hg", "hgrc"), path) return path, lui def _checkshellalias(lui, ui, args, precheck=True):
# 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 _getlocal(ui, rpath): """Return (path, local ui object) for the given target path. Takes paths in [cwd]/.hg/hgrc into account." """ try: wd = os.getcwd() except OSError, e: raise util.Abort(_("error getting current working directory: %s") % e.strerror) path = cmdutil.findrepo(wd) or "" if not path: lui = ui else: lui = ui.copy() lui.readconfig(os.path.join(path, ".hg", "hgrc"), path) if rpath: path = lui.expandpath(rpath[-1]) lui = ui.copy() lui.readconfig(os.path.join(path, ".hg", "hgrc"), path) return path, lui def _checkshellalias(ui, args): cwd = os.getcwd()
def _dispatch(ui, args): # read --config before doing anything else # (e.g. to change trust settings for reading .hg/hgrc) _parseconfig(ui, _earlygetopt(['--config'], args)) # check for cwd cwd = _earlygetopt(['--cwd'], args) if cwd: os.chdir(cwd[-1]) # read the local repository .hgrc into a local ui object path = cmdutil.findrepo(os.getcwd()) or "" if not path: lui = ui else: try: lui = ui.copy() 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.copy() lui.readconfig(os.path.join(path, ".hg", "hgrc")) # Configure extensions in phases: uisetup, extsetup, cmdtable, and # reposetup. Programs like TortoiseHg will call _dispatch several # times so we keep track of configured extensions in _loaded. extensions.loadall(lui) exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded] # (uisetup and extsetup are handled in extensions.loadall) for name, module in exts: 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.add(name) # (reposetup is handled in hg.repository) addaliases(lui, commands.table) # check for fallback encoding fallback = lui.config('ui', 'fallbackencoding') if fallback: encoding.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 (e.g. not -qR) " "and --repository may only be abbreviated as --repo!")) if options["encoding"]: encoding.encoding = options["encoding"] if options["encodingmode"]: encoding.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) if options['verbose'] or options['debug'] or options['quiet']: ui.setconfig('ui', 'verbose', str(bool(options['verbose']))) ui.setconfig('ui', 'debug', str(bool(options['debug']))) ui.setconfig('ui', 'quiet', str(bool(options['quiet']))) if options['traceback']: ui.setconfig('ui', 'traceback', 'on') if options['noninteractive']: ui.setconfig('ui', 'interactive', 'off') 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 error.RepoError: if cmd not in commands.optionalrepo.split(): if args and not path: # try to infer -R from command args repos = map(cmdutil.findrepo, args) guess = repos[0] if guess and repos.count(guess) == len(repos): return _dispatch(ui, ['--repository', guess] + fullargs) if not path: raise error.RepoError(_("There is no Mercurial repository" " here (.hg not found)")) raise args.insert(0, repo) elif rpath: ui.warn("warning: --repository ignored\n") d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) return runcommand(lui, repo, cmd, fullargs, ui, options, d)
def _dispatch(ui, args): # read --config before doing anything else # (e.g. to change trust settings for reading .hg/hgrc) _parseconfig(ui, _earlygetopt(['--config'], args)) # check for cwd cwd = _earlygetopt(['--cwd'], args) if cwd: os.chdir(cwd[-1]) # read the local repository .hgrc into a local ui object path = cmdutil.findrepo(os.getcwd()) or "" if not path: lui = ui else: try: lui = ui.copy() 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.copy() lui.readconfig(os.path.join(path, ".hg", "hgrc")) # Configure extensions in phases: uisetup, extsetup, cmdtable, and # reposetup. Programs like TortoiseHg will call _dispatch several # times so we keep track of configured extensions in _loaded. extensions.loadall(lui) exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded] # (uisetup and extsetup are handled in extensions.loadall) for name, module in exts: 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.add(name) # (reposetup is handled in hg.repository) addaliases(lui, commands.table) # check for fallback encoding fallback = lui.config('ui', 'fallbackencoding') if fallback: encoding.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 (e.g. not -qR) " "and --repository may only be abbreviated as --repo!")) if options["encoding"]: encoding.encoding = options["encoding"] if options["encodingmode"]: encoding.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) if options['verbose'] or options['debug'] or options['quiet']: ui.setconfig('ui', 'verbose', str(bool(options['verbose']))) ui.setconfig('ui', 'debug', str(bool(options['debug']))) ui.setconfig('ui', 'quiet', str(bool(options['quiet']))) if options['traceback']: ui.setconfig('ui', 'traceback', 'on') if options['noninteractive']: ui.setconfig('ui', 'interactive', 'off') 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 error.RepoError: if cmd not in commands.optionalrepo.split(): if args and not path: # try to infer -R from command args repos = map(cmdutil.findrepo, args) guess = repos[0] if guess and repos.count(guess) == len(repos): return _dispatch(ui, ['--repository', guess] + fullargs) if not path: raise error.RepoError( _("There is no Mercurial repository" " here (.hg not found)")) raise args.insert(0, repo) elif rpath: ui.warn("warning: --repository ignored\n") d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) return runcommand(lui, repo, cmd, fullargs, ui, options, d)