changeset 12577:05210e955bef

Merge with stable
author Patrick Mezard <pmezard@gmail.com>
date Tue, 28 Sep 2010 01:11:24 +0200
parents be4b0a397470 (current diff) 1c9bb7e00f71 (diff)
children fdb0983ad395
files mercurial/patch.py tests/test-diff-upgrade.t tests/test-git-import.t
diffstat 3 files changed, 79 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Mon Sep 27 22:49:30 2010 +0200
+++ b/mercurial/patch.py	Tue Sep 28 01:11:24 2010 +0200
@@ -1184,7 +1184,9 @@
                 gp.path = pathstrip(gp.path, strip - 1)[1]
                 if gp.oldpath:
                     gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1]
-                if gp.op in ('COPY', 'RENAME'):
+                # Binary patches really overwrite target files, copying them
+                # will just make it fails with "target file exists"
+                if gp.op in ('COPY', 'RENAME') and not gp.binary:
                     copyfn(gp.oldpath, gp.path, cwd)
                 changed[gp.path] = gp
         else:
@@ -1530,6 +1532,9 @@
                         header.append('new file mode %s\n' % mode)
                     elif ctx2.flags(f):
                         losedatafn(f)
+                # In theory, if tn was copied or renamed we should check
+                # if the source is binary too but the copy record already
+                # forces git mode.
                 if util.binary(tn):
                     if opts.git:
                         dodiff = 'binary'
@@ -1549,7 +1554,7 @@
                     else:
                         header.append('deleted file mode %s\n' %
                                       gitmode[man1.flags(f)])
-                elif not to:
+                elif not to or util.binary(to):
                     # regular diffs cannot represent empty file deletion
                     losedatafn(f)
             else:
--- a/tests/test-diff-upgrade.t	Mon Sep 27 22:49:30 2010 +0200
+++ b/tests/test-diff-upgrade.t	Tue Sep 28 01:11:24 2010 +0200
@@ -7,10 +7,13 @@
   $ hg init repo
   $ cd repo
 
+
+
 make a combination of new, changed and deleted file
 
   $ echo regular > regular
   $ echo rmregular > rmregular
+  $ python -c "file('bintoregular', 'wb').write('\0')"
   $ touch rmempty
   $ echo exec > exec
   $ chmod +x exec
@@ -23,6 +26,7 @@
   $ python -c "file('rmbinary', 'wb').write('\0')"
   $ hg ci -Am addfiles
   adding binary
+  adding bintoregular
   adding exec
   adding regular
   adding rmbinary
@@ -38,6 +42,7 @@
   $ rm rmregular
   $ echo exec >> exec
   $ echo newexec > newexec
+  $ echo bintoregular > bintoregular
   $ chmod +x newexec
   $ rm rmexec
   $ chmod +x setexec
@@ -58,40 +63,42 @@
 git=no: regular diff for all files
 
   $ hg autodiff --git=no
-  diff -r b3f053cd7c7f binary
+  diff -r a66d19b9302d binary
   Binary file binary has changed
-  diff -r b3f053cd7c7f exec
+  diff -r a66d19b9302d bintoregular
+  Binary file bintoregular has changed
+  diff -r a66d19b9302d exec
   --- a/exec
   +++ b/exec
   @@ -1,1 +1,2 @@
    exec
   +exec
-  diff -r b3f053cd7c7f newbinary
+  diff -r a66d19b9302d newbinary
   Binary file newbinary has changed
-  diff -r b3f053cd7c7f newexec
+  diff -r a66d19b9302d newexec
   --- /dev/null
   +++ b/newexec
   @@ -0,0 +1,1 @@
   +newexec
-  diff -r b3f053cd7c7f newregular
+  diff -r a66d19b9302d newregular
   --- /dev/null
   +++ b/newregular
   @@ -0,0 +1,1 @@
   +newregular
-  diff -r b3f053cd7c7f regular
+  diff -r a66d19b9302d regular
   --- a/regular
   +++ b/regular
   @@ -1,1 +1,2 @@
    regular
   +regular
-  diff -r b3f053cd7c7f rmbinary
+  diff -r a66d19b9302d rmbinary
   Binary file rmbinary has changed
-  diff -r b3f053cd7c7f rmexec
+  diff -r a66d19b9302d rmexec
   --- a/rmexec
   +++ /dev/null
   @@ -1,1 +0,0 @@
   -rmexec
-  diff -r b3f053cd7c7f rmregular
+  diff -r a66d19b9302d rmregular
   --- a/rmregular
   +++ /dev/null
   @@ -1,1 +0,0 @@
@@ -107,41 +114,39 @@
    regular
   +regular
 
-git=auto: regular diff for regular files and removals
+git=auto: regular diff for regular files and non-binary removals
 
