Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 23663:a9853fc172d2
trydiff: simplify checking for additions
In the body of the loop in trydiff(), there are conditions like:
addedset or (f in modifiedset and to is None)
The second half of that expression is to account for the fact that
merge-in additions appear as additions. By instead fixing up the sets
of modified and added files to compensate for this fact, we can
simplify the body of the loop. It also fixes one case where the
addedset was checked without the additional check (the "have we
already reported a copy above?" case in the code, also see fixed test
case).
The similar condition with 'removedset' in it seems to have served no
purpose even before this change, so it could have been simplified even
before.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 23 Dec 2014 16:12:54 -0800 |
parents | bc7d90c966d2 |
children | 377124ba6b10 |
comparison
equal
deleted
inserted
replaced
23662:bc7d90c966d2 | 23663:a9853fc172d2 |
---|---|
1794 | 1794 |
1795 if opts.git: | 1795 if opts.git: |
1796 revs = None | 1796 revs = None |
1797 | 1797 |
1798 modifiedset, addedset, removedset = set(modified), set(added), set(removed) | 1798 modifiedset, addedset, removedset = set(modified), set(added), set(removed) |
1799 # Fix up modified and added, since merged-in additions appear as | |
1800 # modifications during merges | |
1801 for f in modifiedset.copy(): | |
1802 if f not in ctx1: | |
1803 addedset.add(f) | |
1804 modifiedset.remove(f) | |
1799 for f in sorted(modified + added + removed): | 1805 for f in sorted(modified + added + removed): |
1800 to = None | 1806 to = None |
1801 tn = None | 1807 tn = None |
1802 dodiff = True | 1808 dodiff = True |
1803 header = [] | 1809 header = [] |
1805 to = getfilectx(f, ctx1).data() | 1811 to = getfilectx(f, ctx1).data() |
1806 if f not in removedset: | 1812 if f not in removedset: |
1807 tn = getfilectx(f, ctx2).data() | 1813 tn = getfilectx(f, ctx2).data() |
1808 a, b = f, f | 1814 a, b = f, f |
1809 if opts.git or losedatafn: | 1815 if opts.git or losedatafn: |
1810 if f in addedset or (f in modifiedset and to is None): | 1816 if f in addedset: |
1811 mode = gitmode[ctx2.flags(f)] | 1817 mode = gitmode[ctx2.flags(f)] |
1812 if f in copy or f in copyto: | 1818 if f in copy or f in copyto: |
1813 if opts.git: | 1819 if opts.git: |
1814 if f in copy: | 1820 if f in copy: |
1815 a = copy[f] | 1821 a = copy[f] |
1841 else: | 1847 else: |
1842 losedatafn(f) | 1848 losedatafn(f) |
1843 if not opts.git and not tn: | 1849 if not opts.git and not tn: |
1844 # regular diffs cannot represent new empty file | 1850 # regular diffs cannot represent new empty file |
1845 losedatafn(f) | 1851 losedatafn(f) |
1846 elif f in removedset or (f in modifiedset and tn is None): | 1852 elif f in removedset: |
1847 if opts.git: | 1853 if opts.git: |
1848 # have we already reported a copy above? | 1854 # have we already reported a copy above? |
1849 if ((f in copy and copy[f] in addedset | 1855 if ((f in copy and copy[f] in addedset |
1850 and copyto[copy[f]] == f) or | 1856 and copyto[copy[f]] == f) or |
1851 (f in copyto and copyto[f] in addedset | 1857 (f in copyto and copyto[f] in addedset |