[PATCH 3 of 3 V4] revset: add a followlines(file, fromline, toline[, rev]) revset
Yuya Nishihara
yuya at tcha.org
Sat Jan 7 05:26:35 EST 2017
On Wed, 04 Jan 2017 17:03:49 +0100, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde at logilab.fr>
> # Date 1483544869 -3600
> # Wed Jan 04 16:47:49 2017 +0100
> # Node ID e36f0540260ec2bf9e3f324bc7839d5409a3314b
> # Parent ae66a9ae337e267ecb47f8e2610c308fd81743b7
> # EXP-Topic linerange-log/revset
> revset: add a followlines(file, fromline, toline[, rev]) revset
Also looks good. I'll queue this.
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -1065,6 +1065,52 @@ def _followfirst(repo, subset, x):
> # of every revisions or files revisions.
> return _follow(repo, subset, x, '_followfirst', followfirst=True)
>
> + at predicate('followlines(file, fromline, toline[, rev=.])', safe=True)
I slightly prefer "fromline:toline" than "fromline, toline". I'll take a look
how that will complicate things and hopefully will send a patch before the
freeze.
> +def followlines(repo, subset, x):
> + """Changesets modifying `file` in line range ('fromline', 'toline').
> +
> + Line range corresponds to 'file' content at 'rev' and should hence be
> + consistent with file size. If rev is not specified, working directory's
> + parent is used.
> + """
> + from . import context # avoid circular import issues
> +
> + args = getargs(x, 3, 4, _("followlines takes at least three arguments"))
> +
> + rev = '.'
> + if len(args) == 4:
> + revarg = getargsdict(args[3], 'followlines', 'rev')
> + if 'rev' in revarg:
> + revs = getset(repo, fullreposet(repo), revarg['rev'])
> + if len(revs) != 1:
> + raise error.ParseError(
> + _("followlines expects exactly one revision"))
> + rev = revs.last()
> +
> + pat = getstring(args[0], _("followlines requires a pattern"))
> + if not matchmod.patkind(pat):
> + fname = pathutil.canonpath(repo.root, repo.getcwd(), pat)
> + else:
> + m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[rev])
> + files = [f for f in repo[rev] if m(f)]
> + if len(files) != 1:
> + raise error.ParseError(_("followlines expects exactly one file"))
> + fname = files[0]
> +
> + try:
> + fromline, toline = [int(getsymbol(a)) for a in args[1:3]]
More information about the Mercurial-devel
mailing list