Differences between revisions 6 and 7
Revision 6 as of 2005-09-18 17:16:20
Size: 3186
Comment:
Revision 7 as of 2005-09-18 17:31:42
Size: 3202
Comment:
Deletions are marked like this. Additions are marked like this.
Line 8: Line 8:
== Create a user for the repository. == == Create a user and setup a repository ==
Line 10: Line 10:
This is not strictly necessary, but it will make it easier to update the repository remotely.
Create a user {{{hg}}} and setup a repository in {{{/home/hg/repo-name}}}:
Line 17: Line 16:
}}}
This will create a repository in {{{/home/hg/repo-name}}}. If you create a directory {{{/home/hg/.ssh}}} and set up its {{{authorized_keys}}} file appropriately, you will be able to remotely update the repository via the command
{{{
$ hg push ssh://hg@example.org/repo-name
Line 31: Line 26:
Not strictly necessary, but if you want to allow remote updates to your
repository, you can create a directory {{{/home/hg/.ssh}}} and set up
its {{{authorized_keys}}} file appropriately. You will be able to remotely
update the repository via the command:
{{{
$ hg push ssh://hg@example.org/repo-name
}}}
Line 32: Line 34:
== Setup the cgi script to refer to your repository ==
== Setup a cgi script to refer to your repository ==
Line 36: Line 39:
mercurial sources to {{{/var/www/cgi-hg/index.cgi}}} and change the call to hgweb.hgweb() so that the
first argument lists the path to the repository and the second argument gives the name of the repository.  
mercurial sources to {{{/var/www/cgi-hg/index.cgi}}} and change the call to {{{hgweb.hgweb()}}} so that the
first argument lists the path to the repository and the second argument gives the name of the repository.

Setting up a Mercurial CGI Server

If you would like to publish your repository to the world, it must be made available via a web server. ["Mercurial"] does have a built-in web server which can be used for this, which can be accessed via hg serve. However, it will only allow one connection at a time, and it is not very robust; a broken connection at the wrong time can cause the hg serve to exit. A much better way to do things is to access Mercurial from a CGI script using an Apache web server.

The following example shows you one way of doing making a repository named repo-name available on the host example.org

Create a user and setup a repository

Create a user hg and setup a repository in /home/hg/repo-name:

# adduser hg
# su - hg
$ mkdir /home/hg/repo-name; cd /home/hg/repo-name
$ hg init

You should add a bit of information about your hg repository by making sure the following lines in the config file repo-name/.hg/hgrc are set:

[web]
description = short description of repo-name
author = Example User <hg@example.com>

Not strictly necessary, but if you want to allow remote updates to your repository, you can create a directory /home/hg/.ssh and set up its authorized_keys file appropriately. You will be able to remotely update the repository via the command:

$ hg push ssh://hg@example.org/repo-name

Setup a cgi script to refer to your repository

Most people adding new content to the repository don't need to change the cgi script, so keeping that separate (maybe even protected by root permissions) is best. Copy the hgweb.cgi script from the mercurial sources to /var/www/cgi-hg/index.cgi and change the call to hgweb.hgweb() so that the first argument lists the path to the repository and the second argument gives the name of the repository.

Using the example names as used above, the index.cgi file might look like this:

import cgitb, os, sys
cgitb.enable()

# sys.path.insert(0, "/path/to/python/lib") # if not a system-wide install
from mercurial import hgweb

h = hgweb.hgweb("/home/hg/repo-name", "name of repository")
h.run()

Make sure the index.cgi file is executable:

$ chmod a+x index.cgi

Edit your apache configuration file

Place the following in your apache configuration file and reload the apache server so that the configuration changes take effect:

Alias /hg /var/www/cgi-hg
<Directory "/var/www/cgi-hg">
    DirectoryIndex index.cgi
    AddHandler cgi-script .cgi
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>

In case you also want to make the repository available as static html files (which should normally not be necessary), you could add:

Alias /hg-static /home/hg/repo-name
<Directory "/home/hg/repo-name">
    Options Indexes
    Order allow,deny
    Allow from all
</Directory>

That's it!

Once you have populated the repository, users will be able to access the repositry using the URL: http://example.org/hg/.

CGIinstall (last edited 2009-11-30 17:50:03 by PaulBoddie)