[PATCH 05 of 11] mdiff: make unidiff filter hunks out of specified line ranges

Yuya Nishihara yuya at tcha.org
Fri Feb 24 11:21:39 EST 2017


On Wed, 22 Feb 2017 16:09:59 +0100, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde at logilab.fr>
> # Date 1484921181 -3600
> #      Fri Jan 20 15:06:21 2017 +0100
> # Node ID 9090c35a37b14e5e09d0911d4794b65ee9ed35de
> # Parent  4d83e067c9c6e0f5fb7b126a9739aa9dd8113af4
> # EXP-Topic linerange-log/hgweb-filelog
> mdiff: make unidiff filter hunks out of specified line ranges

> @@ -258,7 +260,7 @@ def unidiff(a, ad, b, bd, fn1, fn2, opts
>  # creates a headerless unified diff
>  # t1 and t2 are the text to be diffed
>  # l1 and l2 are the text broken up into lines
> -def _unidiff(t1, t2, l1, l2, opts=defaultopts):
> +def _unidiff(t1, t2, l1, l2, opts=defaultopts, range1=None, range2=None):
>      def contextend(l, len):
>          ret = l + opts.context
>          if ret > len:
> @@ -315,6 +317,10 @@ def _unidiff(t1, t2, l1, l2, opts=defaul
>      ignoredlines = 0
>      for s, stype in allblocks(t1, t2, opts, l1, l2):
>          a1, a2, b1, b2 = s
> +        if range1 is not None and not (range1[0] < a2 and a1 < range1[1]):
> +            continue
> +        if range2 is not None and not (range2[0] < b2 and b1 < range2[1]):
> +            continue

Maybe range1/range2 could be specified as a function to filter blocks so
that we can apply e.g. blocksinrange() as needed. But that would slightly
complicate the next patch. I don't know which is better.

The change looks good.


More information about the Mercurial-devel mailing list