Exemplo n.º 1
0
def revrange(repo, revs):
    """Yield revision as strings from a list of revision specifications."""

    def revfix(repo, val, defval):
        if not val and val != 0 and defval is not None:
            return defval
        return repo[val].rev()

    subsets = []

    revsetaliases = [alias for (alias, _) in
                     repo.ui.configitems("revsetalias")]

    for spec in revs:
        # attempt to parse old-style ranges first to deal with
        # things like old-tag which contain query metacharacters
        try:
            # ... except for revset aliases without arguments. These
            # should be parsed as soon as possible, because they might
            # clash with a hash prefix.
            if spec in revsetaliases:
                raise error.RepoLookupError

            if isinstance(spec, int):
                subsets.append(revset.baseset([spec]))
                continue

            if _revrangesep in spec:
                start, end = spec.split(_revrangesep, 1)
                if start in revsetaliases or end in revsetaliases:
                    raise error.RepoLookupError

                start = revfix(repo, start, 0)
                end = revfix(repo, end, len(repo) - 1)
                if end == nullrev and start < 0:
                    start = nullrev
                if start < end:
                    l = revset.spanset(repo, start, end + 1)
                else:
                    l = revset.spanset(repo, start, end - 1)
                subsets.append(l)
                continue
            elif spec and spec in repo: # single unquoted rev
                rev = revfix(repo, spec, None)
                subsets.append(revset.baseset([rev]))
                continue
        except error.RepoLookupError:
            pass

        # fall through to new-style queries if old-style fails
        m = revset.match(repo.ui, spec, repo)
        subsets.append(m(repo))

    return revset._combinesets(subsets)
Exemplo n.º 2
0
def revrange(repo, revs):
    """Yield revision as strings from a list of revision specifications."""
    def revfix(repo, val, defval):
        if not val and val != 0 and defval is not None:
            return defval
        return repo[val].rev()

    subsets = []

    revsetaliases = [
        alias for (alias, _) in repo.ui.configitems("revsetalias")
    ]

    for spec in revs:
        # attempt to parse old-style ranges first to deal with
        # things like old-tag which contain query metacharacters
        try:
            # ... except for revset aliases without arguments. These
            # should be parsed as soon as possible, because they might
            # clash with a hash prefix.
            if spec in revsetaliases:
                raise error.RepoLookupError

            if isinstance(spec, int):
                subsets.append(revset.baseset([spec]))
                continue

            if _revrangesep in spec:
                start, end = spec.split(_revrangesep, 1)
                if start in revsetaliases or end in revsetaliases:
                    raise error.RepoLookupError

                start = revfix(repo, start, 0)
                end = revfix(repo, end, len(repo) - 1)
                if end == nullrev and start < 0:
                    start = nullrev
                if start < end:
                    l = revset.spanset(repo, start, end + 1)
                else:
                    l = revset.spanset(repo, start, end - 1)
                subsets.append(l)
                continue
            elif spec and spec in repo:  # single unquoted rev
                rev = revfix(repo, spec, None)
                subsets.append(revset.baseset([rev]))
                continue
        except error.RepoLookupError:
            pass

        # fall through to new-style queries if old-style fails
        m = revset.match(repo.ui, spec, repo)
        subsets.append(m(repo))

    return revset._combinesets(subsets)
Exemplo n.º 3
0
def revrange(repo, revs):
    """Yield revision as strings from a list of revision specifications."""

    def revfix(repo, val, defval):
        if not val and val != 0 and defval is not None:
            return defval
        return repo[val].rev()

    seen, l = set(), revset.baseset([])
    for spec in revs:
        if l and not seen:
            seen = set(l)
        # attempt to parse old-style ranges first to deal with
        # things like old-tag which contain query metacharacters
        try:
            if isinstance(spec, int):
                seen.add(spec)
                l = l + revset.baseset([spec])
                continue

            if _revrangesep in spec:
                start, end = spec.split(_revrangesep, 1)
                start = revfix(repo, start, 0)
                end = revfix(repo, end, len(repo) - 1)
                if end == nullrev and start < 0:
                    start = nullrev
                rangeiter = repo.changelog.revs(start, end)
                if not seen and not l:
                    # by far the most common case: revs = ["-1:0"]
                    l = revset.baseset(rangeiter)
                    # defer syncing seen until next iteration
                    continue
                newrevs = set(rangeiter)
                if seen:
                    newrevs.difference_update(seen)
                    seen.update(newrevs)
                else:
                    seen = newrevs
                l = l + revset.baseset(sorted(newrevs, reverse=start > end))
                continue
            elif spec and spec in repo:  # single unquoted rev
                rev = revfix(repo, spec, None)
                if rev in seen:
                    continue
                seen.add(rev)
                l = l + revset.baseset([rev])
                continue
        except error.RepoLookupError:
            pass

        # fall through to new-style queries if old-style fails
        m = revset.match(repo.ui, spec, repo)
        if seen or l:
            dl = [r for r in m(repo, revset.spanset(repo)) if r not in seen]
            l = l + revset.baseset(dl)
            seen.update(dl)
        else:
            l = m(repo, revset.spanset(repo))

    return l
Exemplo n.º 4
0
def revrange(repo, revs):
    """Yield revision as strings from a list of revision specifications."""

    def revfix(repo, val, defval):
        if not val and val != 0 and defval is not None:
            return defval
        return repo[val].rev()

    seen, l = set(), revset.baseset([])
    for spec in revs:
        if l and not seen:
            seen = set(l)
        # attempt to parse old-style ranges first to deal with
        # things like old-tag which contain query metacharacters
        try:
            if isinstance(spec, int):
                seen.add(spec)
                l = l + revset.baseset([spec])
                continue

            if _revrangesep in spec:
                start, end = spec.split(_revrangesep, 1)
                start = revfix(repo, start, 0)
                end = revfix(repo, end, len(repo) - 1)
                if end == nullrev and start < 0:
                    start = nullrev
                rangeiter = repo.changelog.revs(start, end)
                if not seen and not l:
                    # by far the most common case: revs = ["-1:0"]
                    l = revset.baseset(rangeiter)
                    # defer syncing seen until next iteration
                    continue
                newrevs = set(rangeiter)
                if seen:
                    newrevs.difference_update(seen)
                    seen.update(newrevs)
                else:
                    seen = newrevs
                l = l + revset.baseset(sorted(newrevs, reverse=start > end))
                continue
            elif spec and spec in repo: # single unquoted rev
                rev = revfix(repo, spec, None)
                if rev in seen:
                    continue
                seen.add(rev)
                l = l + revset.baseset([rev])
                continue
        except error.RepoLookupError:
            pass

        # fall through to new-style queries if old-style fails
        m = revset.match(repo.ui, spec, repo)
        if seen or l:
            dl = [r for r in m(repo, revset.spanset(repo)) if r not in seen]
            l = l + revset.baseset(dl)
            seen.update(dl)
        else:
            l = m(repo, revset.spanset(repo))

    return l