Apache/Windows 上的 Mercurial 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2229341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mercurial Server on Apache/Windows
提问by Jhonny D. Cano -Leftware-
I'm searching for info to setup a Mercurial Server for Windows (7 or XP) with an Apache (xampp if it is useful to know it) with the Push Model, just like in this questionbut my team is composed of 5 to 8 (unsolvent) guys who are each one working in separated places, so I don't think the bitbucket solution or anyother non-private repo out there.
我正在搜索信息以使用推送模型为 Windows(7 或 XP)设置 Mercurial 服务器(如果知道它有用,则为 xampp),就像在这个问题中一样,但我的团队由 5 到 8 人组成(无偿付能力)每个人都在不同的地方工作,所以我不认为 bitbucket 解决方案或任何其他非私人回购在那里。
I think this postwould do the trick, but i haven't experienced anything with cgi before,
我认为这篇文章可以解决问题,但我之前没有使用过 cgi,
Has anybody done this before? where can I find a more detailed explanation? thanks in advance
以前有人这样做过吗?我在哪里可以找到更详细的解释?提前致谢
[EDIT]
[编辑]
I'm now getting this error: Premature end of script headers: hgwebdir.cgi
我现在收到此错误:脚本标题过早结束:hgwebdir.cgi
The log error says "no module named mercurial"
日志错误说“没有名为 mercurial 的模块”
this is my hgwebdir.cgi file
这是我的 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)
回答by John Weldon
I used the HgWebDir instructions:
我使用了HgWebDir 指令:
Here is my httpd.conf piece for the mercurial sites (slightly edited):
这是我用于 mercurial 站点的 httpd.conf 部分(略有编辑):
<VirtualHost *:88>
ServerName hg.example.com
DocumentRoot c:/apache_sites/hg
RewriteEngine on
RewriteRule ^/$ /public [R]
RewriteRule ^/public(.*) /public/hgwebdir.cgi [L]
RewriteRule ^/private(.*) /private/hgwebdir.cgi [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:
I also had to turn on a few modules for Auth Digest, etc.
我还必须为 Auth Digest 等打开一些模块。
I put the hgwebdir.cgi in the root of the public and the private folders, and just put each of my hg repos in the repos subfolder under the appropriate folders.
我将 hgwebdir.cgi 放在 public 和 private 文件夹的根目录中,并将我的每个 hg repos 放在相应文件夹下的 repos 子文件夹中。
Apache authentication took care of my authorization.
Apache 身份验证负责我的授权。
Then I just put a hgweb.config file in the same locations like this:
然后我只是将 hgweb.config 文件放在相同的位置,如下所示:
[collections]
repos = repos
[web]
allow_archive = bz2 gz zip
style = gitweb
baseurl = /public
Updated Question
更新的问题
The mercurial packages need to be on the PYTHON_PATH
mercurial 包需要在 PYTHON_PATH 上
This answergives more detail.
这个答案提供了更多细节。
回答by Tom Willis
John Weldons answer is correct, I just wanted to provide a little detail on the wide array of possibilities you may also be interested in.
John Weldons 的回答是正确的,我只是想提供一些有关您可能也感兴趣的各种可能性的详细信息。
hgwebdir is just a wsgiapplication, so you can run it like any other wsgi application using mod_wsgiin apache2. mod_wsgi will also perform better than cgi because the overhead of loading the python interpreter is done once rather than for each request.
hgwebdir 只是一个wsgi应用程序,因此您可以像在 apache2 中使用mod_wsgi 的任何其他 wsgi 应用程序一样运行它。mod_wsgi 也会比 cgi 表现得更好,因为加载 python 解释器的开销是一次完成的,而不是每个请求都完成。
Also by virtue of being a wsgi application means you can also wrap it up in middleware, or hang it off another urlof a bigger website etc...
此外,由于是 wsgi 应用程序,这意味着您还可以将其包装在中间件中,或者将其挂在更大网站的另一个 url 上,等等...
For example, say you are using trac(another wsgi app) and you want to share the authorization scheme between trac and hgwebdir, this can be accomplished by putting them both behind authorization middleware like repoze.whofor example.
例如,假设您正在使用trac(另一个 wsgi 应用程序)并且您想在 trac 和 hgwebdir 之间共享授权方案,这可以通过将它们都放在授权中间件(例如repoze.who)之后来实现。
Finally, since python pastemakes building web apps out of smaller pieces, I wrote this code snippet to start hgwebdir via paste.
最后,由于python paste可以用更小的部分构建 web 应用程序,我写了这个代码片段来通过 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)
And the corresponding config file part to load it...
以及相应的配置文件部分来加载它...
[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
回答by Pete Magsig
I found this blog post particularly helpful: http://blog.riverside-software.fr/2011/02/quick-and-easy-setup-of-mercurial.html.
我发现这篇博文特别有用:http: //blog.riverside-software.fr/2011/02/quick-and-easy-setup-of-mercurial.html。
It's simple, to the point, and got me up and working in less than 15 minutes.
这很简单,让我在不到 15 分钟的时间内起床并开始工作。

