[PATCH 1 of 5] log: handle binary files in --line-range patterns

Denis Laxalde denis at laxalde.org
Thu Oct 19 13:51:46 UTC 2017


# HG changeset patch
# User Denis Laxalde <denis at laxalde.org>
# Date 1508346033 -7200
#      Wed Oct 18 19:00:33 2017 +0200
# Node ID a5f0f523e960a7aa3ded8dd5d120058bc2a37044
# Parent  315e04247750ad4983d648d3ba002eb328624b70
# EXP-Topic followlines-cli
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 --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2652,6 +2652,9 @@ def getloglinerangerevs(repo, userrevs, 
                 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 --git a/tests/test-log-linerange.t b/tests/test-log-linerange.t
--- a/tests/test-log-linerange.t
+++ b/tests/test-log-linerange.t
@@ -849,6 +849,39 @@ Renames are followed.
   +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


More information about the Mercurial-devel mailing list