Mercurial > public > mercurial-scm > hg-stable
diff mercurial/merge.py @ 5042:f191bc3916f7
merge: do early copy to deal with issue636
Without copies/renames, merges source names are 1:1 with their
targets. Copies and renames introduce the possibility that there will
be two merges with the same input but different output. By doing the
copy to the destination name before the merge, the actual merge
becomes 1:1 again, and no source is the input to two different merges.
- add a preliminary scan to applyupdates to do copies
- for the merge action, pass the old name (for finding ancestors) and
the new name (for input to the merge) to filemerge
- eliminate the old post-merge copy
- lookup file contents from new name in filemerge
- pass new name to external merge helper
- report merge failure at new name
- add a test
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 01 Aug 2007 12:33:12 -0500 |
parents | 60c54154ec4c |
children | bf444a9a9c23 8d9bdcbb2b18 |
line wrap: on
line diff
--- a/mercurial/merge.py Mon Jul 30 20:01:16 2007 +0200 +++ b/mercurial/merge.py Wed Aug 01 12:33:12 2007 -0500 @@ -9,10 +9,11 @@ from i18n import _ import errno, util, os, tempfile, context -def filemerge(repo, fw, fo, wctx, mctx): +def filemerge(repo, fw, fd, fo, wctx, mctx): """perform a 3-way merge in the working directory - fw = filename in the working directory + fw = original filename in the working directory + fd = destination filename in the working directory fo = filename in other parent wctx, mctx = working and merge changecontexts """ @@ -27,15 +28,16 @@ return name fcm = wctx.filectx(fw) + fcmdata = wctx.filectx(fd).data() fco = mctx.filectx(fo) - if not fco.cmp(fcm.data()): # files identical? + if not fco.cmp(fcmdata): # files identical? return None fca = fcm.ancestor(fco) if not fca: fca = repo.filectx(fw, fileid=nullrev) - a = repo.wjoin(fw) + a = repo.wjoin(fd) b = temp("base", fca) c = temp("other", fco) @@ -49,11 +51,11 @@ cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge") or "hgmerge") r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root, - environ={'HG_FILE': fw, + environ={'HG_FILE': fd, 'HG_MY_NODE': str(wctx.parents()[0]), 'HG_OTHER_NODE': str(mctx)}) if r: - repo.ui.warn(_("merging %s failed!\n") % fw) + repo.ui.warn(_("merging %s failed!\n") % fd) os.unlink(b) os.unlink(c) @@ -380,6 +382,15 @@ updated, merged, removed, unresolved = 0, 0, 0, 0 action.sort() + # prescan for copy/renames + for a in action: + f, m = a[:2] + if m == 'm': # merge + f2, fd, flags, move = a[2:] + if f != fd: + repo.ui.debug(_("copying %s to %s\n") % (f, fd)) + repo.wwrite(fd, repo.wread(f), flags) + for a in action: f, m = a[:2] if f and f[0] == "/": @@ -396,7 +407,7 @@ removed += 1 elif m == "m": # merge f2, fd, flags, move = a[2:] - r = filemerge(repo, f, f2, wctx, mctx) + r = filemerge(repo, f, fd, f2, wctx, mctx) if r > 0: unresolved += 1 else: @@ -404,12 +415,9 @@ updated += 1 else: merged += 1 - if f != fd: - repo.ui.debug(_("copying %s to %s\n") % (f, fd)) - repo.wwrite(fd, repo.wread(f), flags) - if move: - repo.ui.debug(_("removing %s\n") % f) - os.unlink(repo.wjoin(f)) + if f != fd and move: + repo.ui.debug(_("removing %s\n") % f) + os.unlink(repo.wjoin(f)) util.set_exec(repo.wjoin(fd), "x" in flags) elif m == "g": # get flags = a[2]