Show More
@@ -8,10 +8,21 b' cgitb.enable()' | |||
|
8 | 8 | # sys.path.insert(0, "/path/to/python/lib") # if not a system-wide install |
|
9 | 9 | from mercurial import hgweb |
|
10 | 10 | |
|
11 |
# The config file looks like this |
|
|
11 | # The config file looks like this. You can have paths to individual | |
|
12 | # repos, collections of repos in a directory tree, or both. | |
|
13 | # | |
|
12 | 14 | # [paths] |
|
13 | 15 | # virtual/path = /real/path |
|
14 | 16 | # virtual/path = /real/path |
|
17 | # | |
|
18 | # [collections] | |
|
19 | # /prefix/to/strip/off = /root/of/tree/full/of/repos | |
|
20 | # | |
|
21 | # collections example: say directory tree /foo contains repos /foo/bar, | |
|
22 | # /foo/quux/baz. Give this config section: | |
|
23 | # [collections] | |
|
24 | # /foo = /foo | |
|
25 | # Then repos will list as bar and quux/baz. | |
|
15 | 26 | |
|
16 | 27 | # Alternatively you can pass a list of ('virtual/path', '/real/path') tuples |
|
17 | 28 | # or use a dictionary with entries like 'virtual/path': '/real/path' |
@@ -1075,17 +1075,27 b' def create_server(repo):' | |||
|
1075 | 1075 | class hgwebdir(object): |
|
1076 | 1076 | def __init__(self, config): |
|
1077 | 1077 | def cleannames(items): |
|
1078 |
return [(name.strip( |
|
|
1078 | return [(name.strip(os.sep), path) for name, path in items] | |
|
1079 | 1079 | |
|
1080 |
if |
|
|
1080 | if isinstance(config, (list, tuple)): | |
|
1081 | 1081 | self.repos = cleannames(config) |
|
1082 |
elif |
|
|
1082 | elif isinstance(config, dict): | |
|
1083 | 1083 | self.repos = cleannames(config.items()) |
|
1084 | 1084 | self.repos.sort() |
|
1085 | 1085 | else: |
|
1086 | 1086 | cp = ConfigParser.SafeConfigParser() |
|
1087 | 1087 | cp.read(config) |
|
1088 |
self.repos = |
|
|
1088 | self.repos = [] | |
|
1089 | if cp.has_section('paths'): | |
|
1090 | self.repos.extend(cleannames(cp.items('paths'))) | |
|
1091 | if cp.has_section('collections'): | |
|
1092 | for prefix, root in cp.items('collections'): | |
|
1093 | for path in util.walkrepos(root): | |
|
1094 | repo = os.path.normpath(path) | |
|
1095 | name = repo | |
|
1096 | if name.startswith(prefix): | |
|
1097 | name = name[len(prefix):] | |
|
1098 | self.repos.append((name.lstrip(os.sep), repo)) | |
|
1089 | 1099 | self.repos.sort() |
|
1090 | 1100 | |
|
1091 | 1101 | def run(self, req=hgrequest()): |
@@ -690,3 +690,16 b" def datestr(date=None, format='%c'):" | |||
|
690 | 690 | (time.strftime(format, time.gmtime(float(t) - tz)), |
|
691 | 691 | -tz / 3600, |
|
692 | 692 | ((-tz % 3600) / 60))) |
|
693 | ||
|
694 | def walkrepos(path): | |
|
695 | '''yield every hg repository under path, recursively.''' | |
|
696 | def errhandler(err): | |
|
697 | if err.filename == path: | |
|
698 | raise err | |
|
699 | ||
|
700 | for root, dirs, files in os.walk(path, onerror=errhandler): | |
|
701 | for d in dirs: | |
|
702 | if d == '.hg': | |
|
703 | yield root | |
|
704 | dirs[:] = [] | |
|
705 | break |
General Comments 0
You need to be logged in to leave comments.
Login now