Patchwork [2,of,3] trydiff: check only if added file is a copy target, not source

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 2, 2015, 6:10 a.m.
Message ID <42117e61f40155ee5067.1422857419@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7587/
State Accepted
Commit 0188c2d90356e8b524f8a7392ecdf92658b38058
Headers show

Comments

Martin von Zweigbergk - Feb. 2, 2015, 6:10 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1421456518 28800
#      Fri Jan 16 17:01:58 2015 -0800
# Branch stable
# Node ID 42117e61f40155ee5067b50a24c6e2e7f1b90754
# Parent  e6401a11a73d8bd5b9de972959d37eddc719a6dc
trydiff: check only if added file is a copy target, not source

When creating a diff with copy/rename enabled, we consider added files
and check if they are either copy sources or targets. However, an
added file should never be a copy source. The test suite seems to
agree with this: all tests pass if we raise an exception when an added
file is a copy source. So, let's simplify the code by dropping the
conditions that are never true.

For those interested in the historical reasons:

Before commit d1f209bb9564 (patch: separate reverse copy data
(issue1959), 2010-02-11), 'copy' seems to have been a bidirectional
map. Then that commit split it up into two unidirectional maps and
duplicated the logic to look in both maps. It was still needed at that
point to look in both maps, as the copy detection was poor and could
sometimes be reported in reverse.

A little later came 91eb4512edd0 (copies: rewrite copy detection for
non-merge users, 2012-01-04). That commit fixed the copy detection to
be backwards when it should, and made the hacks in trydiff
unnecessary.

Patch

diff -r e6401a11a73d -r 42117e61f401 mercurial/patch.py
--- a/mercurial/patch.py	Thu Jan 29 21:12:35 2015 -0800
+++ b/mercurial/patch.py	Fri Jan 16 17:01:58 2015 -0800
@@ -1807,12 +1807,9 @@ 
         if opts.git or losedatafn:
             if f in addedset:
                 mode = gitmode[ctx2.flags(f)]
-                if f in copy or f in copyto:
+                if f in copy:
                     if opts.git:
-                        if f in copy:
-                            a = copy[f]
-                        else:
-                            a = copyto[f]
+                        a = copy[f]
                         omode = gitmode[ctx1.flags(a)]
                         addmodehdr(header, omode, mode)
                         if a in removedset and a not in gone:
@@ -1841,10 +1838,8 @@ 
             elif f in removedset:
                 if opts.git:
                     # have we already reported a copy above?
-                    if ((f in copy and copy[f] in addedset
-                         and copyto[copy[f]] == f) or
-                        (f in copyto and copyto[f] in addedset
-                         and copy[copyto[f]] == f)):
+                    if (f in copyto and copyto[f] in addedset
+                        and copy[copyto[f]] == f):
                         continue
                     else:
                         header.append('deleted file mode %s\n' %