代码之家  ›  专栏  ›  技术社区  ›  Jhonny D. Cano -Leftware-

Apache/Windows上的Mercurial服务器

  •  5
  • Jhonny D. Cano -Leftware-  · 技术社区  · 15 年前

    我正在搜索信息,以便为Windows(7或XP)安装一个Mercurial服务器,并使用Apache(如果了解它很有用,请使用xampp),就像在 this question 但是我的团队由5到8个(未售出的)人组成,每个人在不同的地方工作,所以我不认为BitBucket解决方案或任何其他非私有回购。

    我想 this post 会的,但是我以前没有经历过任何关于CGI的事情,

    以前有人做过吗?哪里可以找到更详细的解释?提前谢谢

    [编辑]

    我现在得到这个错误:脚本头过早结束:hgwebdir.cgi

    日志错误显示“没有名为mercurial的模块”

    这是我的hgwebdir.cgi文件

    #!c:/python24/python.exe
    #
    # An example CGI script to export multiple hgweb repos, edit as necessary
    
    # adjust python path if not a system-wide install:
    import sys
    sys.path.insert(0, "c:/mercurial_library")
    
    # enable importing on demand to reduce startup time
    from mercurial import demandimport; demandimport.enable()
    
    # Uncomment to send python tracebacks to the browser if an error occurs:
    #import cgitb
    #cgitb.enable()
    
    # If you'd like to serve pages with UTF-8 instead of your default
    # locale charset, you can do so by uncommenting the following lines.
    # Note that this will cause your .hgrc files to be interpreted in
    # UTF-8 and all your repo files to be displayed using UTF-8.
    #
    #import os
    #os.environ["HGENCODING"] = "UTF-8"
    
    from mercurial.hgweb.hgwebdir_mod import hgwebdir
    import mercurial.hgweb.wsgicgi as wsgicgi
    application = hgwebdir('hgweb.config')
    wsgicgi.launch(application)
    
    3 回复  |  直到 8 年前
        1
  •  9
  •   Vadim Kotov First Zero    8 年前

    我用过 HgWebDir instructions :

    这是我的httpd.conf文章,为Mercurial网站(稍微编辑一下):

    <VirtualHost *:88>
        ServerName hg.example.com
        DocumentRoot c:/apache_sites/hg
        RewriteEngine on
    
        RewriteRule ^/$ /public [R]
        RewriteRule ^/public(.*) /public/hgwebdir.cgi$1 [L]
        RewriteRule ^/private(.*) /private/hgwebdir.cgi$1 [L]
    
        # mod_alias alternative (pretty url's)
        <Directory c:/apache_sites/hg >
            Order allow,deny
            Allow from all
            AllowOverride All
            Options ExecCGI
            AddHandler cgi-script .cgi
        </Directory>
        <Location /private/>
            AuthType Digest
            AuthName "hg.example.com"
            AuthDigestProvider file
            AuthUserFile c:/apache_sites/hg/hgusers
            AuthGroupFile c:/apache_sites/hg/hggroup
            AuthDigestDomain /private/
            Require group owner
        </Location>
        <Location /public/>
            AuthType Digest
            AuthName "hg.example.com"
            AuthDigestProvider file
            AuthUserFile c:/apache_sites/hg/hgusers
            AuthGroupFile c:/apache_sites/hg/hggroup
            AuthDigestDomain /public/
            <LimitExcept GET>
                Require group developer
            </LimitExcept>
        </Location>
    
        LogLevel debug
        ErrorLog "c:/apache/logs/hg-error.log"
        CustomLog "c:/apache/logs/hg-access.log" combined
        LogLevel debug
    </VirtualHost>
    # vim:se ft=apache:
    

    我还必须为auth摘要等打开一些模块。

    我将hgwebdir.cgi放在公用文件夹和专用文件夹的根目录中,然后将每个hg repos放在相应文件夹下的repos子文件夹中。

    Apache身份验证处理了我的授权。

    然后我将一个hgweb.config文件放在如下相同的位置:

    [collections]
    repos = repos
    
    [web]
    allow_archive = bz2 gz zip
    style = gitweb
    baseurl = /public
    

    更新的问题

    Mercurial软件包必须在python路径上

    This answer 提供更多细节。

        2
  •  8
  •   Tom Willis    15 年前

    约翰·韦尔登的回答是正确的,我只是想提供一些你可能也感兴趣的各种可能性的细节。

    hgwebdir只是一个 wsgi 应用程序,因此您可以像使用 mod_wsgi 在APACHE2中。mod_wsgi的性能也将优于cgi,因为加载python解释器的开销只完成一次,而不是针对每个请求。

    而且,由于是一个WSGi应用程序,意味着您也可以将其包装在 middleware hang it off another url 一个更大的网站等…

    例如,假设您正在使用 trac (另一个wsgi应用程序)并且您希望在trac和hgwebdir之间共享授权方案,这可以通过将它们放在授权中间件后面来实现,例如 repoze.who 例如。

    最后,因为 python paste 我写了这个代码片段,通过粘贴启动hgwebdir。

    """
    Wsgi wrapper of hgweb that is paste compatible
    """
    import os
    from mercurial import demandimport
    demandimport.enable()
    from mercurial.hgweb.hgwebdir_mod import hgwebdir
    
    CONFIG_FILE_KEY = "hgwebdir.config"
    
    def hgweb_paste(global_config, **local_conf):
        """
        looking for a config file setting in global or local
        """
        cfg = global_config
        cfg.update(local_conf)
        config_file = cfg.get(CONFIG_FILE_KEY)
        if config_file and os.path.exists(config_file):
            return hgwebdir(config_file)
        else:
            raise KeyError, "%s not set or %s does not exist" % (CONFIG_FILE_KEY,config_file)
    

    以及加载它的相应配置文件部分…

    [server:main]
    use = egg:Paste#http
    host = 0.0.0.0
    port = 6543
    
    [app:main]
    use = egg:hg.paste#hgweb
    hgwebdir.config = %(here)s/hg.config
    
        3
  •  0
  •   Pete Magsig    13 年前

    我发现这篇博文特别有用: http://blog.riverside-software.fr/2011/02/quick-and-easy-setup-of-mercurial.html .

    这很简单,直截了当,让我在不到15分钟的时间内起床工作。