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

login
register
mail settings
Submitter Johan Björk
Date Oct. 27, 2013, 2:13 p.m.
Message ID <a3a69719934fb487534b.1382883229@phbs-MacBook-Air.local>
Download mbox | patch
Permalink /patch/2826/
State Accepted
Headers show

Comments

Johan Björk - Oct. 27, 2013, 2:13 p.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 a3a69719934fb487534bc21cccbfedca61aa3a7e
# Parent  1d7a36ff2615e6e12ce65681db4e07622e7b60d1
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.
Johan Björk - Oct. 27, 2013, 2:17 p.m.
This version finally fixes the failing tests, sorry about the confusion
about the previous test-failures, I must have missed them the second time
around due to other tests failing for me on OSX (due to "+  abort: cannot
start server at ':$HGPORT': Address already in use) any ideas?


On Sun, Oct 27, 2013 at 10:13 AM, Johan Bjork <jbjoerk@gmail.com> 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 a3a69719934fb487534bc21cccbfedca61aa3a7e
> # Parent  1d7a36ff2615e6e12ce65681db4e07622e7b60d1
> 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.
>
> diff -r 1d7a36ff2615 -r a3a69719934f mercurial/patch.py
> --- a/mercurial/patch.py        Wed Oct 23 13:12:48 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 to is None):
>                  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 tn is None):
>                  if opts.git:
>                      # have we already reported a copy above?
>                      if ((f in copy and copy[f] in added
> diff -r 1d7a36ff2615 -r a3a69719934f tests/test-git-export.t
> --- a/tests/test-git-export.t   Wed Oct 23 13:12:48 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
> diff -r 1d7a36ff2615 -r a3a69719934f tests/test-shelve.t
> --- a/tests/test-shelve.t       Wed Oct 23 13:12:48 2013 -0700
> +++ b/tests/test-shelve.t       Sun Oct 13 08:38:30 2013 -0400
> @@ -228,6 +228,7 @@
>    +a
>    +>>>>>>> other
>    diff --git a/b.rename/b b/b.rename/b
> +  new file mode 100644
>    --- /dev/null
>    +++ b/b.rename/b
>    @@ -0,0 +1,1 @@
> @@ -239,6 +240,7 @@
>    @@ -1,1 +0,0 @@
>    -b
>    diff --git a/c.copy b/c.copy
> +  new file mode 100644
>    --- /dev/null
>    +++ b/c.copy
>    @@ -0,0 +1,1 @@
>
Matt Mackall - Nov. 1, 2013, 9:53 p.m.
On Sun, 2013-10-27 at 10:13 -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 a3a69719934fb487534bc21cccbfedca61aa3a7e
> # Parent  1d7a36ff2615e6e12ce65681db4e07622e7b60d1
> patch: Always ensure valid git diffs in case source/destination file is missing (issue4046)

Queued for stable, thanks.

Patch

diff -r 1d7a36ff2615 -r a3a69719934f mercurial/patch.py
--- a/mercurial/patch.py	Wed Oct 23 13:12:48 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 to is None):
                 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 tn is None):
                 if opts.git:
                     # have we already reported a copy above?
                     if ((f in copy and copy[f] in added
diff -r 1d7a36ff2615 -r a3a69719934f tests/test-git-export.t
--- a/tests/test-git-export.t	Wed Oct 23 13:12:48 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
diff -r 1d7a36ff2615 -r a3a69719934f tests/test-shelve.t
--- a/tests/test-shelve.t	Wed Oct 23 13:12:48 2013 -0700
+++ b/tests/test-shelve.t	Sun Oct 13 08:38:30 2013 -0400
@@ -228,6 +228,7 @@ 
   +a
   +>>>>>>> other
   diff --git a/b.rename/b b/b.rename/b
+  new file mode 100644
   --- /dev/null
   +++ b/b.rename/b
   @@ -0,0 +1,1 @@
@@ -239,6 +240,7 @@ 
   @@ -1,1 +0,0 @@
   -b
   diff --git a/c.copy b/c.copy
+  new file mode 100644
   --- /dev/null
   +++ b/c.copy
   @@ -0,0 +1,1 @@