Move win32 find_in_files from util_win32 to util.
--- a/mercurial/util.py Thu May 03 17:27:21 2007 -0500
+++ b/mercurial/util.py Sun May 06 16:40:53 2007 +0200
@@ -211,18 +211,6 @@
return fn(s, cmd[len(name):].lstrip())
return pipefilter(s, cmd)
-def find_in_path(name, path, default=None):
- '''find name in search path. path can be string (will be split
- with os.pathsep), or iterable thing that returns strings. if name
- found, return path to name. else return default.'''
- if isinstance(path, str):
- path = path.split(os.pathsep)
- for p in path:
- p_name = os.path.join(p, name)
- if os.path.exists(p_name):
- return p_name
- return default
-
def binary(s):
"""return true if a string is binary data using diff's heuristic"""
if s and '\0' in s[:4096]:
@@ -920,6 +908,30 @@
# username and groupname functions above, too.
def isowner(fp, st=None):
return True
+
+ def find_in_path(name, path, default=None):
+ '''find name in search path. path can be string (will be split
+ with os.pathsep), or iterable thing that returns strings. if name
+ found, return path to name. else return default. name is looked up
+ using cmd.exe rules, using PATHEXT.'''
+ if isinstance(path, str):
+ path = path.split(os.pathsep)
+
+ pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
+ pathext = pathext.lower().split(os.pathsep)
+ isexec = os.path.splitext(name)[1].lower() in pathext
+
+ for p in path:
+ p_name = os.path.join(p, name)
+
+ if isexec and os.path.exists(p_name):
+ return p_name
+
+ for ext in pathext:
+ p_name_ext = p_name + ext
+ if os.path.exists(p_name_ext):
+ return p_name_ext
+ return default
try:
# override functions with win32 versions if possible
@@ -1058,6 +1070,18 @@
if st is None:
st = fstat(fp)
return st.st_uid == os.getuid()
+
+ def find_in_path(name, path, default=None):
+ '''find name in search path. path can be string (will be split
+ with os.pathsep), or iterable thing that returns strings. if name
+ found, return path to name. else return default.'''
+ if isinstance(path, str):
+ path = path.split(os.pathsep)
+ for p in path:
+ p_name = os.path.join(p, name)
+ if os.path.exists(p_name):
+ return p_name
+ return default
def _buildencodefun():
e = '_'
--- a/mercurial/util_win32.py Thu May 03 17:27:21 2007 -0500
+++ b/mercurial/util_win32.py Sun May 06 16:40:53 2007 +0200
@@ -297,30 +297,5 @@
win32file.SetEndOfFile(self.handle)
except pywintypes.error, err:
raise WinIOError(err)
-
-def find_in_path(name, path, default=None):
- '''find name in search path. path can be string (will be split
- with os.pathsep), or iterable thing that returns strings. if name
- found, return path to name. else return default. name is looked up
- using cmd.exe rules, using PATHEXT.'''
- if isinstance(path, str):
- path = path.split(os.pathsep)
-
- pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
- pathext = pathext.lower().split(os.pathsep)
- isexec = os.path.splitext(name)[1].lower() in pathext
-
- for p in path:
- p_name = os.path.join(p, name)
-
- if isexec and os.path.exists(p_name):
- return p_name
-
- for ext in pathext:
- p_name_ext = p_name + ext
- if os.path.exists(p_name_ext):
- return p_name_ext
-
- return default
getuser_fallback = win32api.GetUserName