mercurial/merge.py
changeset 3303 69b9471f26bb
parent 3302 20087b4bc6f9
child 3305 e7abcf3a7c5f
equal deleted inserted replaced
3302:20087b4bc6f9 3303:69b9471f26bb
     8 from node import *
     8 from node import *
     9 from i18n import gettext as _
     9 from i18n import gettext as _
    10 from demandload import *
    10 from demandload import *
    11 demandload(globals(), "errno util os tempfile")
    11 demandload(globals(), "errno util os tempfile")
    12 
    12 
    13 def filemerge(repo, fw, fo, fd, my, other, p1, p2, move):
    13 def filemerge(repo, fw, fo, fd, my, other, wctx, mctx, move):
    14     """perform a 3-way merge in the working directory
    14     """perform a 3-way merge in the working directory
    15 
    15 
    16     fw = filename in the working directory and first parent
    16     fw = filename in the working directory and first parent
    17     fo = filename in other parent
    17     fo = filename in other parent
    18     fd = destination filename
    18     fd = destination filename
    19     my = fileid in first parent
    19     my = fileid in first parent
    20     other = fileid in second parent
    20     other = fileid in second parent
    21     p1, p2 = hex changeset ids for merge command
    21     wctx, mctx = working and merge changecontexts
    22     move = whether to move or copy the file to the destination
    22     move = whether to move or copy the file to the destination
    23 
    23 
    24     TODO:
    24     TODO:
    25       if fw is copied in the working directory, we get confused
    25       if fw is copied in the working directory, we get confused
    26       implement move and fd
    26       implement move and fd
    48 
    48 
    49     cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge")
    49     cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge")
    50            or "hgmerge")
    50            or "hgmerge")
    51     r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root,
    51     r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root,
    52                     environ={'HG_FILE': fw,
    52                     environ={'HG_FILE': fw,
    53                              'HG_MY_NODE': p1,
    53                              'HG_MY_NODE': str(wctx.parents()[0]),
    54                              'HG_OTHER_NODE': p2})
    54                              'HG_OTHER_NODE': str(mctx)})
    55     if r:
    55     if r:
    56         repo.ui.warn(_("merging %s failed!\n") % fw)
    56         repo.ui.warn(_("merging %s failed!\n") % fw)
    57     else:
    57     else:
    58         if fd != fw:
    58         if fd != fw:
    59             repo.ui.debug(_("copying %s to %s\n") % (fw, fd))
    59             repo.ui.debug(_("copying %s to %s\n") % (fw, fd))
   273         else:
   273         else:
   274             act("remote created", f, "g", m2.execf(f), n)
   274             act("remote created", f, "g", m2.execf(f), n)
   275 
   275 
   276     return action
   276     return action
   277 
   277 
   278 def applyupdates(repo, action, xp1, xp2):
   278 def applyupdates(repo, action, wctx, mctx):
   279     updated, merged, removed, unresolved = 0, 0, 0, 0
   279     updated, merged, removed, unresolved = 0, 0, 0, 0
   280     action.sort()
   280     action.sort()
   281     for a in action:
   281     for a in action:
   282         f, m = a[:2]
   282         f, m = a[:2]
   283         if f[0] == "/":
   283         if f[0] == "/":
   293                                  (f, inst.strerror))
   293                                  (f, inst.strerror))
   294             removed +=1
   294             removed +=1
   295         elif m == "c": # copy
   295         elif m == "c": # copy
   296             f2, fd, my, other, flag, move = a[2:]
   296             f2, fd, my, other, flag, move = a[2:]
   297             repo.ui.status(_("merging %s and %s to %s\n") % (f, f2, fd))
   297             repo.ui.status(_("merging %s and %s to %s\n") % (f, f2, fd))
   298             if filemerge(repo, f, f2, fd, my, other, xp1, xp2, move):
   298             if filemerge(repo, f, f2, fd, my, other, wctx, mctx, move):
   299                 unresolved += 1
   299                 unresolved += 1
   300             util.set_exec(repo.wjoin(fd), flag)
   300             util.set_exec(repo.wjoin(fd), flag)
   301             merged += 1
   301             merged += 1
   302         elif m == "m": # merge
   302         elif m == "m": # merge
   303             flag, my, other = a[2:]
   303             flag, my, other = a[2:]
   304             repo.ui.status(_("merging %s\n") % f)
   304             repo.ui.status(_("merging %s\n") % f)
   305             if filemerge(repo, f, f, f, my, other, xp1, xp2, False):
   305             if filemerge(repo, f, f, f, my, other, wctx, mctx, False):
   306                 unresolved += 1
   306                 unresolved += 1
   307             util.set_exec(repo.wjoin(f), flag)
   307             util.set_exec(repo.wjoin(f), flag)
   308             merged += 1
   308             merged += 1
   309         elif m == "g": # get
   309         elif m == "g": # get
   310             flag, node = a[2:]
   310             flag, node = a[2:]
   431         fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2)
   431         fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2)
   432 
   432 
   433     if not partial:
   433     if not partial:
   434         repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2)
   434         repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2)
   435 
   435 
   436     updated, merged, removed, unresolved = applyupdates(repo, action, xp1, xp2)
   436     updated, merged, removed, unresolved = applyupdates(repo, action, wc, p2)
   437 
   437 
   438     # update dirstate
   438     # update dirstate
   439     if not partial:
   439     if not partial:
   440         recordupdates(repo, action, branchmerge)
   440         recordupdates(repo, action, branchmerge)
   441         repo.dirstate.setparents(fp1, fp2)
   441         repo.dirstate.setparents(fp1, fp2)