diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -162,6 +162,7 @@ logopts = [ diffopts = [ ('a', 'text', None, _('treat all files as text')), ('g', 'git', None, _('use git extended diff format')), + ('', 'binary', None, _('generate binary diffs in git mode (default)')), ('', 'nodates', None, _('omit dates from diff headers')) ] diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -2210,7 +2210,9 @@ def difffeatureopts(ui, opts=None, untru 'ignoreblanklines') if formatchanging: buildopts['text'] = opts and opts.get('text') - buildopts['nobinary'] = get('nobinary', forceplain=False) + binary = None if opts is None else opts.get('binary') + buildopts['nobinary'] = (not binary if binary is not None + else get('nobinary', forceplain=False)) buildopts['noprefix'] = get('noprefix', forceplain=False) return mdiff.diffopts(**pycompat.strkwargs(buildopts)) diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -216,8 +216,8 @@ Show all commands + options annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude, template clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure commit: addremove, close-branch, amend, secret, edit, interactive, include, exclude, message, logfile, date, user, subrepos - diff: rev, change, text, git, nodates, noprefix, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, root, include, exclude, subrepos - export: output, switch-parent, rev, text, git, nodates + diff: rev, change, text, git, binary, nodates, noprefix, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, root, include, exclude, subrepos + export: output, switch-parent, rev, text, git, binary, nodates forget: include, exclude init: ssh, remotecmd, insecure log: follow, follow-first, date, copies, keyword, rev, removed, only-merges, user, only-branch, branch, prune, patch, git, limit, no-merges, stat, graph, style, template, include, exclude diff --git a/tests/test-diff-binary-file.t b/tests/test-diff-binary-file.t --- a/tests/test-diff-binary-file.t +++ b/tests/test-diff-binary-file.t @@ -108,4 +108,37 @@ Test text mode with extended git-style d \ No newline at end of file +\x00\x01\x02\x03 (esc) +Test binary mode with extended git-style diff format + $ hg diff --no-binary -r 0 -r 1 + diff -r fb45f71337ad -r 9ca112d1a3c1 binfile.bin + Binary file binfile.bin has changed + + $ hg diff --git --no-binary -r 0 -r 1 + diff --git a/binfile.bin b/binfile.bin + Binary file binfile.bin has changed + + $ hg diff --git --binary -r 0 -r 1 + diff --git a/binfile.bin b/binfile.bin + index eaf36c1daccfdf325514461cd1a2ffbc139b5464..ba71a782e93f3fb63a428383706065e3ec2828e9 + GIT binary patch + literal 5 + Mc${NkWMbw50018V5dZ)H + + $ hg diff --git --binary --config diff.nobinary=True -r 0 -r 1 + diff --git a/binfile.bin b/binfile.bin + index eaf36c1daccfdf325514461cd1a2ffbc139b5464..ba71a782e93f3fb63a428383706065e3ec2828e9 + GIT binary patch + literal 5 + Mc${NkWMbw50018V5dZ)H + + + $ hg diff --git --binary --text -r 0 -r 1 + diff --git a/binfile.bin b/binfile.bin + --- a/binfile.bin + +++ b/binfile.bin + @@ -1,1 +1,1 @@ + -\x00\x01\x02\x03 (esc) + \ No newline at end of file + +\x00\x01\x02\x03 (esc) + $ cd .. diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -545,6 +545,7 @@ Test command without options -c --change REV change made by revision -a --text treat all files as text -g --git use git extended diff format + --binary generate binary diffs in git mode (default) --nodates omit dates from diff headers --noprefix omit a/ and b/ prefixes from filenames -p --show-function show which function each change is in