# HG changeset patch # User Denis Laxalde # Date 1508346033 -7200 # Node ID 4554649a6ea4ab1fb4a672e1a0f6a52cdf631c30 # Parent 16d9f0b3e13459ba4020409e514a02f01791ad5b log: handle binary files in --line-range patterns When a file is binary patch.trydiff() would yield None for 'hunkrange'. Handle this case in the hunksfilter() callback. Add tests with and without diff.git option as binary handling differs depending on this option's value. diff -r 16d9f0b3e134 -r 4554649a6ea4 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Tue Oct 17 22:46:08 2017 +0200 +++ b/mercurial/cmdutil.py Wed Oct 18 19:00:33 2017 +0200 @@ -2652,6 +2652,9 @@ lineranges = fctxlineranges.get(fctx.path()) if lineranges is not None: for hr, lines in hunks: + if hr is None: # binary + yield hr, lines + continue if any(mdiff.hunkinrange(hr[2:], lr) for lr in lineranges): yield hr, lines diff -r 16d9f0b3e134 -r 4554649a6ea4 tests/test-log-linerange.t --- a/tests/test-log-linerange.t Tue Oct 17 22:46:08 2017 +0200 +++ b/tests/test-log-linerange.t Wed Oct 18 19:00:33 2017 +0200 @@ -849,6 +849,39 @@ +3 +4 + +Binary files work but without diff hunks filtering. +(Checking w/ and w/o diff.git option.) + + >>> open('binary', 'w').write('this\nis\na\nbinary\0') + $ hg add binary + $ hg ci -m 'add a binary file' --quiet + $ hg log -f -L binary,1-2 -p + changeset: 10:c96381c229df + tag: tip + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: add a binary file + + diff --git a/dir/binary b/dir/binary + new file mode 100644 + index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c2e1fbed209fe919b3f189a6a31950e9adf61e45 + GIT binary patch + literal 17 + Wc$_QA$SmdpqC~Ew%)G>+N(KNlNClYy + + + $ hg log -f -L binary,1-2 -p --config diff.git=false + changeset: 10:c96381c229df + tag: tip + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: add a binary file + + diff -r 6af29c3a778f -r c96381c229df dir/binary + Binary file dir/binary has changed + + Option --follow is required. $ hg log -L foo,5-7