Patchwork diff: fix binary file removals in git mode

login
register
mail settings
Submitter Sean Farley
Date March 22, 2013, 10:49 p.m.
Message ID <61208f15fe3d5f28de7c.1363992547@laptop.local>
Download mbox | patch
Permalink /patch/1169/
State Accepted
Headers show

Comments

Sean Farley - March 22, 2013, 10:49 p.m.
# HG changeset patch
# User Johan Bjork <jbjoerk@gmail.com>
# Date 1362436451 0
#      Mon Mar 04 22:34:11 2013 +0000
# Node ID 61208f15fe3d5f28de7c5c75858c180f033024b5
# Parent  ac0336471ba766cc3c1234473e75d4478819e50d
diff: fix binary file removals in git mode.

With the previous version, a binary file removal diff generated with
Sean Farley - March 22, 2013, 10:54 p.m.
Sent this patch on behalf of Johan (forgot to cc him with the original
patch) with some minor fix ups. Apparently, his patch triggered this
bug in patch.py:

http://markmail.org/message/b5fgo7iourvxzrag

On Fri, Mar 22, 2013 at 5:49 PM, Sean Farley
<sean.michael.farley@gmail.com> wrote:
> # HG changeset patch
> # User Johan Bjork <jbjoerk@gmail.com>
> # Date 1362436451 0
> #      Mon Mar 04 22:34:11 2013 +0000
> # Node ID 61208f15fe3d5f28de7c5c75858c180f033024b5
> # Parent  ac0336471ba766cc3c1234473e75d4478819e50d
> diff: fix binary file removals in git mode.
>
> With the previous version, a binary file removal diff generated with
> diff --git would not apply with 'git apply' with the error
> "
> error: removal patch leaves file contents
> error: <file>: patch does not apply
> "

Nitpick: For some reason the quotations look oddly positioned to me.

> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -1754,10 +1754,12 @@
>                           and copy[copyto[f]] == f)):
>                          dodiff = False
>                      else:
>                          header.append('deleted file mode %s\n' %
>                                        gitmode[man1.flags(f)])
> +                        if util.binary(to):
> +                            dodiff = 'binary'
>                  elif not to or util.binary(to):
>                      # regular diffs cannot represent empty file deletion
>                      losedatafn(f)
>              else:
>                  oflag = man1.flags(f)
> diff --git a/tests/test-diff-upgrade.t b/tests/test-diff-upgrade.t
> --- a/tests/test-diff-upgrade.t
> +++ b/tests/test-diff-upgrade.t
> @@ -198,20 +198,25 @@
>    deleted file mode 100644
>
>    % git=auto: git diff for rmbinary
>    diff --git a/rmbinary b/rmbinary
>    deleted file mode 100644
> -  Binary file rmbinary has changed
> +  index f76dd238ade08917e6712764a16a22005a50573d..0000000000000000000000000000000000000000
> +  GIT binary patch
> +  literal 0
> +  Hc$@<O00001
> +
>
>    % git=auto: git diff for bintoregular
>    diff --git a/bintoregular b/bintoregular
>    index f76dd238ade08917e6712764a16a22005a50573d..9c42f2b6427d8bf034b7bc23986152dc01bfd3ab
>    GIT binary patch
>    literal 13
>    Uc$`bh%qz(+N=+}#Ni5<5043uE82|tP
>
>
> +

Hmm, I couldn't quickly figure out why your dodiff='binary' changed
this second test (by adding a new line). Does anyone else know why?
Bryan O'Sullivan - March 26, 2013, 5:01 p.m.
On Fri, Mar 22, 2013 at 3:49 PM, Sean Farley
<sean.michael.farley@gmail.com>wrote:

> diff: fix binary file removals in git mode.
>

Applied, thanks.
Johan Björk - March 26, 2013, 8:30 p.m.
Thanks!

/Johan


On Tue, Mar 26, 2013 at 1:01 PM, Bryan O'Sullivan <bos@serpentine.com>wrote:

> On Fri, Mar 22, 2013 at 3:49 PM, Sean Farley <
> sean.michael.farley@gmail.com> wrote:
>
>> diff: fix binary file removals in git mode.
>>
>
> Applied, thanks.

Patch

diff --git would not apply with 'git apply' with the error
"
error: removal patch leaves file contents
error: <file>: patch does not apply
"

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1754,10 +1754,12 @@ 
                          and copy[copyto[f]] == f)):
                         dodiff = False
                     else:
                         header.append('deleted file mode %s\n' %
                                       gitmode[man1.flags(f)])
+                        if util.binary(to):
+                            dodiff = 'binary'
                 elif not to or util.binary(to):
                     # regular diffs cannot represent empty file deletion
                     losedatafn(f)
             else:
                 oflag = man1.flags(f)
diff --git a/tests/test-diff-upgrade.t b/tests/test-diff-upgrade.t
--- a/tests/test-diff-upgrade.t
+++ b/tests/test-diff-upgrade.t
@@ -198,20 +198,25 @@ 
   deleted file mode 100644
   
   % git=auto: git diff for rmbinary
   diff --git a/rmbinary b/rmbinary
   deleted file mode 100644
-  Binary file rmbinary has changed
+  index f76dd238ade08917e6712764a16a22005a50573d..0000000000000000000000000000000000000000
+  GIT binary patch
+  literal 0
+  Hc$@<O00001
+  
   
   % git=auto: git diff for bintoregular
   diff --git a/bintoregular b/bintoregular
   index f76dd238ade08917e6712764a16a22005a50573d..9c42f2b6427d8bf034b7bc23986152dc01bfd3ab
   GIT binary patch
   literal 13
   Uc$`bh%qz(+N=+}#Ni5<5043uE82|tP
   
 
+
 git=warn: regular diff with data loss warnings
 
   $ hg autodiff --git=warn
   diff -r a66d19b9302d binary
   Binary file binary has changed