From patchwork Wed Apr 5 22:51:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,3,v2] hg: add --binary option for git mode diffs From: Alexander Fomin X-Patchwork-Id: 19974 Message-Id: <900f393807023064cb48.1491432708@devvm2125.lla2.facebook.com> To: Date: Wed, 5 Apr 2017 15:51:48 -0700 # HG changeset patch # User Alexander Fomin # Date 1491431468 25200 # Wed Apr 05 15:31:08 2017 -0700 # Node ID 900f393807023064cb484e86e3ccffa6338b55bb # Parent bb06942306b27dfbbe554c307f82a5c6b08e0cae hg: add --binary option for git mode diffs This patch adds --binary option to `hg diff` and `hg export` to allow more control about when binary diffs are displayed in Git mode as well as some tests to verify it behaves correctly (issue5510). diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -160,6 +160,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(**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) - $ cd .. +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 @@ -543,6 +543,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