##// END OF EJS Templates
merge: extend file merge function for renames
Matt Mackall -
r3211:3fd098e0 default
parent child Browse files
Show More
@@ -10,43 +10,59 from i18n import gettext as _
10 10 from demandload import *
11 11 demandload(globals(), "errno util os tempfile")
12 12
13 def merge3(repo, fn, my, other, p1, p2):
14 """perform a 3-way merge in the working directory"""
13 def filemerge(repo, fw, fo, fd, my, other, p1, p2, move):
14 """perform a 3-way merge in the working directory
15 15
16 def temp(prefix, node):
17 pre = "%s~%s." % (os.path.basename(fn), prefix)
16 fw = filename in the working directory and first parent
17 fo = filename in other parent
18 fd = destination filename
19 my = fileid in first parent
20 other = fileid in second parent
21 p1, p2 = hex changeset ids for merge command
22 move = whether to move or copy the file to the destination
23
24 TODO:
25 if fw is copied in the working directory, we get confused
26 implement move and fd
27 """
28
29 def temp(prefix, ctx):
30 pre = "%s~%s." % (os.path.basename(ctx.path()), prefix)
18 31 (fd, name) = tempfile.mkstemp(prefix=pre)
19 32 f = os.fdopen(fd, "wb")
20 repo.wwrite(fn, fl.read(node), f)
33 repo.wwrite(ctx.path(), ctx.data(), f)
21 34 f.close()
22 35 return name
23 36
24 fl = repo.file(fn)
25 base = fl.ancestor(my, other)
26 a = repo.wjoin(fn)
27 b = temp("base", base)
28 c = temp("other", other)
37 fcm = repo.filectx(fw, fileid=my)
38 fco = repo.filectx(fo, fileid=other)
39 fca = fcm.ancestor(fco)
40 if not fca:
41 fca = repo.filectx(fw, fileid=-1)
42 a = repo.wjoin(fw)
43 b = temp("base", fca)
44 c = temp("other", fco)
29 45
30 repo.ui.note(_("resolving %s\n") % fn)
31 repo.ui.debug(_("file %s: my %s other %s ancestor %s\n") %
32 (fn, short(my), short(other), short(base)))
46 repo.ui.note(_("resolving %s\n") % fw)
47 repo.ui.debug(_("my %s other %s ancestor %s\n") % (fcm, fco, fca))
33 48
34 49 cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge")
35 50 or "hgmerge")
36 51 r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root,
37 environ={'HG_FILE': fn,
52 environ={'HG_FILE': fw,
38 53 'HG_MY_NODE': p1,
39 'HG_OTHER_NODE': p2,
40 'HG_FILE_MY_NODE': hex(my),
41 'HG_FILE_OTHER_NODE': hex(other),
42 'HG_FILE_BASE_NODE': hex(base)})
54 'HG_OTHER_NODE': p2})
43 55 if r:
44 repo.ui.warn(_("merging %s failed!\n") % fn)
56 repo.ui.warn(_("merging %s failed!\n") % fw)
45 57
46 58 os.unlink(b)
47 59 os.unlink(c)
48 60 return r
49 61
62 def merge3(repo, fn, my, other, p1, p2):
63 """perform a 3-way merge in the working directory"""
64 return filemerge(repo, fn, fn, fn, my, other, p1, p2, False)
65
50 66 def checkunknown(repo, m2, status):
51 67 """
52 68 check for collisions between unknown files and files in m2
@@ -27,7 +27,7 resolving manifests
27 27 test.txt: versions differ -> m
28 28 merging test.txt
29 29 resolving test.txt
30 file test.txt: my fc3148072371 other d40249267ae3 ancestor 8fe46a3eb557
30 my test.txt@451c744aabcc other test.txt@a070d41e8360 ancestor test.txt@faaea63e63a9
31 31 merging test.txt failed!
32 32 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
33 33 There are unresolved merges, you can redo the full merge using:
@@ -21,7 +21,7 resolving manifests
21 21 b: remote created -> g
22 22 merging a
23 23 resolving a
24 file a: my b789fdd96dc2 other d730145abbf9 ancestor b789fdd96dc2
24 my a@33aaa84a386b other a@802f095af299 ancestor a@33aaa84a386b
25 25 getting b
26 26 1 files updated, 1 files merged, 0 files removed, 0 files unresolved
27 27 changeset: 1:802f095af299
@@ -55,7 +55,7 resolving manifests
55 55 b: remote created -> g
56 56 merging a
57 57 resolving a
58 file a: my b789fdd96dc2 other d730145abbf9 ancestor b789fdd96dc2
58 my a@33aaa84a386b other a@802f095af299 ancestor a@33aaa84a386b
59 59 getting b
60 60 1 files updated, 1 files merged, 0 files removed, 0 files unresolved
61 61 changeset: 1:802f095af299
@@ -106,10 +106,10 resolving manifests
106 106 b: versions differ -> m
107 107 merging a
108 108 resolving a
109 file a: my d730145abbf9 other 13e0d5f949fa ancestor b789fdd96dc2
109 my a@802f095af299 other a@030602aee63d ancestor a@33aaa84a386b
110 110 merging b
111 111 resolving b
112 file b: my 1e88685f5dde other 61de8c7723ca ancestor 000000000000
112 my b@802f095af299 other b@030602aee63d ancestor b@000000000000
113 113 0 files updated, 2 files merged, 0 files removed, 0 files unresolved
114 114 (branch merge, don't forget to commit)
115 115 changeset: 1:802f095af299
General Comments 0
You need to be logged in to leave comments. Login now