Mercurial

From DreamHost

Jump to: navigation, search
The instructions provided in this article or section are considered advanced.

You are expected to be knowledgeable in the UNIX shell.
Support for these instructions is not available from DreamHost tech support.
Server changes may cause this to break. Be prepared to troubleshoot this yourself if this happens.
We seriously aren't kidding about this. Read the blinky part again.

The instructions provided in this article or section require shell access unless otherwise stated.

You can use the PuTTY client on Windows, or SSH on UNIX and UNIX-like systems such as Linux or Mac OS X.
Your account must be configured for shell access in the Control Panel.
More information may be available on the article's talk page.


Mercurial (official site) is a distributed version control system that is used track revisions of your files. You can find the unofficial manual here: (Distributed Revision Control with Mercurial).

Mercurial isn't currently installed by DreamHost (actually it appears that an old version 0.9.x is installed). This page will document how to install the latest version of Mercurial in your home account and get the webserver up and running. This is a work in progress.

Contents

How To Install Mercurial

  • Note: These instructions assume everything works with no problems. If you have any issues, please make a note and we can try and get them fixed.
  • Login to the shell account you would like to install Mercurial in
  • Download the latest Mercurial package (1.3.1 as of 2-Aug-2009), (check latest here: http://mercurial.selenic.com/wiki/Download)
mkdir -p ~/srcs
cd ~/srcs
wget http://mercurial.selenic.com/release/mercurial-1.3.1.tar.gz
  • gunzip and untar the package
tar xvzf mercurial-1.3.1.tar.gz
  • Change directory to mercurial-1.3.1
cd mercurial-1.3.1
  • Run the make all command
make all
  • Install the Mercurial package in your home directory. It will create bin, lib, and share directory in your home directory to install
make install-home
  • Assuming your are using bash shell, you need to update your PATH and PYTHONPATH environment variables to call this new local installation of mercurial instead of the old default version already installed on the system. You can do this by adding the updated env variables to your .bash_profile:
vi ~/.bash_profile
  • add these lines at the bottom:
export PYTHONPATH=~/lib/python
export PATH=~/bin:$PATH
  • Now, do the same thing to your .bashrc (create one if it's not there already). Most methods of working with your repositories remotely issue non-interactive shells, and the .bash_profile will never be read. In general, this is likely to cause errors when mercurial attempts to run using the wrong set of python libraries. If the remote mercurial repository is running on the wrong python libraries, you will receive the somewhat unhelpful error
remote: abort: index 00changelog.i invalid format 2!
  • update this shell process with the new variables:
source ~/.bash_profile
  • Run the command hg --version and you should get the version information and copyright. Check that this version is the same as the version of the tar file you initially downloaded
hg --version
  • You may get an error message - *** failed to import extension hgext/hbisect: No module named demandload. This is due to the older installation specifying an extension called hbisect, which is no longer necessary. As you can't edit the system-wide configuration you can do the following:
mkdir ~/.hgext
touch ~/.hgext/dummy.py
echo -e "[extensions]\nhgext/hbisect=~/.hgext/dummy.py" >> ~/.hgrc

How to Configure a DreamHost Account to Serve a Mercurial Repository

  • Note: These instructions are based on the instructions listed here ([1])
  • Login to your shell account
  • There needs to be a directory where the repository can be stored
mkdir -p ~/hg/repos
  • Create the file hgweb.config
vi ~/hg/hgweb.config
  • ...and add the following lines:
[collections]
repos/ = repos/
[web]
style = gitweb
  • Copy the hgwebdir.cgi script to the hg directory
cp ~/srcs/mercurial-1.3.1/hgwebdir.cgi ~/hg
chmod +x ~/hg/hgwebdir.cgi
  • Open the hgwebdir.cgi and update the sys path
vi ~/hg/hgwebdir.cgi
Change the following two lines:
 #import sys
 #sys.path.insert(0, "/path/to/python/lib")
to:
 import sys
 sys.path.insert(0, "/home/<user_name>/lib/python")
<user_name> is your shell login name
  • Create a .htaccess file for the hg directory (Taken from [2])
vi ~/hg/.htaccess
  • ...add the following lines (Comments optional) and then save the file
# Taken from http://www.pmwiki.org/wiki/Cookbook/CleanUrls#samedir
# Used at http://ggap.sf.net/hg/
Options +ExecCGI
RewriteEngine On
#write base depending on where the base url lives
RewriteBase /hg
RewriteRule ^$ hgwebdir.cgi  [L]
# Send requests for files that exist to those files.
RewriteCond %{REQUEST_FILENAME} !-f
# Send requests for directories that exist to those directories.
RewriteCond %{REQUEST_FILENAME} !-d
# Send requests to hgwebdir.cgi, appending the rest of url.
RewriteRule (.*) hgwebdir.cgi/$1  [QSA,L]
  • Create a symbolic link to the hg directory in your domain
cd to your domain directory
ln -s ~/hg
  • Test the directory - http://<your-domain.com>/hg
    • You should see a web page that says "Mercurial Repositories"

Create a New Repository

  • Login to your shell account
  • Create a repository called my_first_repo
hg init ~/hg/repos/my_first_repo
  • Create a hgrc file for the repository
vi ~/hg/repos/my_first_repo/.hg/hgrc
  • ...add the following lines to this file
[web]
contact = <Your Name>
description = My first Mercurial Repository
push_ssl = false
  • Test your repository on DreamHost. First, make a file in your repository.
cd ~/hg/repos/my_first_repo
date >> my_first_file
hg add
hg commit -m "Added my_first_file to the repository"

On your home system, try to clone your repository.

hg clone http://<your-domain>/hg/my_first_repo local_repo_copy
cat local_repo_copy/my_first_file
  • By default, no one is allowed to push your repository. Read the next section, and review the Mercurial documentation on publishing repositories.

Securing your Repositories

  • Login to your shell account
  • Add this to the .htaccess file for the hg directory
AuthUserFile /home/<username>/hg/hgweb.passwd
AuthGroupFile /dev/null
AuthName "My Mercurial Repository"
AuthType Basic
    <Limit GET POST PUT> # Remove GET to allow anonymous read-only access
        Require valid-user
    </Limit>
  • Create hgweb.passwd
htpasswd -c -m ~/hg/hgweb.passwd <username>
  • Set up user names in the repo hgrc
vi ~/hg/repos/my_first_repo/.hg/hgrc
  • ...add the following line:
allow_push = <comma-delimited username list>
  • "Trick" Mercurial into asking for authentication:
touch ~/hg/failed_auth.html
  • You can avoid having to type in your user name and password each time by providing it when you clone the repository locally. If you did not clone the repository with a user name and password you can also update the .hg/hgrc of a local repository by updating the [paths] section.
hg clone http://<user>:<password>@<your-domain.com>/hg <localdir>

How to Configure a Dedicated Subdomain with Cleaner URLS

This step can be done after the previously listed steps, and should be done after having verified all other aspects are working

If your domain directory is one you have made explicitly for serving mercurial at the root level (e.g. something like http://hg.domain.com/some_repo), then you can do this by simply moving the .htaccess to your root public web directory (since it will rewrite to /hg/hgwebdir.cgi from root level, which is valid due to the ~/hg symlink):

cd to your domain directory
mv ~/hg/.htaccess ./
  • Now we make some modifications in hgwebdir.cgi:
vi ~/hg/hgwebdir.cgi
  • Modify the following lines to override the script name (here I have given it a blank name so that nothing extra is prepended in links)
>Change this:
 #import os
>to:
 import os
 # Force script name - needs webserver rewrite support
 os.environ["SCRIPT_NAME"] = ""
  • Now you should be able to navigate projects with a format like http://hg.domain.com/some_repo instead of the existing format: http://hg.domain.com/hg/hgwebdir.cgi/some_repo
Personal tools