246 if dirname == name: |
246 if dirname == name: |
247 break |
247 break |
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 |