コード例 #1
0
def _revsetutil(repo, subset, x, rtypes):
    """utility function to return a set of revs based on the rtypes"""
    args = revsetlang.getargs(x, 0, 1, _(b'only one argument accepted'))
    if args:
        kind, pattern, matcher = stringutil.stringmatcher(
            revsetlang.getstring(args[0], _(b'argument must be a string')))
    else:
        kind = pattern = None
        matcher = util.always

    nodes = set()
    cl = repo.changelog
    for rtype in rtypes:
        if rtype in repo.names:
            ns = repo.names[rtype]
            for name in ns.listnames(repo):
                if not matcher(name):
                    continue
                nodes.update(ns.nodes(repo, name))
    if kind == b'literal' and not nodes:
        raise error.RepoLookupError(
            _(b"remote name '%s' does not exist") % pattern)

    revs = (cl.rev(n) for n in nodes if cl.hasnode(n))
    return subset & smartset.baseset(revs)
コード例 #2
0
def commonsetup(ui):
    wireprotov1server.commands['listkeyspatterns'] = (
        wireprotolistkeyspatterns, 'namespace patterns')
    scratchbranchpat = ui.config('infinitepush', 'branchpattern')
    if scratchbranchpat:
        global _scratchbranchmatcher
        kind, pat, _scratchbranchmatcher = \
                stringutil.stringmatcher(scratchbranchpat)
コード例 #3
0
    def filtered(self, namespace=None, name=None):
        """Yield all journal entries with the given namespace or name

        Both the namespace and the name are optional; if neither is given all
        entries in the journal are produced.

        Matching supports regular expressions by using the `re:` prefix
        (use `literal:` to match names or namespaces that start with `re:`)

        """
        if namespace is not None:
            namespace = stringutil.stringmatcher(namespace)[-1]
        if name is not None:
            name = stringutil.stringmatcher(name)[-1]
        for entry in self:
            if namespace is not None and not namespace(entry.namespace):
                continue
            if name is not None and not name(entry.name):
                continue
            yield entry
コード例 #4
0
 def _listbookmarks(self, pattern):
     if pattern.endswith(b'*'):
         pattern = b're:^' + pattern[:-1] + b'.*'
     kind, pat, matcher = stringutil.stringmatcher(pattern)
     prefixlen = len(self._bookmarkmap) + 1
     for dirpath, _, books in self._repo.vfs.walk(self._bookmarkmap):
         for book in books:
             bookmark = os.path.join(dirpath, book)[prefixlen:]
             bookmark = util.pconvert(bookmark)
             if not matcher(bookmark):
                 continue
             yield bookmark, self._read(os.path.join(dirpath, book))
コード例 #5
0
def branch(repo, subset, x):
    # type: (gitrepository, abstractsmartset, Tuple) -> abstractsmartset
    """
    All changesets belonging to the given branch or the branches of the given
    changesets.

    Pattern matching is supported for `string`. See
    :hg:`help revisions.patterns`.
    """
    def getbranchrevs(r):
        return set(branches_with(repo._repo, r))

    # FIXME: look into sorting by branch name, to keep results stable
    branchrevs = set()
    revspec = False

    try:
        b = revset.getstring(x, '')
    except error.ParseError:
        # not a string, but another revspec, e.g. tip()
        revspec = True
    else:
        kind, pattern, matcher = stringutil.stringmatcher(b)
        branchmap = repo.branchmap()
        if kind == 'literal':
            # note: falls through to the revspec case if no branch with
            # this name exists and pattern kind is not specified explicitly
            if pattern in branchmap:
                branchrevs.add(branchmap[b][0])
            elif b.startswith('literal:'):
                raise error.RepoLookupError(
                    _("branch '%s' does not exist") % pattern)
            else:
                revspec = True
        else:
            branchrevs.update(r[0] for b, r in branchmap.items() if matcher(b))

    if revspec:
        # get all the branches in x
        s = revset.getset(repo, gitfullreposet(repo), x)
        for r in s:
            branchrevs.update(getbranchrevs(r))

    if not branchrevs:
        # FIXME: return empty set or subset?
        raise NotImplementedError

    brs = list(branchrevs)
    s = gitfullreposet(repo, heads=brs)
    return subset & s
コード例 #6
0
def localrepolistkeys(orig, self, namespace, patterns=None):
    if namespace == 'bookmarks' and patterns:
        index = self.bundlestore.index
        results = {}
        bookmarks = orig(self, namespace)
        for pattern in patterns:
            results.update(index.getbookmarks(pattern))
            if pattern.endswith('*'):
                pattern = 're:^' + pattern[:-1] + '.*'
            kind, pat, matcher = stringutil.stringmatcher(pattern)
            for bookmark, node in bookmarks.iteritems():
                if matcher(bookmark):
                    results[bookmark] = node
        return results
    else:
        return orig(self, namespace)
コード例 #7
0
ファイル: revsets.py プロジェクト: danchr/hg-git
def revset_gittag(repo, subset, x):
    """``gittag([name])``

    The specified Git tag by name, or all revisions tagged with Git if
    no name is given.

    Pattern matching is supported for `name`. See
    :hg:`help revisions.patterns`.

    """
    # mostly copied from tag() mercurial/revset.py

    # i18n: "tag" is a keyword
    args = revset.getargs(x, 0, 1, _(b"tag takes one or no arguments"))
    cl = repo.changelog
    git = repo.githandler

    if args:
        pattern = revset.getstring(
            args[0],
            # i18n: "tag" is a keyword
            _(b'the argument to tag must be a string'),
        )
        kind, pattern, matcher = stringutil.stringmatcher(pattern)
        if kind == b'literal':
            # avoid resolving all tags
            tn = git.tags.get(pattern, None)
            if tn is None:
                raise error.RepoLookupError(
                    _(b"git tag '%s' does not exist") % pattern)
            s = {repo[bin(tn)].rev()}
        else:
            s = {cl.rev(bin(n)) for t, n in git.tags.items() if matcher(t)}
    else:
        s = {cl.rev(bin(n)) for t, n in git.tags.items()}
    return subset & s