# HG changeset patch # User Matt Mackall # Date 1159808688 18000 # Node ID 3fd098e0902d7efe5ec738f7ebfa55a57ca1e7d1 # Parent 7240f9e47144bfa5f844ddd7dd6aee7d72c72cb6 merge: extend file merge function for renames diff --git a/mercurial/merge.py b/mercurial/merge.py --- a/mercurial/merge.py +++ b/mercurial/merge.py @@ -10,43 +10,59 @@ from i18n import gettext as _ from demandload import * demandload(globals(), "errno util os tempfile") -def merge3(repo, fn, my, other, p1, p2): - """perform a 3-way merge in the working directory""" +def filemerge(repo, fw, fo, fd, my, other, p1, p2, move): + """perform a 3-way merge in the working directory - def temp(prefix, node): - pre = "%s~%s." % (os.path.basename(fn), prefix) + fw = filename in the working directory and first parent + fo = filename in other parent + fd = destination filename + my = fileid in first parent + other = fileid in second parent + p1, p2 = hex changeset ids for merge command + move = whether to move or copy the file to the destination + + TODO: + if fw is copied in the working directory, we get confused + implement move and fd + """ + + def temp(prefix, ctx): + pre = "%s~%s." % (os.path.basename(ctx.path()), prefix) (fd, name) = tempfile.mkstemp(prefix=pre) f = os.fdopen(fd, "wb") - repo.wwrite(fn, fl.read(node), f) + repo.wwrite(ctx.path(), ctx.data(), f) f.close() return name - fl = repo.file(fn) - base = fl.ancestor(my, other) - a = repo.wjoin(fn) - b = temp("base", base) - c = temp("other", other) + fcm = repo.filectx(fw, fileid=my) + fco = repo.filectx(fo, fileid=other) + fca = fcm.ancestor(fco) + if not fca: + fca = repo.filectx(fw, fileid=-1) + a = repo.wjoin(fw) + b = temp("base", fca) + c = temp("other", fco) - repo.ui.note(_("resolving %s\n") % fn) - repo.ui.debug(_("file %s: my %s other %s ancestor %s\n") % - (fn, short(my), short(other), short(base))) + repo.ui.note(_("resolving %s\n") % fw) + repo.ui.debug(_("my %s other %s ancestor %s\n") % (fcm, fco, fca)) 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': fn, + environ={'HG_FILE': fw, 'HG_MY_NODE': p1, - 'HG_OTHER_NODE': p2, - 'HG_FILE_MY_NODE': hex(my), - 'HG_FILE_OTHER_NODE': hex(other), - 'HG_FILE_BASE_NODE': hex(base)}) + 'HG_OTHER_NODE': p2}) if r: - repo.ui.warn(_("merging %s failed!\n") % fn) + repo.ui.warn(_("merging %s failed!\n") % fw) os.unlink(b) os.unlink(c) return r +def merge3(repo, fn, my, other, p1, p2): + """perform a 3-way merge in the working directory""" + return filemerge(repo, fn, fn, fn, my, other, p1, p2, False) + def checkunknown(repo, m2, status): """ check for collisions between unknown files and files in m2 diff --git a/tests/test-merge7.out b/tests/test-merge7.out --- a/tests/test-merge7.out +++ b/tests/test-merge7.out @@ -27,7 +27,7 @@ resolving manifests test.txt: versions differ -> m merging test.txt resolving test.txt -file test.txt: my fc3148072371 other d40249267ae3 ancestor 8fe46a3eb557 +my test.txt@451c744aabcc other test.txt@a070d41e8360 ancestor test.txt@faaea63e63a9 merging test.txt failed! 0 files updated, 0 files merged, 0 files removed, 1 files unresolved There are unresolved merges, you can redo the full merge using: diff --git a/tests/test-up-local-change.out b/tests/test-up-local-change.out --- a/tests/test-up-local-change.out +++ b/tests/test-up-local-change.out @@ -21,7 +21,7 @@ resolving manifests b: remote created -> g merging a resolving a -file a: my b789fdd96dc2 other d730145abbf9 ancestor b789fdd96dc2 +my a@33aaa84a386b other a@802f095af299 ancestor a@33aaa84a386b getting b 1 files updated, 1 files merged, 0 files removed, 0 files unresolved changeset: 1:802f095af299 @@ -55,7 +55,7 @@ resolving manifests b: remote created -> g merging a resolving a -file a: my b789fdd96dc2 other d730145abbf9 ancestor b789fdd96dc2 +my a@33aaa84a386b other a@802f095af299 ancestor a@33aaa84a386b getting b 1 files updated, 1 files merged, 0 files removed, 0 files unresolved changeset: 1:802f095af299 @@ -106,10 +106,10 @@ resolving manifests b: versions differ -> m merging a resolving a -file a: my d730145abbf9 other 13e0d5f949fa ancestor b789fdd96dc2 +my a@802f095af299 other a@030602aee63d ancestor a@33aaa84a386b merging b resolving b -file b: my 1e88685f5dde other 61de8c7723ca ancestor 000000000000 +my b@802f095af299 other b@030602aee63d ancestor b@000000000000 0 files updated, 2 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) changeset: 1:802f095af299