Patchwork [STABLE,V2] patch: Always ensure valid git diffs in case source/destination file is missing (issue4046)

login
register
mail settings
Submitter Johan Björk
Date Oct. 22, 2013, 12:17 a.m.
Message ID <183ddc93dc21411c85b2.1382401021@phbs-MacBook-Air.local>
Download mbox | patch
Permalink /patch/2800/
State Superseded, archived
Headers show

Comments

Johan Björk - Oct. 22, 2013, 12:17 a.m.
# HG changeset patch
# User Johan Bjork <jbjoerk@gmail.com>
# Date 1381667910 14400
#      Sun Oct 13 08:38:30 2013 -0400
# Branch stable
# Node ID 183ddc93dc21411c85b262415efb6fc3de728fa5
# Parent  2c886dedd9021598b6290d95ea0f068731ea4e2b
patch: Always ensure valid git diffs in case source/destination file is missing (issue4046)

This is arguably a workaround, a better fix may be in the repo to ensure that it won't list a file 'modified' unless
there is a file context for the previous version.
Matt Mackall - Oct. 25, 2013, 8:33 p.m.
On Mon, 2013-10-21 at 20:17 -0400, Johan Bjork wrote:
> # HG changeset patch
> # User Johan Bjork <jbjoerk@gmail.com>
> # Date 1381667910 14400
> #      Sun Oct 13 08:38:30 2013 -0400
> # Branch stable
> # Node ID 183ddc93dc21411c85b262415efb6fc3de728fa5
> # Parent  2c886dedd9021598b6290d95ea0f068731ea4e2b
> patch: Always ensure valid git diffs in case source/destination file is missing (issue4046)

As mentioned last time around, this breaks tests. In particular, it
breaks these:

Failed test-import.t: output changed
Failed test-shelve.t: output changed

These changes might be correct, but it's your job to figure out what the
test breakage means and update the tests.

Patch

diff -r 2c886dedd902 -r 183ddc93dc21 mercurial/patch.py
--- a/mercurial/patch.py	Mon Oct 21 10:50:58 2013 -0700
+++ b/mercurial/patch.py	Sun Oct 13 08:38:30 2013 -0400
@@ -1703,7 +1703,7 @@ 
             tn = getfilectx(f, ctx2).data()
         a, b = f, f
         if opts.git or losedatafn:
-            if f in added:
+            if f in added or (f in modified and not to):
                 mode = gitmode[ctx2.flags(f)]
                 if f in copy or f in copyto:
                     if opts.git:
@@ -1739,7 +1739,7 @@ 
                 if not opts.git and not tn:
                     # regular diffs cannot represent new empty file
                     losedatafn(f)
-            elif f in removed:
+            elif f in removed or (f in modified and not tn):
                 if opts.git:
                     # have we already reported a copy above?
                     if ((f in copy and copy[f] in added
diff -r 2c886dedd902 -r 183ddc93dc21 tests/test-git-export.t
--- a/tests/test-git-export.t	Mon Oct 21 10:50:58 2013 -0700
+++ b/tests/test-git-export.t	Sun Oct 13 08:38:30 2013 -0400
@@ -360,3 +360,23 @@ 
   +foo
   $ hg ci -m 'add filename with spaces'
 
+Additions should be properly marked even in the middle of a merge
+
+  $ hg up -r -2
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo "New File" >> inmerge
+  $ hg add inmerge
+  $ hg ci -m "file in merge"
+  created new head
+  $ hg up 23
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg merge
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg diff -g
+  diff --git a/inmerge b/inmerge
+  new file mode 100644
+  --- /dev/null
+  +++ b/inmerge
+  @@ -0,0 +1,1 @@
+  +New File