# HG changeset patch # User Martin von Zweigbergk # Date 2014-12-24 00:12:54 # 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 --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1796,6 +1796,12 @@ def trydiff(repo, revs, ctx1, ctx2, modi 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 @@ def trydiff(repo, revs, ctx1, ctx2, modi 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 @@ def trydiff(repo, revs, ctx1, ctx2, modi 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 --git a/tests/test-shelve.t b/tests/test-shelve.t --- a/tests/test-shelve.t +++ b/tests/test-shelve.t @@ -238,12 +238,6 @@ ensure that we have a merge with unresol 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