[PATCH 2 of 5] enable hgmerge subsystem
Steve Borho
steve at borho.org
Fri Feb 1 04:56:47 UTC 2008
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1201840187 21600
# Node ID 023c3e19566ddd6ce10e2cb79af3f6ddf902433a
# Parent d97cd00ba47b21050f1c85ccd0e06bba36d80eee
enable hgmerge subsystem
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -811,37 +811,43 @@
# merge helper
ui.status(_("Checking merge helper...\n"))
- cmd = (os.environ.get("HGMERGE") or ui.config("ui", "merge")
- or "hgmerge")
- cmdpath = util.find_exe(cmd) or util.find_exe(cmd.split()[0])
- if not cmdpath:
- if cmd == 'hgmerge':
- ui.write(_(" No merge helper set and can't find default"
- " hgmerge script in PATH\n"))
- ui.write(_(" (specify a merge helper in your .hgrc file)\n"))
+ cmd = os.environ.get("HGMERGE") or ui.config("ui", "merge")
+ if not cmd:
+ # internal hgmerge wrapper
+ import hgmerge
+ tools = hgmerge.query_plugins(ui, True)
+ if tools:
+ names = [tool.name for tool in tools]
+ ui.status(_(" Found merge tool(s): %s\n" % ', '.join(names)))
else:
- ui.write(_(" Can't find merge helper '%s' in PATH\n") % cmd)
- ui.write(_(" (specify a merge helper in your .hgrc file)\n"))
+ ui.write(_(" Can't find any merge tools\n"))
+ ui.write(_(" (specify a merge tool in your .hgrc file)\n"))
problems += 1
else:
- # actually attempt a patch here
- fa = writetemp("1\n2\n3\n4\n")
- fl = writetemp("1\n2\n3\ninsert\n4\n")
- fr = writetemp("begin\n1\n2\n3\n4\n")
- r = util.system('%s "%s" "%s" "%s"' % (cmd, fl, fa, fr))
- if r:
- ui.write(_(" Got unexpected merge error %d!\n") % r)
+ cmdpath = util.find_exe(cmd) or util.find_exe(cmd.split()[0])
+ if not cmdpath:
+ ui.write(_(" Can't find merge helper '%s' in PATH\n") % cmd)
+ ui.write(_(" (specify merge helper path in your .hgrc file)\n"))
problems += 1
- m = file(fl).read()
- if m != "begin\n1\n2\n3\ninsert\n4\n":
- ui.write(_(" Got unexpected merge results!\n"))
- ui.write(_(" (your merge helper may have the"
- " wrong argument order)\n"))
- ui.write(_(" Result: %r\n") % m)
- problems += 1
- os.unlink(fa)
- os.unlink(fl)
- os.unlink(fr)
+ else:
+ # actually attempt a patch here
+ fa = writetemp("1\n2\n3\n4\n")
+ fl = writetemp("1\n2\n3\ninsert\n4\n")
+ fr = writetemp("begin\n1\n2\n3\n4\n")
+ r = util.system('%s "%s" "%s" "%s"' % (cmd, fl, fa, fr))
+ if r:
+ ui.write(_(" Got unexpected merge error %d!\n") % r)
+ problems += 1
+ m = file(fl).read()
+ if m != "begin\n1\n2\n3\ninsert\n4\n":
+ ui.write(_(" Got unexpected merge results!\n"))
+ ui.write(_(" (your merge helper may have the"
+ " wrong argument order)\n"))
+ ui.write(_(" Result: %r\n") % m)
+ problems += 1
+ os.unlink(fa)
+ os.unlink(fl)
+ os.unlink(fr)
# editor
ui.status(_("Checking commit editor...\n"))
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -8,6 +8,8 @@
from node import *
from i18n import _
import errno, util, os, tempfile, context, heapq
+
+from mercurial import hgmerge
def filemerge(repo, fw, fd, fo, wctx, mctx):
"""perform a 3-way merge in the working directory
@@ -40,7 +42,6 @@
a = repo.wjoin(fd)
b = temp("base", fca)
c = temp("other", fco)
-
if fw != fo:
repo.ui.status(_("merging %s and %s\n") % (fw, fo))
else:
@@ -48,17 +49,21 @@
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': fd,
- 'HG_MY_NODE': str(wctx.parents()[0]),
- 'HG_OTHER_NODE': str(mctx),
- 'HG_MY_ISLINK': fcm.islink(),
- 'HG_OTHER_ISLINK': fco.islink(),
- 'HG_BASE_ISLINK': fca.islink(),})
- if r:
- repo.ui.warn(_("merging %s failed!\n") % fd)
+ cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge"))
+ if cmd:
+ r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root,
+ environ={'HG_FILE': fd,
+ 'HG_MY_NODE': str(wctx.parents()[0]),
+ 'HG_OTHER_NODE': str(mctx),
+ 'HG_MY_ISLINK': fcm.islink(),
+ 'HG_OTHER_ISLINK': fco.islink(),
+ 'HG_BASE_ISLINK': fca.islink(),})
+
+ if r:
+ repo.ui.warn(_("merging %s failed!\n") % fd)
+ else:
+ fcm.fname, fca.fname, fco.fname = a, b, c
+ r = hgmerge.merge(repo, fcm, fca, fco)
os.unlink(b)
os.unlink(c)
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -221,6 +221,37 @@
if s and '\0' in s[:4096]:
return True
return False
+
+def eoltype(name):
+ """get the eol or file type"""
+ try:
+ # First check if it's a symlink
+ lmode = os.lstat(name)[stat.ST_MODE]
+ if stat.S_ISLNK(lmode):
+ return 'symlink'
+
+ # Look for tell-tale signs in first 4K of file
+ f = open(name, "rb")
+ data = f.read(4096)
+ f.close()
+ if '\0' in data:
+ return 'binary'
+ elif '\r\n' in data:
+ return 'dos'
+ elif '\r' in data:
+ return 'mac'
+ elif '\n' in data:
+ return 'unix'
+ elif len(data) == 1024:
+ return 'binary'
+ else:
+ # small file with no line-feeds, return native
+ if os.name == 'nt':
+ return 'dos'
+ else:
+ return 'unix'
+ except (IOError, OSError):
+ return 'unknown'
def unique(g):
"""return the uniq elements of iterable g"""
diff --git a/mercurial/util_win32.py b/mercurial/util_win32.py
--- a/mercurial/util_win32.py
+++ b/mercurial/util_win32.py
@@ -187,6 +187,38 @@
return details[0] != winerror.ERROR_INVALID_PARAMETER
return True
+def lookup_reg(key, valname=None, scope=None):
+ ''' Look up a key/value name in the Windows registry.
+
+ @param valname: value name. If unspecified, the default value for the key
+ is used.
+ @param scope: optionally specify scope for registry lookup, this can be
+ a sequence of scopes to look up in order. Default (CURRENT_USER,
+ LOCAL_MACHINE).
+ @return: the value if found, else None.
+ '''
+ try:
+ from _winreg import HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, \
+ QueryValueEx, OpenKey
+ except ImportError:
+ return None
+
+ def query_val(scope, key):
+ try:
+ keyhandle = OpenKey(scope, key)
+ return QueryValueEx(keyhandle, valname)[0]
+ except EnvironmentError:
+ return None
+
+ if scope is None:
+ scope = (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE)
+ elif not isinstance(scope, (list, tuple)):
+ scope = (scope,)
+ for s in scope:
+ val = query_val(s, key, valname)
+ if val is not None:
+ return val
+
def system_rcpath_win32():
'''return default os-specific hgrc search path'''
proc = win32api.GetCurrentProcess()
More information about the Mercurial-devel
mailing list