comparison mercurial/patch.py @ 27901:29c8e35d3283

diff: don't crash when merged-in addition was removed (issue4786) During a merge, if the user removes a file that came from parent 2 and did not exist in parent 1, the file's status will be "removed". This surprises the diff code, which crashes because it expects removed files exist in parent 1. This has been broken since 377124ba6b10 (trydiff: use 'not in addedset' for symmetry with 'not in removedset', 2014-12-23). Fix by fixing up the list of removed file, similar to how we currently fix up the list of modified and added files during a merge.
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 14 Jan 2016 10:14:24 -0800
parents 27572a5cc409
children 51b6ce257e0a
comparison
equal deleted inserted replaced
27900:27572a5cc409 27901:29c8e35d3283
2256 if dst.startswith(relroot) 2256 if dst.startswith(relroot)
2257 and src.startswith(relroot))) 2257 and src.startswith(relroot)))
2258 2258
2259 modifiedset = set(modified) 2259 modifiedset = set(modified)
2260 addedset = set(added) 2260 addedset = set(added)
2261 removedset = set(removed)
2261 for f in modified: 2262 for f in modified:
2262 if f not in ctx1: 2263 if f not in ctx1:
2263 # Fix up added, since merged-in additions appear as 2264 # Fix up added, since merged-in additions appear as
2264 # modifications during merges 2265 # modifications during merges
2265 modifiedset.remove(f) 2266 modifiedset.remove(f)
2266 addedset.add(f) 2267 addedset.add(f)
2268 for f in removed:
2269 if f not in ctx1:
2270 # Merged-in additions that are then removed are reported as removed.
2271 # They are not in ctx1, so We don't want to show them in the diff.
2272 removedset.remove(f)
2267 modified = sorted(modifiedset) 2273 modified = sorted(modifiedset)
2268 added = sorted(addedset) 2274 added = sorted(addedset)
2275 removed = sorted(removedset)
2269 2276
2270 def difffn(opts, losedata): 2277 def difffn(opts, losedata):
2271 return trydiff(repo, revs, ctx1, ctx2, modified, added, removed, 2278 return trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
2272 copy, getfilectx, opts, losedata, prefix, relroot) 2279 copy, getfilectx, opts, losedata, prefix, relroot)
2273 if opts.upgrade and not opts.git: 2280 if opts.upgrade and not opts.git: