Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 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 | af60153b5e3b |
comparison
equal
deleted
inserted
replaced
13974:23f2736abce3 | 13975:938fbeacac84 |
---|---|
1081 return text | 1081 return text |
1082 return utext.encode(encoding.encoding) | 1082 return utext.encode(encoding.encoding) |
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(): |
1136 '''return default os-specific hgrc search path''' | 1089 '''return default os-specific hgrc search path''' |
1137 path = system_rcpath() | 1090 path = system_rcpath() |