def extsetup(ui): extensions.wrapfilecache(localrepo.localrepository, "dirstate", wrapdirstate) if pycompat.isdarwin: # An assist for avoiding the dangling-symlink fsevents bug extensions.wrapfunction(os, "symlink", wrapsymlink) extensions.wrapfunction(filesystem, "findthingstopurge", wrappurge)
def extsetup(ui): extensions.wrapfunction(graphmod, "dagwalker", _dagwalker) extensions.wrapfunction(hg, "updaterepo", _updaterepo) extensions.wrapfunction(visibility.visibleheads, "_updateheads", _updateheads) extensions.wrapfunction(templatekw, "showgraphnode", _showgraphnode) templatekw.keywords["graphnode"] = templatekw.showgraphnode extensions.wrapfunction(bundlerepo.bundlerepository, "_handlebundle2part", _handlebundle2part) extensions.wrapcommand(commands.table, "update", _update) def wrapamend(loaded): if not loaded: return amend = extensions.find("amend") extensions.wrapfunction(amend.hide, "_dounhide", _dounhide) def wrapsmartlog(loaded): if not loaded: return smartlog = extensions.find("smartlog") extensions.wrapfunction(smartlog, "smartlogrevset", _smartlogrevset) smartlog.revsetpredicate._table["smartlog"] = smartlog.smartlogrevset extensions.afterloaded("amend", wrapamend) extensions.afterloaded("smartlog", wrapsmartlog)
def extsetup(ui): origpushkeyhandler = bundle2.parthandlermapping["pushkey"] def newpushkeyhandler(*args, **kwargs): bundle2pushkey(origpushkeyhandler, *args, **kwargs) newpushkeyhandler.params = origpushkeyhandler.params bundle2.parthandlermapping["pushkey"] = newpushkeyhandler orighandlephasehandler = bundle2.parthandlermapping["phase-heads"] newphaseheadshandler = lambda *args, **kwargs: bundle2handlephases( orighandlephasehandler, *args, **kwargs ) newphaseheadshandler.params = orighandlephasehandler.params bundle2.parthandlermapping["phase-heads"] = newphaseheadshandler extensions.wrapfunction(localrepo.localrepository, "listkeys", localrepolistkeys) wireproto.commands["lookup"] = ( _makelookupwrap(wireproto.commands["lookup"][0]), "key", ) extensions.wrapfunction(exchange, "getbundlechunks", getbundlechunks) extensions.wrapfunction(bundle2, "processparts", processparts) if util.safehasattr(wireproto, "_capabilities"): extensions.wrapfunction(wireproto, "_capabilities", _capabilities) else: extensions.wrapfunction(wireproto, "capabilities", _capabilities)
def uisetup(ui): def show(orig, self, ctx, *args): res = orig(self, ctx, *args) if commit_info and ctx == self.repo["."]: changes = ctx.p1().status(ctx) prefixes = ["M", "A", "R", "!", "?", "I", "C"] labels = [ "status.modified", "status.added", "status.removed", "status.deleted", "status.unknown", "status.ignored", "status.copied", ] for prefix, label, change in zip(prefixes, labels, changes): for fname in change: self.ui.write( self.ui.label(" {0} {1}\n".format(prefix, fname), label)) self.ui.write("\n") return res extensions.wrapfunction(cmdutil.changeset_printer, "_show", show) extensions.wrapfunction(cmdutil.changeset_templater, "_show", show)
def uisetup(ui): progressfile = ui.config("progress", "statefile") append = ui.configbool("progress", "statefileappend", False) filemode = "a+" if append else "w+" if progressfile: global _pid _pid = ui.configint("progress", "fakedpid") or util.getpid() def wrapengine(orig): origengine = progress._engine currentengine = orig() if origengine != currentengine or not getattr( currentengine, "_filewrapped", False ): class fileengine(currentengine.__class__): def _show(self, now): super(fileengine, self)._show(now) writeprogress(self, progressfile, filemode, self._bars) def _complete(self): super(fileengine, self)._complete() writeprogress(self, progressfile, filemode, []) currentengine.__class__ = fileengine currentengine._filewrapped = True return currentengine wrapfunction(progress, "getengine", wrapengine)
def extsetup(): # monkeypatch in the new version extensions.wrapfunction(webcommands, "_filerevision", filerevision_highlight) extensions.wrapfunction(webcommands, "annotate", annotate_highlight) webcommands.highlightcss = generate_css webcommands.__all__.append("highlightcss")
def extsetup(ui): entry = extensions.wrapcommand(commands.table, "push", _push) # Don't add the 'to' arg if it already exists if not any(a for a in entry[1] if a[1] == "to"): entry[1].append(("", "to", "", _("push revs to this bookmark"))) if not any(a for a in entry[1] if a[1] == "non-forward-move"): entry[1].append( ( "", "non-forward-move", None, _("allows moving a remote bookmark to an " "arbitrary place"), ) ) if not any(a for a in entry[1] if a[1] == "create"): entry[1].append(("", "create", None, _("create a new remote bookmark"))) entry[1].append( ("", "bundle-store", None, _("force push to go to bundle store (EXPERIMENTAL)")) ) bookcmd = extensions.wrapcommand(commands.table, "bookmarks", _bookmarks) bookcmd[1].append( ( "", "list-remote", None, "list remote bookmarks. " "Positional arguments are interpreted as wildcard patterns. " "Only allowed wildcard is '*' in the end of the pattern. " "If no positional arguments are specified then it will list " 'the most "important" remote bookmarks. ' "Otherwise it will list remote bookmarks " "that match at least one pattern " "", ) ) bookcmd[1].append( ("", "remote-path", "", "name of the remote path to list the bookmarks") ) extensions.wrapcommand(commands.table, "pull", _pull) extensions.wrapcommand(commands.table, "update", _update) extensions.wrapfunction(bundle2, "_addpartsfromopts", _addpartsfromopts) wireproto.wirepeer.listkeyspatterns = listkeyspatterns wireproto.wirepeer.knownnodes = knownnodes # Move infinitepush part before pushrebase part # to avoid generation of both parts. partorder = exchange.b2partsgenorder index = partorder.index("changeset") if constants.pushrebaseparttype in partorder: index = min(index, partorder.index(constants.pushrebaseparttype)) partorder.insert( index, partorder.pop(partorder.index(constants.scratchbranchparttype)) )
def extsetup(ui): # No need to enable directaccess if narrow-heads is enabled. if ui.configbool("experimental", "narrow-heads"): return extensions.wrapfunction(revset, "posttreebuilthook", _posttreebuilthook) extensions.wrapfunction(hg, "repository", _repository) setupdirectaccess()
def uisetup(ui): # Wrap util.log as an inner function so that we can use the ui object. def utillog(orig, event, *msg, **opts): for ui in loguis: logevent(ui, event, *msg, **opts) return orig(event, *msg, **opts) extensions.wrapfunction(util, "log", utillog)
def _smartlogloaded(loaded): smartlog = None try: smartlog = extensions.find("smartlog") except KeyError: pass if smartlog: extensions.wrapfunction(smartlog, "getdag", _getsmartlogdag)
def replaceremotefctxannotate(): try: r = extensions.find("remotefilelog") except KeyError: return else: extensions.wrapfunction(r.remotefilectx.remotefilectx, "annotate", _remotefctxannotate)
def extsetup(ui): wireproto.commands["listkeyspatterns"] = ( wireprotolistkeyspatterns, "namespace patterns", ) wireproto.commands["knownnodes"] = (wireprotoknownnodes, "nodes *") extensions.wrapfunction(debugcommands, "_debugbundle2part", debugbundle2part) extensions.wrapfunction(bundlerepo.bundlerepository, "_handlebundle2part", bundlerepohandlebundle2part)
def transaction(self, *args, **kwargs): tr = super(globalrevsrepo, self).transaction(*args, **kwargs) if tr.count > 1: return tr def transactionabort(orig): self._nextrevisionnumber = None return orig() extensions.wrapfunction(tr, "_abort", transactionabort) return tr
def _extend_histedit(ui): histedit = extensions.find("histedit") _aliases, entry = cmdutil.findcmd("histedit", histedit.cmdtable) options = entry[1] options.append(("x", "retry", False, _("retry exec command that failed and try to continue"))) options.append(("", "show-plan", False, _("show remaining actions list"))) extensions.wrapfunction(histedit, "_histedit", _histedit) extensions.wrapfunction(histedit, "parserules", parserules)
def extsetup(ui): schemes.update(dict(ui.configitems("schemes"))) t = templater.engine(lambda x: x) for scheme, url in schemes.items(): if (pycompat.iswindows and len(scheme) == 1 and scheme.isalpha() and os.path.exists("%s:\\" % scheme)): raise error.Abort( _("custom scheme %s:// conflicts with drive " "letter %s:\\\n") % (scheme, scheme.upper())) hg.schemes[scheme] = ShortRepository(url, scheme, t) extensions.wrapfunction(util, "hasdriveletter", hasdriveletter)
def extsetup(ui): extensions.wrapfunction(localrepo.localrepository, "commitctx", _commitctx) def wrapshelve(loaded=False): try: shelvemod = extensions.find("shelve") extensions.wrapcommand(shelvemod.cmdtable, "shelve", _bypassdirsync) extensions.wrapcommand(shelvemod.cmdtable, "unshelve", _bypassdirsync) except KeyError: pass extensions.afterloaded("shelve", wrapshelve)
def uisetup(ui): if util.safehasattr(localrepo, "newreporequirements"): extensions.wrapfunction(localrepo, "newreporequirements", requirements) else: @replaceclass(localrepo, "localrepository") class lz4repo(localrepo.localrepository): def _baserequirements(self, create): reqs = super(lz4repo, self)._baserequirements(create) if create and self.ui.configbool("format", "uselz4", True): reqs.append("lz4revlog") return reqs @replaceclass(revlog, "revlog") class lz4revlog(revlog.revlog): def __init__(self, opener, indexfile, **kwds): super(lz4revlog, self).__init__(opener, indexfile, **kwds) opts = getattr(opener, "options", None) self._lz4 = opts and "lz4revlog" in opts def compress(self, text): if util.safehasattr(self, "_lz4") and self._lz4: if not text: return ("", text) c = lz4compresshc(text) if len(text) <= len(c): if text[0] == "\0": return ("", text) return ("u", text) return ("", "4" + c) return super(lz4revlog, self).compress(text) def decompress(self, bin): if not bin: return bin t = bin[0] if t == "\0": return bin if t == "4": return lz4decompress(bin[1:]) return super(lz4revlog, self).decompress(bin) cls = localrepo.localrepository for reqs in "supportedformats openerreqs".split(): getattr(cls, reqs).add("lz4revlog") if util.safehasattr(cls, "_basesupported"): # hg >= 2.8. Since we're good at falling back to the usual revlog, we # aren't going to bother with enabling ourselves per-repository. cls._basesupported.add("lz4revlog") else: # hg <= 2.7 cls.supported.add("lz4revlog")
def uisetup(ui): class extralogui(ui.__class__): def log(self, event, *msg, **opts): logevent(self, event, *msg, **opts) return super(extralogui, self).log(event, *msg, **opts) ui.__class__ = extralogui # Wrap util.log as an inner function so that we can use the ui object. def utillog(orig, event, *msg, **opts): logevent(ui, event, *msg, **opts) return orig(event, *msg, **opts) extensions.wrapfunction(util, "log", utillog)
def extsetup(ui) -> None: extensions.wrapfunction(dispatch, "runcommand", runcommand) extensions.wrapfunction(bookmarks.bmstore, "_write", recordbookmarks) extensions.wrapfilecache(localrepo.localrepository, "dirstate", wrapdirstate) extensions.wrapfunction(hg, "postshare", wrappostshare) extensions.wrapfunction(hg, "copystore", unsharejournal)
def uisetup(ui): """Wraps user facing Mercurial commands to swap them out with shallow versions. """ hg.wirepeersetupfuncs.append(fileserverclient.peersetup) entry = extensions.wrapcommand(commands.table, "clone", cloneshallow) entry[1].append(( "", "shallow", None, _("create a shallow clone which uses remote file " "history"), )) extensions.wrapcommand(commands.table, "debugindex", debugcommands.debugindex) extensions.wrapcommand(commands.table, "debugindexdot", debugcommands.debugindexdot) extensions.wrapcommand(commands.table, "log", log) extensions.wrapcommand(commands.table, "pull", pull) extensions.wrapfunction(bundle2, "getrepocaps", getrepocaps) # Prevent 'hg manifest --all' def _manifest(orig, ui, repo, *args, **opts): if shallowrepo.requirement in repo.requirements and opts.get("all"): raise error.Abort(_("--all is not supported in a shallow repo")) return orig(ui, repo, *args, **opts) extensions.wrapcommand(commands.table, "manifest", _manifest) # Wrap remotefilelog with lfs code def _lfsloaded(loaded=False): lfsmod = None try: lfsmod = extensions.find("lfs") except KeyError: pass if lfsmod: lfsmod.wrapfilelog(remotefilelog.remotefilelog) fileserverclient._lfsmod = lfsmod extensions.afterloaded("lfs", _lfsloaded) # debugdata needs remotefilelog.len to work extensions.wrapcommand(commands.table, "debugdata", debugdatashallow) wrappackers()
def uisetup(ui): if util.safehasattr(cmdutil, "openrevlog") and not util.safehasattr( commands, "debugrevlogopts"): # for "historical portability": # In this case, Mercurial should be 1.9 (or a79fea6b3e77) - # 3.7 (or 5606f7d0d063). Therefore, '--dir' option for # openrevlog() should cause failure, because it has been # available since 3.5 (or 49c583ca48c4). def openrevlog(orig, repo, cmd, file_, opts): if opts.get("dir") and not util.safehasattr(repo, "dirlog"): raise error.Abort("This version doesn't support --dir option", hint="use 3.5 or later") return orig(repo, cmd, file_, opts) extensions.wrapfunction(cmdutil, "openrevlog", openrevlog)
def extsetup(ui): extensions.wrapfunction(dirstate.dirstate, "_poststatusfixup", _poststatusfixup) extensions.wrapfunction(context.committablectx, "markcommitted", markcommitted) extensions.wrapfunction(treedirstate.treedirstatemap, "write", treedirstatewrite) extensions.wrapfunction(treestate.treestatemap, "write", treestatewrite)
def pushbackupbundle(ui, repo, other, outgoing, bookmarks): """ push a backup bundle to the server Pushes an infinitepush bundle containing the commits described in `outgoing` and the bookmarks described in `bookmarks` to the `other` server. """ # Wrap deltaparent function to make sure that bundle takes less space # See _deltaparent comments for details extensions.wrapfunction(changegroup.cg2packer, "deltaparent", _deltaparent) try: bundler = _createbundler(ui, repo, other) bundler.addparam("infinitepush", "True") pushvarspart = bundler.newpart("pushvars") pushvarspart.addparam("BYPASS_READONLY", "True", mandatory=False) backup = False if outgoing and not outgoing.missing and not bookmarks: ui.status(_("nothing to back up\n")) return True if outgoing and outgoing.missing: backup = True parts = bundleparts.getscratchbranchparts( repo, other, outgoing, confignonforwardmove=False, ui=ui, bookmark=None, create=False, bookmarknode=None, ) for part in parts: bundler.addpart(part) if bookmarks: backup = True bundler.addpart( bundleparts.getscratchbookmarkspart(other, bookmarks)) if backup: _sendbundle(bundler, other) return backup finally: extensions.unwrapfunction(changegroup.cg2packer, "deltaparent", _deltaparent)
def reposetup(ui, repo): synccheckout = ui.configbool("commitcloud", "synccheckoutlocations") def _sendlocation(orig, self, ui, prefix, *args, **kwargs): if prefix == "post": parents = [ nodemod.hex(p) if p != nodemod.nullid else "" for p in self._pl ] p1 = parents[0] # TODO(T52387128): do it asynchronously in the background checkoutlocations.send(ui, repo, p1, **kwargs) return orig(self, ui, prefix) if synccheckout: extensions.wrapfunction(localrepo.dirstate.dirstate, "loginfo", _sendlocation) class commitcloudrepo(repo.__class__): def transaction(self, *args, **kwargs): def finalize(tr): for obj in tr, self: if (hgutil.safehasattr( obj, "_commitcloudskippendingobsmarkers") and obj._commitcloudskippendingobsmarkers): return markers = tr.changes["obsmarkers"] if markers: obsmarkers.addpendingobsmarkers(self, markers) tr = super(commitcloudrepo, self).transaction(*args, **kwargs) tr.addfinalize("commitcloudobsmarkers", finalize) return tr def automigratefinish(self): super(commitcloudrepo, self).automigratefinish() automigrate = self.ui.configbool("commitcloud", "automigrate") if (automigrate and not workspace.disconnected(self) and background.autobackupenabled(self)): workspacename = None if self.ui.configbool("commitcloud", "automigratehostworkspace"): workspacename = workspace.hostnameworkspace(self.ui) cccommands.cloudrejoin(self.ui, self, raw_workspace=workspacename) repo.__class__ = commitcloudrepo
def exchangepull(orig, repo, remote, *args, **kwargs): # Hook into the callstream/getbundle to insert bundle capabilities # during a pull. def localgetbundle( orig, source, heads=None, common=None, bundlecaps=None, **kwargs ): if not bundlecaps: bundlecaps = set() bundlecaps.add("remotefilelog") return orig(source, heads=heads, common=common, bundlecaps=bundlecaps, **kwargs) if util.safehasattr(remote, "_callstream"): remote._localrepo = repo elif util.safehasattr(remote, "getbundle"): wrapfunction(remote, "getbundle", localgetbundle) return orig(repo, remote, *args, **kwargs)
def setup_streamout(repo, remote): # Replace remote.stream_out with a version that sends file # patterns. def stream_out_shallow(orig): caps = shallowutil.peercapabilities(remote) if shallowrepo.requirement in caps: opts = {} if repo.includepattern: opts["includepattern"] = "\0".join(repo.includepattern) if repo.excludepattern: opts["excludepattern"] = "\0".join(repo.excludepattern) if repo.ui.configbool("treemanifest", "treeonly"): opts["noflatmanifest"] = "True" return remote._callstream("stream_out_shallow", **opts) else: return orig() wrapfunction(remote, "stream_out", stream_out_shallow)
def extsetup(ui): # Wrap the APIs used to get the revisions for "hg log" so we # can peekahead into the rev list and query phabricator for multiple diffs # at once. extensions.wrapfunction(cmdutil, "getlogrevs", _getlogrevs) extensions.wrapfunction(cmdutil, "getgraphlogrevs", _getlogrevs) # Also wrap the APIs used by smartlog def _smartlogloaded(loaded): smartlog = None try: smartlog = extensions.find("smartlog") except KeyError: pass if smartlog: extensions.wrapfunction(smartlog, "getdag", _getsmartlogdag) extensions.afterloaded("smartlog", _smartlogloaded)
def extsetup(ui): templatekw.keywords.update({"gitnode": gitnodekw}) revset.symbols.update({ "fromgit": revset_fromgit, "gitnode": revset_gitnode }) helpdir = os.path.join(os.path.dirname(__file__), "help") entry = ( ["git"], _("Working with Git Repositories"), # Mercurial >= 3.6: doc(ui) lambda *args: open(os.path.join(helpdir, "git.rst")).read(), ) insort(help.helptable, entry) # Mercurial >= 3.2 extensions.wrapfunction(exchange, "pull", exchangepull) # Mercurial >= 3.4 extensions.wrapfunction(manifest.manifestdict, "diff", overlay.wrapmanifestdictdiff)
def uisetup(ui): extensions.wrapfunction(localrepo, "newreporequirements", _newreporequirementswrapper) def _hgsqlwrapper(loaded): if loaded: hgsqlmod = extensions.find("hgsql") extensions.wrapfunction(hgsqlmod, "wraprepo", _sqllocalrepowrapper) # We only wrap `hgsql` extension for embedding strictly increasing global # revision number in commits if the repository has `hgsql` enabled and it is # also configured to write data to the commits. Therefore, do not wrap the # extension if that is not the case. if not ui.configbool("globalrevs", "readonly") and not ishgsqlbypassed(ui): extensions.afterloaded("hgsql", _hgsqlwrapper) cls = localrepo.localrepository for reqs in ["_basesupported", "supportedformats"]: getattr(cls, reqs).add("globalrevs")
def reposetup(ui, repo): synccheckout = ui.configbool("commitcloud", "synccheckoutlocations") def _sendlocation(orig, self, ui, prefix, *args, **kwargs): if prefix == "post": parents = [ nodemod.hex(p) if p != nodemod.nullid else "" for p in self._pl ] p1 = parents[0] # TODO(T52387128): do it asynchronously in the background checkoutlocations.send(ui, repo, p1, **kwargs) return orig(self, ui, prefix) if synccheckout: extensions.wrapfunction(localrepo.dirstate.dirstate, "loginfo", _sendlocation) class commitcloudrepo(repo.__class__): def automigratefinish(self): super(commitcloudrepo, self).automigratefinish() # Do not auto rejoin if the repo has "broken" (incomplete) commit # graph. automigrate = self.ui.configbool( "commitcloud", "automigrate") and ("emergencychangelog" not in self.storerequirements) if (automigrate and not workspace.disconnected(self) and background.autobackupenabled(self)): workspacename = None if self.ui.configbool("commitcloud", "automigratehostworkspace"): workspacename = workspace.hostnameworkspace(self.ui) try: cccommands.cloudrejoin(self.ui, self, raw_workspace=workspacename) except Exception as ex: self.ui.warn( _("warning: failed to auto-join cloud workspace: '%s'\n" ) % ex) repo.__class__ = commitcloudrepo