hgwebdir collection on windows

Igor Kostenko isanych at gmail.com
Tue Sep 2 12:48:33 CDT 2008


Hello all,

Today I finally migrated my windows mercurial hosts from 0.9.5 to
1.0.2. I'd used hgwebdir.cgi and python crashed when I upgraded
mercurial to 1.0, 1.0.1 or 1.0.2.
Now I'm using hgwebdir.wsgi and it works.
Also I've decided to look why [collections] don't work on windows.
Answer is simple - In my case config should be next:

[collections]
C:\D\Hg=C:\D\Hg

but config parser look for any of ':' and '=' as delimeters, and in
hgwebdir_mod.py:

            if cp.has_section('collections'):
                for prefix, root in cp.items('collections'):
                    for path in util.walkrepos(root, followsym=True):
                        repo = os.path.normpath(path)
                        name = repo
                        if name.startswith(prefix):
                            name = name[len(prefix):]
                        self.repos.append((name.lstrip(os.sep), repo))

prefix is 'C' and root is '\D\Hg=C:\D\Hg' - of course it doesn't work.
So here my hgwebdir.wsgi

from mercurial.hgweb.hgwebdir_mod import hgwebdir
from mercurial.hgweb.request import wsgiapplication
import os
from mercurial import util

def make_web_app():
    roots = 'C:\D\hg'
    repos = []
    if isinstance(roots, basestring):
        roots = (roots,)
    for root in roots:
        normalroot = os.path.normpath(root)
        for path in util.walkrepos(root):
            repo = os.path.normpath(path)
            name = repo[len(normalroot):].lstrip(os.sep)
            repos.append((name, repo))
    return hgwebdir(repos)

application = wsgiapplication(make_web_app)

I suggest to extend syntax of [collections] to:

[collections]
*=C:\D\Hg

and add next code in hgwebdir_mod.py:

                for prefix, root in cp.items('collections'):
+                    if prefix=='*':
+                        prefix = os.path.normpath(root)
                    for path in util.walkrepos(root, followsym=True):

In this case windows users could use collections and I think this
would be useful for linux users too.

-- 
Best regards, Igor


More information about the Mercurial mailing list