Mercurial > hg-stable
changeset 13975:938fbeacac84
move walkrepos from util to scmutil
author | Adrian Buehlmann <adrian@cadifra.com> |
---|---|
date | Thu, 21 Apr 2011 16:06:19 +0200 |
parents | 23f2736abce3 |
children | 9ca1ff3d4f8c |
files | mercurial/hgweb/hgwebdir_mod.py mercurial/scmutil.py mercurial/util.py tests/test-walkrepo.py |
diffstat | 4 files changed, 51 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py Thu Apr 21 13:18:52 2011 +0200 +++ b/mercurial/hgweb/hgwebdir_mod.py Thu Apr 21 16:06:19 2011 +0200 @@ -8,7 +8,7 @@ import os, re, time from mercurial.i18n import _ -from mercurial import ui, hg, util, templater +from mercurial import ui, hg, scmutil, util, templater from mercurial import error, encoding, url from common import ErrorResponse, get_mtime, staticfile, paritygen, \ get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR @@ -33,7 +33,7 @@ repos.append((prefix, root)) continue roothead = os.path.normpath(os.path.abspath(roothead)) - paths = util.walkrepos(roothead, followsym=True, recurse=recurse) + paths = scmutil.walkrepos(roothead, followsym=True, recurse=recurse) repos.extend(urlrepos(prefix, roothead, paths)) return repos @@ -89,7 +89,7 @@ repos = findrepos(paths) for prefix, root in u.configitems('collections'): prefix = util.pconvert(prefix) - for path in util.walkrepos(root, followsym=True): + for path in scmutil.walkrepos(root, followsym=True): repo = os.path.normpath(path) name = util.pconvert(repo) if name.startswith(prefix):
--- a/mercurial/scmutil.py Thu Apr 21 13:18:52 2011 +0200 +++ b/mercurial/scmutil.py Thu Apr 21 16:06:19 2011 +0200 @@ -248,3 +248,50 @@ name = dirname raise util.Abort('%s not under root' % myname) + +def walkrepos(path, followsym=False, seen_dirs=None, recurse=False): + '''yield every hg repository under path, recursively.''' + def errhandler(err): + if err.filename == path: + raise err + if followsym and hasattr(os.path, 'samestat'): + def _add_dir_if_not_there(dirlst, dirname): + match = False + samestat = os.path.samestat + dirstat = os.stat(dirname) + for lstdirstat in dirlst: + if samestat(dirstat, lstdirstat): + match = True + break + if not match: + dirlst.append(dirstat) + return not match + else: + followsym = False + + if (seen_dirs is None) and followsym: + seen_dirs = [] + _add_dir_if_not_there(seen_dirs, path) + for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler): + dirs.sort() + if '.hg' in dirs: + yield root # found a repository + qroot = os.path.join(root, '.hg', 'patches') + if os.path.isdir(os.path.join(qroot, '.hg')): + yield qroot # we have a patch queue repo here + if recurse: + # avoid recursing inside the .hg directory + dirs.remove('.hg') + else: + dirs[:] = [] # don't descend further + elif followsym: + newdirs = [] + for d in dirs: + fname = os.path.join(root, d) + if _add_dir_if_not_there(seen_dirs, fname): + if os.path.islink(fname): + for hgname in walkrepos(fname, True, seen_dirs): + yield hgname + else: + newdirs.append(d) + dirs[:] = newdirs
--- a/mercurial/util.py Thu Apr 21 13:18:52 2011 +0200 +++ b/mercurial/util.py Thu Apr 21 16:06:19 2011 +0200 @@ -1083,53 +1083,6 @@ except (UnicodeDecodeError, UnicodeEncodeError): return _ellipsis(text, maxlength)[0] -def walkrepos(path, followsym=False, seen_dirs=None, recurse=False): - '''yield every hg repository under path, recursively.''' - def errhandler(err): - if err.filename == path: - raise err - if followsym and hasattr(os.path, 'samestat'): - def _add_dir_if_not_there(dirlst, dirname): - match = False - samestat = os.path.samestat - dirstat = os.stat(dirname) - for lstdirstat in dirlst: - if samestat(dirstat, lstdirstat): - match = True - break - if not match: - dirlst.append(dirstat) - return not match - else: - followsym = False - - if (seen_dirs is None) and followsym: - seen_dirs = [] - _add_dir_if_not_there(seen_dirs, path) - for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler): - dirs.sort() - if '.hg' in dirs: - yield root # found a repository - qroot = os.path.join(root, '.hg', 'patches') - if os.path.isdir(os.path.join(qroot, '.hg')): - yield qroot # we have a patch queue repo here - if recurse: - # avoid recursing inside the .hg directory - dirs.remove('.hg') - else: - dirs[:] = [] # don't descend further - elif followsym: - newdirs = [] - for d in dirs: - fname = os.path.join(root, d) - if _add_dir_if_not_there(seen_dirs, fname): - if os.path.islink(fname): - for hgname in walkrepos(fname, True, seen_dirs): - yield hgname - else: - newdirs.append(d) - dirs[:] = newdirs - _rcpath = None def os_rcpath():
--- a/tests/test-walkrepo.py Thu Apr 21 13:18:52 2011 +0200 +++ b/tests/test-walkrepo.py Thu Apr 21 16:06:19 2011 +0200 @@ -1,6 +1,6 @@ import os from mercurial import hg, ui -from mercurial.util import walkrepos +from mercurial.scmutil import walkrepos from os import mkdir, chdir from os.path import join as pjoin