##// END OF EJS Templates
move walkrepos from util to scmutil
Adrian Buehlmann -
r13975:938fbeac default
parent child Browse files
Show More
@@ -8,7 +8,7
8
8
9 import os, re, time
9 import os, re, time
10 from mercurial.i18n import _
10 from mercurial.i18n import _
11 from mercurial import ui, hg, util, templater
11 from mercurial import ui, hg, scmutil, util, templater
12 from mercurial import error, encoding, url
12 from mercurial import error, encoding, url
13 from common import ErrorResponse, get_mtime, staticfile, paritygen, \
13 from common import ErrorResponse, get_mtime, staticfile, paritygen, \
14 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
14 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
@@ -33,7 +33,7 def findrepos(paths):
33 repos.append((prefix, root))
33 repos.append((prefix, root))
34 continue
34 continue
35 roothead = os.path.normpath(os.path.abspath(roothead))
35 roothead = os.path.normpath(os.path.abspath(roothead))
36 paths = util.walkrepos(roothead, followsym=True, recurse=recurse)
36 paths = scmutil.walkrepos(roothead, followsym=True, recurse=recurse)
37 repos.extend(urlrepos(prefix, roothead, paths))
37 repos.extend(urlrepos(prefix, roothead, paths))
38 return repos
38 return repos
39
39
@@ -89,7 +89,7 class hgwebdir(object):
89 repos = findrepos(paths)
89 repos = findrepos(paths)
90 for prefix, root in u.configitems('collections'):
90 for prefix, root in u.configitems('collections'):
91 prefix = util.pconvert(prefix)
91 prefix = util.pconvert(prefix)
92 for path in util.walkrepos(root, followsym=True):
92 for path in scmutil.walkrepos(root, followsym=True):
93 repo = os.path.normpath(path)
93 repo = os.path.normpath(path)
94 name = util.pconvert(repo)
94 name = util.pconvert(repo)
95 if name.startswith(prefix):
95 if name.startswith(prefix):
@@ -248,3 +248,50 def canonpath(root, cwd, myname, auditor
248 name = dirname
248 name = dirname
249
249
250 raise util.Abort('%s not under root' % myname)
250 raise util.Abort('%s not under root' % myname)
251
252 def walkrepos(path, followsym=False, seen_dirs=None, recurse=False):
253 '''yield every hg repository under path, recursively.'''
254 def errhandler(err):
255 if err.filename == path:
256 raise err
257 if followsym and hasattr(os.path, 'samestat'):
258 def _add_dir_if_not_there(dirlst, dirname):
259 match = False
260 samestat = os.path.samestat
261 dirstat = os.stat(dirname)
262 for lstdirstat in dirlst:
263 if samestat(dirstat, lstdirstat):
264 match = True
265 break
266 if not match:
267 dirlst.append(dirstat)
268 return not match
269 else:
270 followsym = False
271
272 if (seen_dirs is None) and followsym:
273 seen_dirs = []
274 _add_dir_if_not_there(seen_dirs, path)
275 for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler):
276 dirs.sort()
277 if '.hg' in dirs:
278 yield root # found a repository
279 qroot = os.path.join(root, '.hg', 'patches')
280 if os.path.isdir(os.path.join(qroot, '.hg')):
281 yield qroot # we have a patch queue repo here
282 if recurse:
283 # avoid recursing inside the .hg directory
284 dirs.remove('.hg')
285 else:
286 dirs[:] = [] # don't descend further
287 elif followsym:
288 newdirs = []
289 for d in dirs:
290 fname = os.path.join(root, d)
291 if _add_dir_if_not_there(seen_dirs, fname):
292 if os.path.islink(fname):
293 for hgname in walkrepos(fname, True, seen_dirs):
294 yield hgname
295 else:
296 newdirs.append(d)
297 dirs[:] = newdirs
@@ -1083,53 +1083,6 def ellipsis(text, maxlength=400):
1083 except (UnicodeDecodeError, UnicodeEncodeError):
1083 except (UnicodeDecodeError, UnicodeEncodeError):
1084 return _ellipsis(text, maxlength)[0]
1084 return _ellipsis(text, maxlength)[0]
1085
1085
1086 def walkrepos(path, followsym=False, seen_dirs=None, recurse=False):
1087 '''yield every hg repository under path, recursively.'''
1088 def errhandler(err):
1089 if err.filename == path:
1090 raise err
1091 if followsym and hasattr(os.path, 'samestat'):
1092 def _add_dir_if_not_there(dirlst, dirname):
1093 match = False
1094 samestat = os.path.samestat
1095 dirstat = os.stat(dirname)
1096 for lstdirstat in dirlst:
1097 if samestat(dirstat, lstdirstat):
1098 match = True
1099 break
1100 if not match:
1101 dirlst.append(dirstat)
1102 return not match
1103 else:
1104 followsym = False
1105
1106 if (seen_dirs is None) and followsym:
1107 seen_dirs = []
1108 _add_dir_if_not_there(seen_dirs, path)
1109 for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler):
1110 dirs.sort()
1111 if '.hg' in dirs:
1112 yield root # found a repository
1113 qroot = os.path.join(root, '.hg', 'patches')
1114 if os.path.isdir(os.path.join(qroot, '.hg')):
1115 yield qroot # we have a patch queue repo here
1116 if recurse:
1117 # avoid recursing inside the .hg directory
1118 dirs.remove('.hg')
1119 else:
1120 dirs[:] = [] # don't descend further
1121 elif followsym:
1122 newdirs = []
1123 for d in dirs:
1124 fname = os.path.join(root, d)
1125 if _add_dir_if_not_there(seen_dirs, fname):
1126 if os.path.islink(fname):
1127 for hgname in walkrepos(fname, True, seen_dirs):
1128 yield hgname
1129 else:
1130 newdirs.append(d)
1131 dirs[:] = newdirs
1132
1133 _rcpath = None
1086 _rcpath = None
1134
1087
1135 def os_rcpath():
1088 def os_rcpath():
@@ -1,6 +1,6
1 import os
1 import os
2 from mercurial import hg, ui
2 from mercurial import hg, ui
3 from mercurial.util import walkrepos
3 from mercurial.scmutil import walkrepos
4 from os import mkdir, chdir
4 from os import mkdir, chdir
5 from os.path import join as pjoin
5 from os.path import join as pjoin
6
6
General Comments 0
You need to be logged in to leave comments. Login now