-  $ hg autodiff --git=auto regular newregular rmregular rmbinary rmexec
-  diff -r b3f053cd7c7f newregular
+  $ hg autodiff --git=auto regular newregular rmregular rmexec
+  diff -r a66d19b9302d newregular
   --- /dev/null
   +++ b/newregular
   @@ -0,0 +1,1 @@
   +newregular
-  diff -r b3f053cd7c7f regular
+  diff -r a66d19b9302d regular
   --- a/regular
   +++ b/regular
   @@ -1,1 +1,2 @@
    regular
   +regular
-  diff -r b3f053cd7c7f rmbinary
-  Binary file rmbinary has changed
-  diff -r b3f053cd7c7f rmexec
+  diff -r a66d19b9302d rmexec
   --- a/rmexec
   +++ /dev/null
   @@ -1,1 +0,0 @@
   -rmexec
-  diff -r b3f053cd7c7f rmregular
+  diff -r a66d19b9302d rmregular
   --- a/rmregular
   +++ /dev/null
   @@ -1,1 +0,0 @@
   -rmregular
 
-  $ for f in exec newexec setexec unsetexec binary newbinary newempty rmempty; do
+  $ for f in exec newexec setexec unsetexec binary newbinary newempty rmempty rmbinary bintoregular; do
   >     echo
   >     echo '% git=auto: git diff for' $f
   >     hg autodiff --git=auto $f
   > done
   
   % git=auto: git diff for exec
-  diff -r b3f053cd7c7f exec
+  diff -r a66d19b9302d exec
   --- a/exec
   +++ b/exec
   @@ -1,1 +1,2 @@
@@ -190,52 +195,69 @@
   % git=auto: git diff for rmempty
   diff --git a/rmempty b/rmempty
   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
+  
+  % 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 b3f053cd7c7f binary
+  diff -r a66d19b9302d binary
   Binary file binary has changed
-  diff -r b3f053cd7c7f exec
+  diff -r a66d19b9302d bintoregular
+  Binary file bintoregular has changed
+  diff -r a66d19b9302d exec
   --- a/exec
   +++ b/exec
   @@ -1,1 +1,2 @@
    exec
   +exec
-  diff -r b3f053cd7c7f newbinary
+  diff -r a66d19b9302d newbinary
   Binary file newbinary has changed
-  diff -r b3f053cd7c7f newexec
+  diff -r a66d19b9302d newexec
   --- /dev/null
   +++ b/newexec
   @@ -0,0 +1,1 @@
   +newexec
-  diff -r b3f053cd7c7f newregular
+  diff -r a66d19b9302d newregular
   --- /dev/null
   +++ b/newregular
   @@ -0,0 +1,1 @@
   +newregular
-  diff -r b3f053cd7c7f regular
+  diff -r a66d19b9302d regular
   --- a/regular
   +++ b/regular
   @@ -1,1 +1,2 @@
    regular
   +regular
-  diff -r b3f053cd7c7f rmbinary
+  diff -r a66d19b9302d rmbinary
   Binary file rmbinary has changed
-  diff -r b3f053cd7c7f rmexec
+  diff -r a66d19b9302d rmexec
   --- a/rmexec
   +++ /dev/null
   @@ -1,1 +0,0 @@
   -rmexec
-  diff -r b3f053cd7c7f rmregular
+  diff -r a66d19b9302d rmregular
   --- a/rmregular
   +++ /dev/null
   @@ -1,1 +0,0 @@
   -rmregular
   data lost for: binary
+  data lost for: bintoregular
   data lost for: newbinary
   data lost for: newempty
   data lost for: newexec
+  data lost for: rmbinary
   data lost for: rmempty
   data lost for: setexec
   data lost for: unsetexec
@@ -249,7 +271,7 @@
 git=abort: succeed on regular file
 
   $ hg autodiff --git=abort regular
-  diff -r b3f053cd7c7f regular
+  diff -r a66d19b9302d regular
   --- a/regular
   +++ b/regular
   @@ -1,1 +1,2 @@
--- a/tests/test-git-import.t	Mon Sep 27 22:49:30 2010 +0200
+++ b/tests/test-git-import.t	Tue Sep 28 01:11:24 2010 +0200
@@ -335,3 +335,24 @@
   $ cat foo3
   foo
 
+Move text file and patch as binary
+
+  $ echo a > text2
+  $ hg ci -Am0
+  adding text2
+  $ hg import -d "1000000 0" -m rename-as-binary - <<"EOF"
+  > diff --git a/text2 b/binary2
+  > rename from text2
+  > rename to binary2
+  > index 78981922613b2afb6025042ff6bd878ac1994e85..10efcb362e9f3b3420fcfbfc0e37f3dc16e29757
+  > GIT binary patch
+  > literal 5
+  > Mc$`b*O5$Pw00T?_*Z=?k
+  > 
+  > EOF
+  applying patch from stdin
+  $ python $TESTDIR/printrepr.py < binary2
+  a
+  b
+  \x00
+  $ hg st --copies --change .  abort: unknown revision '.echo'!