# HG changeset patch # User Martin von Zweigbergk # Date 1419379974 28800 # Node ID a9853fc172d2efa755bc7c7c8084dffa133fd73e # Parent bc7d90c966d20d0061daa39245700bc05f024047 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. diff -r bc7d90c966d2 -r a9853fc172d2 mercurial/patch.py --- a/mercurial/patch.py Tue Dec 23 14:56:30 2014 -0800 +++ b/mercurial/patch.py Tue Dec 23 16:12:54 2014 -0800 @@ -1796,6 +1796,12 @@ revs = None modifiedset, addedset, removedset = set(modified), set(added), set(removed) + # Fix up modified and added, since merged-in additions appear as + # modifications during merges + for f in modifiedset.copy(): + if f not in ctx1: + addedset.add(f) + modifiedset.remove(f) for f in sorted(modified + added + removed): to = None tn = None @@ -1807,7 +1813,7 @@ tn = getfilectx(f, ctx2).data() a, b = f, f if opts.git or losedatafn: - if f in addedset or (f in modifiedset and to is None): + if f in addedset: mode = gitmode[ctx2.flags(f)] if f in copy or f in copyto: if opts.git: @@ -1843,7 +1849,7 @@ if not opts.git and not tn: # regular diffs cannot represent new empty file losedatafn(f) - elif f in removedset or (f in modifiedset and tn is None): + elif f in removedset: if opts.git: # have we already reported a copy above? if ((f in copy and copy[f] in addedset diff -r bc7d90c966d2 -r a9853fc172d2 tests/test-shelve.t --- a/tests/test-shelve.t Tue Dec 23 14:56:30 2014 -0800 +++ b/tests/test-shelve.t Tue Dec 23 16:12:54 2014 -0800 @@ -238,12 +238,6 @@ diff --git a/b/b b/b.rename/b rename from b/b rename to b.rename/b - diff --git a/b/b b/b/b - deleted file mode 100644 - --- a/b/b - +++ /dev/null - @@ -1,1 +0,0 @@ - -b diff --git a/c b/c.copy copy from c copy to c.copy