[PATCH 3 of 3] revset: add a changes(file, fromline, toline[, rev]) revset
Yuya Nishihara
yuya at tcha.org
Wed Nov 30 15:09:27 UTC 2016
On Mon, 28 Nov 2016 10:54:16 +0100, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde at logilab.fr>
> # Date 1480086890 -3600
> # Fri Nov 25 16:14:50 2016 +0100
> # Node ID e88a112076294d9b1639a486e7ef0ec9c1ffa660
> # Parent 6dd93ae7b35002531308444c87dcf47beb773648
> # EXP-Topic linerange-log/revset
> revset: add a changes(file, fromline, toline[, rev]) revset
>
> This relies on `filectx.blocksancetors(fromline, toline)`.
>
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -18,6 +18,7 @@ from . import (
> error,
> hbisect,
> match as matchmod,
> + mdiff,
unused.
> + at predicate('changes(file, fromline, toline, rev)', safe=True)
> +def changes(repo, subset, x):
> + """Changesets modifying 'file' in line range ('fromline', 'toline').
> +
> + Line range corresponds to 'file' content at 'rev'. If rev is not
> + specified, working directory's parent is used.
> + """
> + args = map(getsymbol,
> + getargs(x, 3, 4, _('changes takes at least three arguments')))
file can be a string, and rev should be a revset expression.
> + fname = args[0]
> +
> + try:
> + fromline, toline = map(int, args[1:3])
> + except ValueError:
> + raise error.ParseError(_('line range bounds must be integers'))
> + if toline - fromline < 0:
> + raise error.Abort("line range must be positive")
> + if fromline < 1:
> + raise error.Abort("fromline must be > 0")
> + fromline -= 1
> +
> + rev = '.'
> + if len(args) == 4:
> + rev = args[3]
> + fctx = repo[rev].filectx(fname)
file path is relative to the current directory in general.
> + revs = (c.rev() for c in fctx.blockancestors(fromline, toline))
> + return subset & generatorset(revs, iterasc=False)
More information about the Mercurial-devel
mailing list