mercurial/merge.py
changeset 3211 3fd098e0902d
parent 3169 9e002614f2eb
child 3212 cac7be0b9b99
equal deleted inserted replaced
3210:7240f9e47144 3211:3fd098e0902d
     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 merge3(repo, fn, my, other, p1, p2):
    13 def filemerge(repo, fw, fo, fd, my, other, p1, p2, move):
    14     """perform a 3-way merge in the working directory"""
    14     """perform a 3-way merge in the working directory
    15 
    15 
    16     def temp(prefix, node):
    16     fw = filename in the working directory and first parent
    17         pre = "%s~%s." % (os.path.basename(fn), prefix)
    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         (fd, name) = tempfile.mkstemp(prefix=pre)
    31         (fd, name) = tempfile.mkstemp(prefix=pre)
    19         f = os.fdopen(fd, "wb")
    32         f = os.fdopen(fd, "wb")
    20         repo.wwrite(fn, fl.read(node), f)
    33         repo.wwrite(ctx.path(), ctx.data(), f)
    21         f.close()
    34         f.close()
    22         return name
    35         return name
    23 
    36 
    24     fl = repo.file(fn)
    37     fcm = repo.filectx(fw, fileid=my)
    25     base = fl.ancestor(my, other)
    38     fco = repo.filectx(fo, fileid=other)
    26     a = repo.wjoin(fn)
    39     fca = fcm.ancestor(fco)
    27     b = temp("base", base)
    40     if not fca:
    28     c = temp("other", other)
    41         fca = repo.filectx(fw, fileid=-1)
    29 
    42     a = repo.wjoin(fw)
    30     repo.ui.note(_("resolving %s\n") % fn)
    43     b = temp("base", fca)
    31     repo.ui.debug(_("file %s: my %s other %s ancestor %s\n") %
    44     c = temp("other", fco)
    32                           (fn, short(my), short(other), short(base)))
    45 
       
    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     cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge")
    49     cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge")
    35            or "hgmerge")
    50            or "hgmerge")
    36     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,
    37                     environ={'HG_FILE': fn,
    52                     environ={'HG_FILE': fw,
    38                              'HG_MY_NODE': p1,
    53                              'HG_MY_NODE': p1,
    39                              'HG_OTHER_NODE': p2,
    54                              '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)})
       
    43     if r:
    55     if r:
    44         repo.ui.warn(_("merging %s failed!\n") % fn)
    56         repo.ui.warn(_("merging %s failed!\n") % fw)
    45 
    57 
    46     os.unlink(b)
    58     os.unlink(b)
    47     os.unlink(c)
    59     os.unlink(c)
    48     return r
    60     return r
       
    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)
    49 
    65 
    50 def checkunknown(repo, m2, status):
    66 def checkunknown(repo, m2, status):
    51     """
    67     """
    52     check for collisions between unknown files and files in m2
    68     check for collisions between unknown files and files in m2
    53     """
    69     """