comparison mercurial/patch.py @ 23996:0188c2d90356

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.
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 16 Jan 2015 17:01:58 -0800
parents d8330fb8c44d
children 8b88870cbd1e
comparison
equal deleted inserted replaced
23995:d8330fb8c44d 23996:0188c2d90356
1805 tn = getfilectx(f, ctx2).data() 1805 tn = getfilectx(f, ctx2).data()
1806 a, b = f, f 1806 a, b = f, f
1807 if opts.git or losedatafn: 1807 if opts.git or losedatafn:
1808 if f in addedset: 1808 if f in addedset:
1809 mode = gitmode[ctx2.flags(f)] 1809 mode = gitmode[ctx2.flags(f)]
1810 if f in copy or f in copyto: 1810 if f in copy:
1811 if opts.git: 1811 if opts.git:
1812 if f in copy: 1812 a = copy[f]
1813 a = copy[f]
1814 else:
1815 a = copyto[f]
1816 omode = gitmode[ctx1.flags(a)] 1813 omode = gitmode[ctx1.flags(a)]
1817 addmodehdr(header, omode, mode) 1814 addmodehdr(header, omode, mode)
1818 if a in removedset and a not in gone: 1815 if a in removedset and a not in gone:
1819 op = 'rename' 1816 op = 'rename'
1820 gone.add(a) 1817 gone.add(a)
1839 # regular diffs cannot represent new empty file 1836 # regular diffs cannot represent new empty file
1840 losedatafn(f) 1837 losedatafn(f)
1841 elif f in removedset: 1838 elif f in removedset:
1842 if opts.git: 1839 if opts.git:
1843 # have we already reported a copy above? 1840 # have we already reported a copy above?
1844 if ((f in copy and copy[f] in addedset 1841 if (f in copyto and copyto[f] in addedset
1845 and copyto[copy[f]] == f) or 1842 and copy[copyto[f]] == f):
1846 (f in copyto and copyto[f] in addedset
1847 and copy[copyto[f]] == f)):
1848 continue 1843 continue
1849 else: 1844 else:
1850 header.append('deleted file mode %s\n' % 1845 header.append('deleted file mode %s\n' %
1851 gitmode[ctx1.flags(f)]) 1846 gitmode[ctx1.flags(f)])
1852 if util.binary(to): 1847 if util.binary(to):