# HG changeset patch # User Matt Mackall # Date 1202088545 21600 # Node ID 3c9dbb743d2091943950a1f564e899038ad41dac # Parent 3c33032d8906f751ca2b3dd8c0f937dea5a717f4 merge: add registry look up bits to tool search diff -r 3c33032d8906 -r 3c9dbb743d20 mercurial/filemerge.py --- a/mercurial/filemerge.py Sun Feb 03 19:29:05 2008 -0600 +++ b/mercurial/filemerge.py Sun Feb 03 19:29:05 2008 -0600 @@ -16,6 +16,13 @@ return ui.configbool("merge-tools", tool + "." + part, default) def _findtool(ui, tool): + k = _toolstr(ui, tool, "regkey") + if k: + p = util.lookup_reg(k, _toolstr(ui, tool, "regname")) + if p: + p = util.find_exe(p + _toolstr(ui, tool, "regappend")) + if p: + return p return util.find_exe(_toolstr(ui, tool, "executable", tool)) def _picktool(repo, ui, path, binary, symlink): diff -r 3c33032d8906 -r 3c9dbb743d20 mercurial/util.py --- a/mercurial/util.py Sun Feb 03 19:29:05 2008 -0600 +++ b/mercurial/util.py Sun Feb 03 19:29:05 2008 -0600 @@ -1086,6 +1086,9 @@ else: nulldev = '/dev/null' + def lookup_reg(key, name=None, scope=None): + return None + def rcfiles(path): rcs = [os.path.join(path, 'hgrc')] rcdir = os.path.join(path, 'hgrc.d') diff -r 3c33032d8906 -r 3c9dbb743d20 mercurial/util_win32.py --- a/mercurial/util_win32.py Sun Feb 03 19:29:05 2008 -0600 +++ b/mercurial/util_win32.py Sun Feb 03 19:29:05 2008 -0600 @@ -187,6 +187,37 @@ 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. + + valname: value name. If unspecified, the default value for the key + is used. + scope: optionally specify scope for registry lookup, this can be + a sequence of scopes to look up in order. Default (CURRENT_USER, + LOCAL_MACHINE). + ''' + 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()