def runcommand(ui, args): cmd, func, args, options, cmdoptions, alias = _parse(ui, args) cmdoptions['alias'] = alias ui.setconfig("ui", "verbose", str(bool(options["verbose"]))) i18n.setlanguage(ui.config('tortoisehg', 'ui.language')) if options['help']: return help_(ui, cmd) if options['newworkbench']: cmdoptions['newworkbench'] = True path = options['repository'] if path: if path.startswith('bundle:'): s = path[7:].split('+', 1) if len(s) == 1: path, bundle = os.getcwd(), s[0] else: path, bundle = s cmdoptions['bundle'] = os.path.abspath(bundle) path = ui.expandpath(path) # TODO: replace by abspath() if chdir() isn't necessary try: os.chdir(path) path = os.getcwd() except OSError: pass if options['profile']: options['nofork'] = True path = paths.find_root(path) if path: try: lui = ui.copy() lui.readconfig(os.path.join(path, ".hg", "hgrc")) except IOError: pass else: lui = ui hglib.wrapextensionsloader() # enable blacklist of extensions extensions.loadall(lui) args += get_files_from_listfile() if options['quiet']: ui.quiet = True # repository existence will be tested in qtrun() if cmd not in nonrepo_commands.split(): cmdoptions['repository'] = path or options['repository'] or '.' cmdoptions['mainapp'] = True checkedfunc = util.checksignature(func) if cmd in console_commands.split(): d = lambda: checkedfunc(ui, *args, **cmdoptions) else: portable_fork(ui, options) d = lambda: qtrun(checkedfunc, ui, *args, **cmdoptions) return _runcommand(lui, options, cmd, d)
def get_repo(url, alias): global peer myui = ui.ui() myui.setconfig('ui', 'interactive', 'off') myui.fout = sys.stderr if get_config_bool('remote-hg.insecure'): myui.setconfig('web', 'cacerts', '') extensions.loadall(myui) if hg.islocal(url) and not os.environ.get('GIT_REMOTE_HG_TEST_REMOTE'): repo = hg.repository(myui, url) if not os.path.exists(dirname): os.makedirs(dirname) else: shared_path = os.path.join(gitdir, 'hg') # check and upgrade old organization hg_path = os.path.join(shared_path, '.hg') if os.path.exists(shared_path) and not os.path.exists(hg_path): repos = os.listdir(shared_path) for x in repos: local_hg = os.path.join(shared_path, x, 'clone', '.hg') if not os.path.exists(local_hg): continue if not os.path.exists(hg_path): shutil.move(local_hg, hg_path) shutil.rmtree(os.path.join(shared_path, x, 'clone')) # setup shared repo (if not there) try: hg.peer(myui, {}, shared_path, create=True) except error.RepoError: pass if not os.path.exists(dirname): os.makedirs(dirname) local_path = os.path.join(dirname, 'clone') if not os.path.exists(local_path): hg.share(myui, shared_path, local_path, update=False) else: # make sure the shared path is always up-to-date util.writefile(os.path.join(local_path, '.hg', 'sharedpath'), hg_path) repo = hg.repository(myui, local_path) try: peer = hg.peer(myui, {}, url) except: die('Repository error') repo.pull(peer, heads=None, force=True) updatebookmarks(repo, peer) return repo
def runcommand(ui, args): cmd, func, args, options, cmdoptions, alias = _parse(ui, args) cmdoptions['alias'] = alias ui.setconfig("ui", "verbose", str(bool(options["verbose"]))) i18n.setlanguage(ui.config('tortoisehg', 'ui.language')) if options['help']: return help_(ui, cmd) if options['newworkbench']: cmdoptions['newworkbench'] = True path = options['repository'] if path: if path.startswith('bundle:'): s = path[7:].split('+', 1) if len(s) == 1: path, bundle = os.getcwd(), s[0] else: path, bundle = s cmdoptions['bundle'] = os.path.abspath(bundle) path = ui.expandpath(path) if not os.path.exists(path) or not os.path.isdir(path + '/.hg'): print 'abort: %s is not a repository' % path return 1 os.chdir(path) if options['fork']: cmdoptions['fork'] = True if options['nofork'] or options['profile']: cmdoptions['nofork'] = True path = paths.find_root(os.getcwd()) if path: cmdoptions['repository'] = path try: lui = ui.copy() lui.readconfig(os.path.join(path, ".hg", "hgrc")) except IOError: pass else: lui = ui hglib.wrapextensionsloader() # enable blacklist of extensions extensions.loadall(lui) args += get_files_from_listfile() if options['quiet']: ui.quiet = True if cmd not in nonrepo_commands.split() and not path: raise error.RepoError( _("There is no Mercurial repository here" " (.hg not found)")) cmdoptions['mainapp'] = True d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) return _runcommand(lui, options, cmd, d)
def runcommand(ui, args): cmd, func, args, options, cmdoptions, alias = _parse(ui, args) cmdoptions['alias'] = alias ui.setconfig("ui", "verbose", str(bool(options["verbose"]))) i18n.setlanguage(ui.config('tortoisehg', 'ui.language')) if options['help']: return help_(ui, cmd) if options['newworkbench']: cmdoptions['newworkbench'] = True path = options['repository'] if path: if path.startswith('bundle:'): s = path[7:].split('+', 1) if len(s) == 1: path, bundle = os.getcwd(), s[0] else: path, bundle = s cmdoptions['bundle'] = os.path.abspath(bundle) path = ui.expandpath(path) if not os.path.exists(path) or not os.path.isdir(path+'/.hg'): print 'abort: %s is not a repository' % path return 1 os.chdir(path) if options['fork']: cmdoptions['fork'] = True if options['nofork'] or options['profile']: cmdoptions['nofork'] = True path = paths.find_root(os.getcwd()) if path: cmdoptions['repository'] = path try: lui = ui.copy() lui.readconfig(os.path.join(path, ".hg", "hgrc")) except IOError: pass else: lui = ui hglib.wrapextensionsloader() # enable blacklist of extensions extensions.loadall(lui) args += get_files_from_listfile() if options['quiet']: ui.quiet = True if cmd not in nonrepo_commands.split() and not path: raise error.RepoError(_("There is no Mercurial repository here" " (.hg not found)")) cmdoptions['mainapp'] = True d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) return _runcommand(lui, options, cmd, d)
def ensureenabled(ui): """make sure the extension is enabled when used as hook When eol is used through hooks, the extension is never formally loaded and enabled. This has some side effect, for example the config declaration is never loaded. This function ensure the extension is enabled when running hooks. """ if b'eol' in ui._knownconfig: return ui.setconfig(b'extensions', b'eol', b'', source=b'internal') extensions.loadall(ui, [b'eol'])
def extsetup(ui): # Modelled after dispatch._dispatch. We have to re-parse the # arguments to find the path to the repository since there is no # repo object yet. # extsetup is called after all the extension are loaded, and can be useful in case one extension optionally depends on another extension. Signature: # https://www.mercurial-scm.org/wiki/WritingExtensions#Setup_Callbacks #moved to uisetup #args = sys.argv[1:] #rpath = dispatch._earlygetopt(["-R", "--repository", "--repo"], args) #readprojrc(ui, rpath) extensions.loadall(ui) if hasattr(dispatch, "_loaded"): for name, module in extensions.extensions(): if name in dispatch._loaded: continue 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) dispatch._loaded.add(name) else: #dispatch._loaded was removed in the latest mercurial faux_loaded = set() for name in extensions._extensions: faux_loaded.add(name) for name, module in extensions.extensions(): if name in faux_loaded: continue 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) faux_loaded.add(name) extensions.wrapfunction(hg, 'clone', clone) extensions.wrapfunction(hg, 'incoming', incoming) extensions.wrapfunction(exchange, 'pull', pull) pushkey.register('projrc', pushprojrc, listprojrc)
def draw(self, repo): """Helper function displaying a repository graph, especially useful when debugging comprehensive tests. """ # Could be more elegant, but it works with stock hg _ui = ui.ui() _ui.setconfig('extensions', 'graphlog', '') extensions.loadall(_ui) graphlog = extensions.find('graphlog') templ = """\ changeset: {rev}:{node|short} branch: {branches} tags: {tags} summary: {desc|firstline} files: {files} """ graphlog.graphlog(_ui, repo, rev=None, template=templ)
def tree_context_menu(self): _menu = gtk.Menu() _menu.append(create_menu('di_splay', self._show_status)) _menu.append(create_menu('_checkout', self._checkout)) self._cmenu_merge = create_menu('_merge with', self._merge) _menu.append(self._cmenu_merge) _menu.append(create_menu('_export patch', self._export_patch)) _menu.append(create_menu('e_mail patch', self._email_patch)) _menu.append(create_menu('add/remove _tag', self._add_tag)) _menu.append(create_menu('backout revision', self._backout_rev)) # need mq extension for strip command extensions.loadall(self.ui) extensions.load(self.ui, 'mq', None) _menu.append(create_menu('strip revision', self._strip_rev)) _menu.show_all() return _menu
def getgraph(self, repo): """Helper function displaying a repository graph, especially useful when debugging comprehensive tests. """ # Could be more elegant, but it works with stock hg _ui = testui() _ui.setconfig('extensions', 'graphlog', '') extensions.loadall(_ui) graphlog = extensions.find('graphlog') templ = """\ changeset: {rev}:{node|short} (r{svnrev}) branch: {branches} tags: {tags} summary: {desc|firstline} files: {files} """ _ui.pushbuffer() try: graphlog.graphlog(_ui, repo, rev=None, template=templ) except AttributeError: from mercurial import commands commands.log(_ui, repo, rev=None, template=templ, graph=True) return _ui.popbuffer()
def loadextensions(ui): """Load and setup extensions for GUI process""" _wrapextensionsloader() # enable blacklist of extensions extensions.loadall(ui)
if os.name != 'nt': ignore.add('win32mbcs') disabled = [ext for ext in extensions.disabled().keys() if ext not in ignore] hgrc = open(os.environ["HGRCPATH"], 'w') hgrc.write('[extensions]\n') for ext in disabled: hgrc.write(ext + '=\n') hgrc.close() u = ui.ui() extensions.loadall(u) globalshort = set() globallong = set() for option in commands.globalopts: option[0] and globalshort.add(option[0]) option[1] and globallong.add(option[1]) for cmd, entry in commands.table.iteritems(): seenshort = globalshort.copy() seenlong = globallong.copy() for option in entry[1]: if (option[0] and option[0] in seenshort) or \ (option[1] and option[1] in seenlong): print "command '" + cmd + "' has duplicate option " + str(option) seenshort.add(option[0])
def transferprojrc(ui, repo, other, confirmupdate=None): data, valid = getremoteprojrc(ui, repo, other) if not valid or data is None: return if data != "": # Compare the old projrc with the new one try: if hasattr(localrepo, 'localpeer'): # hg >= 2.3 repo = repo.local() olddata = readcurrentprojrc(repo) if olddata != data: def mustconfirm(projrcexists): """Read the projrc.confirm setting. Valid values are: - true: Always ask for confirmation - first: Ask for confirmation when the projrc file is transferred for the first time - false: Do not ask for confirmation (i.e. accept all projrc changes) Note that you can use any valid 'boolean' value instead of true and false (i.e. always, yes, on or 1 instead of true and never, no, off or 0 instead of false) """ confirmchanges = ui.config( 'projrc', 'confirm', default=True) if isinstance(confirmchanges, bool): return confirmchanges confirm = util.parsebool(confirmchanges) if not confirm is None: return confirm confirmchanges = confirmchanges.lower() if projrcexists and confirmchanges == "first": return False return True if confirmupdate is None: confirmupdate = mustconfirm(olddata != "") acceptnewconfig = True if confirmupdate: confirmmsg = \ _("The project settings file (projrc) has changed.\n" "Do you want to update it? (y/n)") YES = _('&Yes') NO = _('&No') try: # hg < 2.7 action = ui.promptchoice(confirmmsg, (YES, NO), default=0) except TypeError, ex: # hg >= 2.7+ action = ui.promptchoice(confirmmsg \ + _(" $$ %s $$ %s") % (YES, NO), default=0) acceptnewconfig = (action == 0) if acceptnewconfig: # If there are changes and the user accepts them, save the new projrc repo_write(repo, 'projrc', data) # and take any transferred settings into account try: loadprojrc(repo.ui, repo_join(repo,'projrc'), repo.root) extensions.loadall(repo.ui) ui.status(_("projrc settings file updated and applied\n")) except IOError: ui.warn(_("projrc settings file updated but could not be applied\n")) except error.ParseError, e: ui.warn(_("not saving retrieved projrc file: " "parse error at '%s' on %s\n") % e.args)
def thgdispatch(ui, path=None, args=[]): ''' Replicate functionality of mercurial dispatch but force the use of the passed in ui for all purposes ''' # 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 = rootpath(path) or "" if path: try: ui.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 = ui.expandpath(rpath[-1]) extensions.loadall(ui) if not hasattr(extensions, 'extensions'): extensions.extensions = lambda: () # pre-0.9.5, loadall did below for name, module in extensions.extensions(): if name in _loaded: continue # setup extensions 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 = ui.config('ui', 'fallbackencoding') if fallback: util._fallbackencoding = fallback fullargs = args cmd, func, args, options, cmdoptions = parse(ui, args) if options["encoding"]: util._encoding = options["encoding"] if options["encodingmode"]: util._encodingmode = options["encodingmode"] 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) repo.ui = ui ui.setconfig("bundle", "mainreporoot", repo.root) if not repo.local(): raise util.Abort(_("repository '%s' is not local") % path) except RepoError: if cmd not in commands.optionalrepo.split(): 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(ui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) if ret: return ret # Run actual command try: ret = d() except TypeError, inst: # was this an argument error? tb = traceback.extract_tb(sys.exc_info()[2]) if len(tb) != 2: # no raise raise ParseError(cmd, _("invalid arguments"))