Patchwork patch: Fix nullid for binary git diffs (issue4054)

login
register
mail settings
Submitter Johan Björk
Date Oct. 7, 2013, 2:18 p.m.
Message ID <ec8b612ba53e3066f720.1381155500@phbs-MacBook-Air.local>
Download mbox | patch
Permalink /patch/2736/
State Accepted
Commit c172660eee01af28b8f843a9f7a568a4de5bb084
Headers show

Comments

Johan Björk - Oct. 7, 2013, 2:18 p.m.
# HG changeset patch
# User Johan Bjork <jbjoerk@gmail.com>
# Date 1381154275 14400
#      Mon Oct 07 09:57:55 2013 -0400
# Node ID ec8b612ba53e3066f7204e250cece1e0307ba13c
# Parent  a69a77a80900eabe1257c935818d0910217e9702
patch: Fix nullid for binary git diffs (issue4054)

The index for an empty file in git is not 0, but sha-1("blobl 0\0").
Augie Fackler - Oct. 7, 2013, 5:01 p.m.
On Mon, Oct 07, 2013 at 10:18:20AM -0400, Johan Bjork wrote:
> # HG changeset patch
> # User Johan Bjork <jbjoerk@gmail.com>
> # Date 1381154275 14400
> #      Mon Oct 07 09:57:55 2013 -0400
> # Node ID ec8b612ba53e3066f7204e250cece1e0307ba13c
> # Parent  a69a77a80900eabe1257c935818d0910217e9702
> patch: Fix nullid for binary git diffs (issue4054)

Queued for stable, thanks.

>
> The index for an empty file in git is not 0, but sha-1("blobl 0\0").
>
> diff -r a69a77a80900 -r ec8b612ba53e mercurial/patch.py
> --- a/mercurial/patch.py	Tue Oct 01 14:48:53 2013 -0400
> +++ b/mercurial/patch.py	Mon Oct 07 09:57:55 2013 -0400
> @@ -14,7 +14,7 @@
>  import email.Parser
>
>  from i18n import _
> -from node import hex, nullid, short
> +from node import hex, short
>  import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
>  import context
>
> @@ -1662,7 +1662,7 @@
>
>      def gitindex(text):
>          if not text:
> -            return hex(nullid)
> +            text = ""
>          l = len(text)
>          s = util.sha1('blob %d\0' % l)
>          s.update(text)
> diff -r a69a77a80900 -r ec8b612ba53e tests/test-diff-upgrade.t
> --- a/tests/test-diff-upgrade.t	Tue Oct 01 14:48:53 2013 -0400
> +++ b/tests/test-diff-upgrade.t	Mon Oct 07 09:57:55 2013 -0400
> @@ -183,7 +183,7 @@
>    % git=auto: git diff for newbinary
>    diff --git a/newbinary b/newbinary
>    new file mode 100644
> -  index 0000000000000000000000000000000000000000..f76dd238ade08917e6712764a16a22005a50573d
> +  index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f76dd238ade08917e6712764a16a22005a50573d
>    GIT binary patch
>    literal 1
>    Ic${MZ000310RR91
> @@ -200,7 +200,7 @@
>    % git=auto: git diff for rmbinary
>    diff --git a/rmbinary b/rmbinary
>    deleted file mode 100644
> -  index f76dd238ade08917e6712764a16a22005a50573d..0000000000000000000000000000000000000000
> +  index f76dd238ade08917e6712764a16a22005a50573d..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
>    GIT binary patch
>    literal 0
>    Hc$@<O00001
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff -r a69a77a80900 -r ec8b612ba53e mercurial/patch.py
--- a/mercurial/patch.py	Tue Oct 01 14:48:53 2013 -0400
+++ b/mercurial/patch.py	Mon Oct 07 09:57:55 2013 -0400
@@ -14,7 +14,7 @@ 
 import email.Parser
 
 from i18n import _
-from node import hex, nullid, short
+from node import hex, short
 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
 import context
 
@@ -1662,7 +1662,7 @@ 
 
     def gitindex(text):
         if not text:
-            return hex(nullid)
+            text = ""
         l = len(text)
         s = util.sha1('blob %d\0' % l)
         s.update(text)
diff -r a69a77a80900 -r ec8b612ba53e tests/test-diff-upgrade.t
--- a/tests/test-diff-upgrade.t	Tue Oct 01 14:48:53 2013 -0400
+++ b/tests/test-diff-upgrade.t	Mon Oct 07 09:57:55 2013 -0400
@@ -183,7 +183,7 @@ 
   % git=auto: git diff for newbinary
   diff --git a/newbinary b/newbinary
   new file mode 100644
-  index 0000000000000000000000000000000000000000..f76dd238ade08917e6712764a16a22005a50573d
+  index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f76dd238ade08917e6712764a16a22005a50573d
   GIT binary patch
   literal 1
   Ic${MZ000310RR91
@@ -200,7 +200,7 @@ 
   % git=auto: git diff for rmbinary
   diff --git a/rmbinary b/rmbinary
   deleted file mode 100644
-  index f76dd238ade08917e6712764a16a22005a50573d..0000000000000000000000000000000000000000
+  index f76dd238ade08917e6712764a16a22005a50573d..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
   GIT binary patch
   literal 0
   Hc$@<O00001