1

If I'm combing through diffs using hg log -p or hg diff, it would be nice to see something like "binary file differs", rather than having to scroll through screenfulls of gibberish to get to the next file. Is there a configuration trick to do that?

(On preview, if there's no simple hg option to set, then there might be some hints in the right direction in this question. I would still need more help to get what I'm asking, though.)

Joshua Goldberg
  • 5,059
  • 2
  • 34
  • 39
  • could you please give a list of steps to reproduce a minimal example? currently tried and don't see such gibberish, just a line stating "Binary file some.blob has changed" – arhak Dec 16 '16 at 15:52
  • I want what you've got! When I have a changeset that changes a pdf, for instance, then either `hg log -pr` or `hg diff --change` are giving me output like: `GIT binary patch — literal 467997 — zc%0O_1#lcqvMxHZ(3UJ_mc6W7...` _(many lines)_ – Joshua Goldberg Dec 17 '16 at 00:42
  • There's a `-a` / `--text` option to force text output, if something is accidentally detected as binary, but the reverse doesn't seem to be provided. And I just learned binary detection is [based on the presense of NUL bytes in the file.](https://www.mercurial-scm.org/wiki/BinaryFiles) My pdf definitely has some strings of NUL bytes in it, though. – Joshua Goldberg Dec 17 '16 at 00:57

2 Answers2

4

With @arhak's help, I see the problem was this in my .hgrc

[diff]
git = True

I'd forgotten that I'd added that after reading this advice that git-style diffs are more readable than the patch-style diffs that are Mercurial's default. I can't find a description of the differences, but looking at a few diffs now, --git (-g) seems to leave out dates in the filename headers, and apparently, it also forces the full uuencode-style diff for binary files. I think I'll keep it as default, but turn it off if for the unusual situations where I'm looking at patches with lots of binary file changes.

To override at the commandline without editing .hgrc, add --config diff.git=False

I'd be curious if there's a way to skip the binaries, but keep git formatting for the regular text files in the diff.

Joshua Goldberg
  • 5,059
  • 2
  • 34
  • 39
2

this is what I get, check mercurial version, just in case

I'm thinking perhaps you have an extensions making fancy stuff with blobs, since I can't get what you describe. I just get Binary file doc.pdf has changed

$ hg version
Mercurial Distributed SCM (version 3.9.2)
...
$ mkdir hg-test
$ cd hg-test
$ hg init
$ echo a text line > text.txt
$ hg add text.txt
$ hg commit -m "1st"
$ echo another text line >> text.txt
$ hg commit -m "2nd"
$ hg add doc.pdf
$ hg commit -m "a binary file"
$ hg commit -m "modified the binary file"
$ hg diff --change 3
diff -r 2fd7730bc3bb -r 155aefdccfbe doc.pdf
Binary file doc.pdf has changed
$ hg diff --change 1
diff -r 9e171966ad0d -r 105aa77984c0 text.txt
--- a/text.txt  Sat Dec 17 12:18:46 2016 +0100
+++ b/text.txt  Sat Dec 17 12:19:28 2016 +0100
@@ -1,1 +1,2 @@
 a text line
+another text line
$ hg log -pr0:3
changeset:   0:9e171966ad0d
user:        arhak
date:        Sat Dec 17 12:18:46 2016 +0100
summary:     1st

diff -r 000000000000 -r 9e171966ad0d text.txt
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/text.txt  Sat Dec 17 12:18:46 2016 +0100
@@ -0,0 +1,1 @@
+a text line

changeset:   1:105aa77984c0
user:        arhak
date:        Sat Dec 17 12:19:28 2016 +0100
summary:     2nd

diff -r 9e171966ad0d -r 105aa77984c0 text.txt
--- a/text.txt  Sat Dec 17 12:18:46 2016 +0100
+++ b/text.txt  Sat Dec 17 12:19:28 2016 +0100
@@ -1,1 +1,2 @@
 a text line
+another text line

changeset:   2:2fd7730bc3bb
user:        arhak
date:        Sat Dec 17 12:27:38 2016 +0100
summary:     a binary file

diff -r 105aa77984c0 -r 2fd7730bc3bb doc.pdf
Binary file doc.pdf has changed

changeset:   3:155aefdccfbe
tag:         tip
user:        arhak
date:        Sat Dec 17 12:28:50 2016 +0100
summary:     modified the binary file

diff -r 2fd7730bc3bb -r 155aefdccfbe doc.pdf
Binary file doc.pdf has changed
arhak
  • 2,488
  • 1
  • 24
  • 38
  • Thanks! I was a point you behind in my hg version — but updating didn't help. Based on your thinking, though, I tried `mv .hgrc .hgrc.bak` and with default configurations I *do* get "Binary file... has changed". I'll try to follow up after I narrow down to the culprit. – Joshua Goldberg Dec 17 '16 at 21:44