mercurial/filemerge.py
changeset 6025 f2335246e5c7
parent 6016 288ec2f6faa2
child 6075 63e0e57ab157
equal deleted inserted replaced
6024:3121f0feefb4 6025:f2335246e5c7
    41         else:
    41         else:
    42             return True
    42             return True
    43         return False
    43         return False
    44 
    44 
    45     # HGMERGE takes precedence
    45     # HGMERGE takes precedence
    46     if os.environ.get("HGMERGE"):
    46     hgmerge = os.environ.get("HGMERGE")
    47         return os.environ.get("HGMERGE")
    47     if hgmerge:
       
    48         return (hgmerge, hgmerge)
    48 
    49 
    49     # then patterns
    50     # then patterns
    50     for pat, tool in ui.configitems("merge-patterns"):
    51     for pat, tool in ui.configitems("merge-patterns"):
    51         mf = util.matcher(repo.root, "", [pat], [], [])[1]
    52         mf = util.matcher(repo.root, "", [pat], [], [])[1]
    52         if mf(path) and check(tool, pat, symlink, False):
    53         if mf(path) and check(tool, pat, symlink, False):
    53                 return tool
    54                 toolpath = _findtool(ui, tool)
       
    55                 return (tool, '"' + toolpath + '"')
    54 
    56 
    55     # then merge tools
    57     # then merge tools
    56     tools = {}
    58     tools = {}
    57     for k,v in ui.configitems("merge-tools"):
    59     for k,v in ui.configitems("merge-tools"):
    58         t = k.split('.')[0]
    60         t = k.split('.')[0]
    61     tools = [(-p,t) for t,p in tools.items()]
    63     tools = [(-p,t) for t,p in tools.items()]
    62     tools.sort()
    64     tools.sort()
    63     if ui.config("ui", "merge"):
    65     if ui.config("ui", "merge"):
    64         tools.insert(0, (None, ui.config("ui", "merge"))) # highest priority
    66         tools.insert(0, (None, ui.config("ui", "merge"))) # highest priority
    65     tools.append((None, "hgmerge")) # the old default, if found
    67     tools.append((None, "hgmerge")) # the old default, if found
    66     tools.append((None, "internal:merge")) # internal merge as last resort
       
    67     for p,t in tools:
    68     for p,t in tools:
    68         if _findtool(ui, t) and check(t, None, symlink, binary):
    69         toolpath = _findtool(ui, t)
    69             return t
    70         if toolpath and check(t, None, symlink, binary):
       
    71             return (t, '"' + toolpath + '"')
       
    72     # internal merge as last resort
       
    73     return (not (symlink or binary) and "internal:merge" or None, None)
    70 
    74 
    71 def _eoltype(data):
    75 def _eoltype(data):
    72     "Guess the EOL type of a file"
    76     "Guess the EOL type of a file"
    73     if '\0' in data: # binary
    77     if '\0' in data: # binary
    74         return None
    78         return None
   122     ui = repo.ui
   126     ui = repo.ui
   123     fcm = wctx.filectx(fw)
   127     fcm = wctx.filectx(fw)
   124     fca = fcm.ancestor(fco) or repo.filectx(fw, fileid=nullrev)
   128     fca = fcm.ancestor(fco) or repo.filectx(fw, fileid=nullrev)
   125     binary = isbin(fcm) or isbin(fco) or isbin(fca)
   129     binary = isbin(fcm) or isbin(fco) or isbin(fca)
   126     symlink = fcm.islink() or fco.islink()
   130     symlink = fcm.islink() or fco.islink()
   127     tool = _picktool(repo, ui, fw, binary, symlink)
   131     tool, toolpath = _picktool(repo, ui, fw, binary, symlink)
   128     ui.debug(_("picked tool '%s' for %s (binary %s symlink %s)\n") %
   132     ui.debug(_("picked tool '%s' for %s (binary %s symlink %s)\n") %
   129                (tool, fw, binary, symlink))
   133                (tool, fw, binary, symlink))
   130 
   134 
   131     if not tool:
   135     if not tool:
   132         tool = "internal:local"
   136         tool = "internal:local"
   175                HG_BASE_ISLINK=fca.islink())
   179                HG_BASE_ISLINK=fca.islink())
   176 
   180 
   177     if tool == "internal:merge":
   181     if tool == "internal:merge":
   178         r = simplemerge.simplemerge(a, b, c, label=['local', 'other'])
   182         r = simplemerge.simplemerge(a, b, c, label=['local', 'other'])
   179     else:
   183     else:
   180         toolpath = _findtool(ui, tool)
       
   181         args = _toolstr(ui, tool, "args", '$local $base $other')
   184         args = _toolstr(ui, tool, "args", '$local $base $other')
   182         if "$output" in args:
   185         if "$output" in args:
   183             out, a = a, back # read input from backup, write to original
   186             out, a = a, back # read input from backup, write to original
   184         replace = dict(local=a, base=b, other=c, output=out)
   187         replace = dict(local=a, base=b, other=c, output=out)
   185         args = re.sub("\$(local|base|other|output)",
   188         args = re.sub("\$(local|base|other|output)",