On Wed, 04 Oct 2017 17:04:00 +0200, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxa...@logilab.fr>
> # Date 1507127862 -7200
> #      Wed Oct 04 16:37:42 2017 +0200
> # Node ID f7b31d85dc0e7c7e60b85d0a7fd728a32ba210ea
> # Parent  3d8ed7dafee4676b49922a3dde0edf1b1fad63ec
> # Available At http://hg.logilab.org/users/dlaxalde/hg
> #              hg pull http://hg.logilab.org/users/dlaxalde/hg -r f7b31d85dc0e
> # EXP-Topic followlines-cli
> diff: pass down line range information from changeset_printer to patch.diff()

> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -2293,7 +2293,8 @@ def difffeatureopts(ui, opts=None, untru
>      return mdiff.diffopts(**pycompat.strkwargs(buildopts))
>  
>  def diff(repo, node1=None, node2=None, match=None, changes=None,
> -         opts=None, losedatafn=None, prefix='', relroot='', copy=None):
> +         opts=None, losedatafn=None, prefix='', relroot='', copy=None,
> +         lineranges=None):
>      '''yields diff of changes to files between two nodes, or node and
>      working directory.
>  
> @@ -2315,11 +2316,23 @@ def diff(repo, node1=None, node2=None, m
>      patterns that fall outside it will be ignored.
>  
>      copy, if not empty, should contain mappings {dst@y: src@x} of copy
> -    information.'''
> +    information.
> +
> +    lineranges, if not None, must be a mapping from filename to line range
> +    tuples and is used to filter diff hunks not in specified range.
> +    '''
>      for hdr, hunks in diffhunks(repo, node1=node1, node2=node2, match=match,
>                                  changes=changes, opts=opts,
>                                  losedatafn=losedatafn, prefix=prefix,
>                                  relroot=relroot, copy=copy):
> +        if lineranges is not None and hdr:
> +            fname = header(hdr).filename()

Parsing header line doesn't seem right. Can we get the original filename or
file ctxs instead?

> +            flineranges = lineranges.get(fname)
> +            if flineranges is not None:
> +                hunks = (
> +                    (hr, lines) for hr, lines in hunks
> +                    if any(mdiff.hunkinrange(hr[2:], lr) for lr in 
> flineranges)
> +                )

Nested iterators seems hard to read. Maybe this could be a filter function,
which could optionally be an argument. i.e. diff(..., filter) instead of
diff(..., lineranges).
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to