def revset_fromgit(repo, subset, x): """``fromgit()`` Select changesets that originate from Git. """ revset.getargs(x, 0, 0, "fromgit takes no arguments") git = repo.githandler node = repo.changelog.node return baseset(r for r in subset if git.map_git_get(hex(node(r))) is not None)
def gitnode(repo, subset, x): """``gitnode(id)`` Return the hg revision corresponding to a given git rev.""" l = revset.getargs(x, 1, 1, _("id requires one argument")) n = revset.getstring(l[0], _("id requires a string")) reponame = repo.ui.config("fbscmquery", "reponame") if not reponame: # We don't know who we are, so we can't ask for a translation return subset.filter(lambda r: False) backingrepos = repo.ui.configlist("fbscmquery", "backingrepos", default=[reponame]) lasterror = None hghash = None for backingrepo in backingrepos: try: client = graphql.Client(repo=repo) hghash = client.getmirroredrev(backingrepo, "git", reponame, "hg", n) if hghash != "": break except Exception as ex: lasterror = ex if not hghash: if lasterror: repo.ui.warn( ("Could not translate revision {0}: {1}\n".format(n, lasterror)) ) else: repo.ui.warn(("Could not translate revision {0}\n".format(n))) return subset.filter(lambda r: False) rn = repo[node.bin(hghash)].rev() return subset & smartset.baseset([rn])
def draftbranchrevset(repo, subset, x): """``draftbranch(set)`` The draft branches containing the given changesets. """ args = revset.getargs(x, 1, 1, _("draftbranch expects one argument")) revs = revset.getset(repo, subset, args[0]) return subset & repo.revs("(draft() & ::%ld)::", revs)
def _revsetsvnrev(repo, subset, x): """Changesets with given Subversion revision number.""" args = revset.getargs(x, 1, 1, "svnrev takes one argument") svnrev = revset.getinteger(args[0], "the argument to svnrev() must be a number") torev = repo.changelog.rev revs = revset.baseset((torev(n) for n in _lookupglobalrev(repo, svnrev)), repo=repo) return subset & revs
def mutrelatedrevset(repo, subset, x): """``mutrelated([set])`` Changesets that are related via mutations. """ args = revset.getargs(x, 1, 1, _("mutrelated expects one argument")) revs = revset.getset(repo, subset, args[0]) return subset & repo.revs("predecessors(%ld):: + successors(%ld)::", revs, revs)
def focusedbranchrevset(repo, subset, x): """``focusedbranch([set])`` The focused branches of the given changesets, being the draft stack and any draft changesets that are related via mutations. """ args = revset.getargs(x, 1, 1, _("focusedbranch expects one argument")) revs = revset.getset(repo, subset, args[0]) return subset & repo.revs("draft() & mutrelated(draftbranch(%ld)) + %ld", revs, revs)
def mutrelatedrevset(repo, subset, x): """``mutrelated([set])`` Draft changesets that are related via mutations. """ args = revset.getargs(x, 1, 1, _("mutrelated expects one argument")) revs = revset.getset(repo, subset, args[0]) return subset & repo.revs( "descendants((predecessors(%ld) + successors(%ld)) & not public())", revs, revs )
def gitnode(repo, subset, x): """``gitnode(id)`` Return the hg revision corresponding to a given git rev.""" l = revset.getargs(x, 1, 1, _("id requires one argument")) n = revset.getstring(l[0], _("id requires a string")) hexhgnode = _lookup_node(repo, n, from_scm_type="git") if not hexhgnode: raise error.RepoLookupError(_("unknown revision '%s'") % n) rev = repo[hexhgnode].rev() return subset.filter(lambda r: r == rev)
def cloudremote(repo, subset, x): """pull missing known changesets from the remote store Currently only for obsoleted commits, can be extended for any commit. """ args = revset.getargs(x, 1, 50, _("cloudremote takes from 1 to up to 50 hex revs")) args = [n[1] for n in args] try: hexnodespulled = missingcloudrevspull( repo, [nodemod.bin(nodehex) for nodehex in args]) return subset & repo.unfiltered().revs("%ls", hexnodespulled) except Exception as e: repo.ui.status( _("unable to pull all changesets from the remote store\n%s\n") % e, component="commitcloud", ) return smartset.baseset([])
def revset_gitnode(repo, subset, x): """``gitnode(hash)`` Select the changeset that originates in the given Git revision. The hash may be abbreviated: `gitnode(a5b)` selects the revision whose Git hash starts with `a5b`. Aborts if multiple changesets match the abbreviation. """ args = revset.getargs(x, 1, 1, "gitnode takes one argument") rev = revset.getstring(args[0], "the argument to gitnode() must be a hash") git = repo.githandler node = repo.changelog.node def matches(r): gitnode = git.map_git_get(hex(node(r))) if gitnode is None: return False return gitnode.startswith(rev) result = baseset(r for r in subset if matches(r)) if 0 <= len(result) < 2: return result raise LookupError(rev, git.map_file, _("ambiguous identifier"))
def grepdiffpredicate(repo, subset, x): """grepdiff: a revset for code archeology Sample usages are: $ hg log --rev "grepdiff('add:command')" mercurial/commands.py will only match changesets that add 'command' somewhere in the diff $ hg log --rev "grepdiff('remove:command')" mercurial/commands.py will match changesets which remove 'command' somewhere in the diff $ hg log --rev "grepdiff('delta:command') mercurial/commands.py" will mathc changesets where the number of 'command' adds is different from the number of 'command' removes in the diff $ hg log --rev "grepdiff('touch:command')" will only match changesets which either add or remove 'command' at least once in the diff $ hg log --rev "grepdiff('inc:command')" folder/file1.py folder/file2.py will match changesets which increase the number of occurrences of 'command' in the specified files $ hg log --rev "grepdiff('dec:command')" will match changesets which decrease the number of occurrences of 'command' """ err = _("wrong set of arguments passed to grepdiff revset") args = revset.getargs(x, 1, -1, err) files = None if len(args) > 1: files = set( pathutil.canonpath(repo.root, repo.getcwd(), arg[1]) for arg in args[1:]) pattern, processor = getpatternandprocessor(repo, args) def matcher(rev): res = processor(*ctxaddsremoves(repo[rev], files, pattern)) return res resset = subset.filter(matcher) return resset
def pushed(repo, subset, x): """Select changesets in any remote repository according to remotenames.""" revset.getargs(x, 0, 0, "pushed takes no arguments") return upstream_revs(lambda x: True, repo, subset, x)