changeset 34904:4554649a6ea4

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.
author Denis Laxalde <denis@laxalde.org>
date Wed, 18 Oct 2017 19:00:33 +0200
parents 16d9f0b3e134
children 5c7dbb730179
files mercurial/cmdutil.py tests/test-log-linerange.t
diffstat 2 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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