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

login
register
mail settings
Submitter Johan Björk
Date Oct. 13, 2013, 12:50 p.m.
Message ID <9b5bc4626c30f9b85642.1381668659@new-host-2.home>
Download mbox | patch
Permalink /patch/2755/
State Superseded, archived
Headers show

Comments

Johan Björk - Oct. 13, 2013, 12:50 p.m.
# HG changeset patch
# User Johan Bjork <jbjoerk@gmail.com>
# Date 1381667910 14400
#      Sun Oct 13 08:38:30 2013 -0400
# Node ID 9b5bc4626c30f9b8564238824618376f08992d3c
# Parent  1b2f9d36953e6ed384a044c1e73cb3a1aa072004
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. 19, 2013, 11:34 p.m.
On Sun, 2013-10-13 at 08:50 -0400, Johan Bjork wrote:
> # HG changeset patch
> # User Johan Bjork <jbjoerk@gmail.com>
> # Date 1381667910 14400
> #      Sun Oct 13 08:38:30 2013 -0400
> # Node ID 9b5bc4626c30f9b8564238824618376f08992d3c
> # Parent  1b2f9d36953e6ed384a044c1e73cb3a1aa072004
> patch: Always ensure valid git diffs in case source/destination file is missing (issue4046)

This looks promising, but

- it breaks several tests in our test suite, which will need diagnosing
- it's probably going to need a testcase of its own

As this is a bug fix, you might be able to get it into 2.8 if you
address the above in the next week or so.

Patch

diff -r 1b2f9d36953e -r 9b5bc4626c30 mercurial/patch.py
--- a/mercurial/patch.py	Mon Sep 30 18:27:42 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 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 not tn:
                 if opts.git:
                     # have we already reported a copy above?
                     if ((f in copy and copy[f] in added