It should be fairly similar for Unix based system, but I haven’t tried that. You can obviously use a different server too.
Thanks goes to my friend Jeroen who helped me out with this.
Obviously, you need Mercurial. It’s up to you how you want to install it, but make sure that the hg command is available from command line. Use the MSI installation and it will do it for you.
I will assume you installed it to C:\Program Files\Mercurial.
The second step is to obtain and install the Apache server. You may want to install it as a service. There is a nice and simple ApacheMonitor application that will put itself in your system tray and you can control your Apache from there.
I will assume you installed it to C:\Program Files\Apache Software Foundation\Apache2.2.
For the Mercurial server to work, you need to have Python installed. The Python version must correspond to the Mercurial version. For Mercurial 1.7.1 you should get Python 2.6.
Please not that you do NOT need to set a system variable called PYTHONPATH as some tutorials suggest.
I will assume you installed your Python to C:\Python26.
Downloading Mercurial source
Download Mercurial source for your Mercurial version and unpack it. If you are lazy, you don’t have to do it - all the necessary files are available on my website (see links below).
- Go to your Mercurial installation directory.
- Unpack the library.zip file contents into a folder called lib. You will have to create it yoruself. In this folder the contents of the library.zip file should reside direcly, i.e. the path to for instance zipfile.pyc should be C:\Program Files\Mercurial\lib\zipfile.pyc.
- Move the C:\Program Files\Mercurial\templates folder into the new lib folder.
Creating a projects folder
You need to create a project where Mercurial will store your projects. I will assume it’s C:\Projects\hg.
In the Apache htdocs folder put this file - hgweb.cgi. Get it from the Mercurial source. In another folder (I will assume it’s the Mercurial installation folder) put hgweb.config - just create it.
Please note those two files are also available for download from my website (see links below).
#!c:/Python26/python.exe -u # # An example hgweb CGI script, edit as necessary # See also http://mercurial.selenic.com/wiki/PublishingRepositories # Path to repo or hgweb config to serve (see 'hg help hgweb') config = "C:/Program Files/Mercurial/hgweb.config" # Uncomment and adjust if Mercurial is not installed system-wide: import sys; sys.path.insert(0, "C:/Program Files/Mercurial/lib") # Uncomment to send python tracebacks to the browser if an error occurs: import cgitb; cgitb.enable() from mercurial import demandimport; demandimport.enable() from mercurial.hgweb import hgweb, wsgicgi application = hgweb(config) wsgicgi.launch(application)
So if you got this file from the source, you need to make it look more or less like this one.
[collections] C:\Projects\hg = C:\Projects\hg [web] allow_push = * style = monoblue contact = firstname.lastname@example.org push_ssl = false
C:\Projects\hg is, again, where Mercurial will contain your projects. It allows anyone to push. It uses the monoblue style. Provide your email in the contact field. The last line makes SSL not compulsory to be able to push.
I didn't have to do this, but user Good reported he did and he found it on the editrocket.com site.
Search the httpd.conf file for the line
Options Indexes FollowSymLinksAdd ExecCGI to this line. The line should now look similar to the following (NOTE: there may be more options listed):
Options Indexes FollowSymLinks ExecCGINext, search for the following:
#AddHandler cgi-script .cgiUncomment this line by removing the # in front of the line, and add a .py to the end of the line. The new line should look like this:
AddHandler cgi-script .cgi .py
Creating a sample project
Now, for each project you will have to manually create a repository in the C:\Projects\hg folder.
Go to console, go to this folder and type hg init projectName. This will create the repository.
Launch the server and go to http://localhost/hgweb.cgi. You should now see your project listed there under projectName.
You can push and pull to http://localhost/hgweb.cgi/projectName/.
Sample hgweb.cgi (I changed the extension to .txt so that the server wouldn’t treat it as a script)