« links for 2007-04-06 | Main | links for 2007-04-07 »

Mercurial, Part II: setting up Mercurial on TextDrive

The wonderful people at TextDrive don't support Mercurial centrally, but since Mercurial is a Python app, you can set it up locally on your account. If you're like me, you'll also want to be able to push and pull changes over HTTP for multiple repositories using the hgwebdir.cgi script. The rest of this post is a (very) terse description of how I set things up on my TXD account, based on the publishing instructions in Mercurial Wiki.

Install mercurial in your home folder:

    #mkdir ~/local; mkdir ~/local/mercurial
    # cd ~local
    # wget http://www.selenic.com/mercurial/release/mercurial-0.9.3.tar.gz 
    # tar xvzf mercurial-0.9.3.tar.gz 
    # cd  ~/local/mercurial-0.9.3
    # python setup.py install --home=~/local/mercurial
    # nano ~/.profile
    PYTHONPATH=${HOME}/local/mercurial/lib/python
    PATH=${HOME}/local/mercurial/bin:$PATH 
    #export PYTHONPATH=${HOME}/local/mercurial/lib/python
    #export PATH=${HOME}/local/mercurial/bin:$PATH 

Create a base configuration file:

    # touch ~/.hgrc
    # nano ~/.hgrc
    [ui]
    username = your name 
    

Check your setup:

    # hg debuginstall
    Checking encoding (US-ASCII)...
    Checking extensions...
    Checking templates...
    Checking patch...
    Checking merge helper...
    Checking commit editor...
    Checking username...
    No problems detected

Make a public repository area, and serve it:

# mkdir ~/web/public/hg
# mkdir ~/web/public/hg/repos

~/web/public/hg/repos is where you will create your public mercurial repositories. Note that symlinking into here doesn't work, they have to be housed. To serve it out

    # cp  ~/local/mercurial-0.9.3/hgwebdir.cgi  ~/web/public/hg
    # chmod 755 ~/web/public/hg/hgwebdir.cgi
    # nano ~/web/public/hg/hgwebdir.cgi
    import sys
    sys.path.insert(0, "/users/home/$youraccountname/local/mercurial/lib/python")

Now tell the cgi where the repos are (for example suppose we had created a repo called 'weblog'):

    # nano ~/web/public/hg/hgweb.config 
    [paths]
    weblog = repos/weblog

Create a user account for pushing changes:

    # mkdir etc
    # htpasswd -c ~/etc/hgpasswd $mercurialname

Configure apache access to the repositories:

    # nano ~/web/public/hg/.htaccess 

    Options +ExecCGI
    RewriteEngine On
    RewriteBase /hg
    RewriteRule ^$ hgwebdir.cgi  [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) hgwebdir.cgi/$1  [QSA,L]
    AuthUserFile /users/home/$youraccountname/etc/hgpasswd
    AuthGroupFile /dev/null
    AuthName "My Repository"
    AuthType Basic
    <Limit POST PUT>
    Require valid-user
    </Limit>

the above will allow anyone to browse

    http://$yourdomain/hg
and see all the repositories under:
    ~/web/public/hg/repos

The Auth* directives mean commits are restricted to authenticated users, but anyone can browse (if you want to restrict browsing add GET to the methods in <Limit>. The rewrite rules are explained in the mercurial wiki.

For each repository under repos you'll need to add the following to its .hg/hgrc file:

    [web]
    push_ssl = false
    allow_push = $mercurialname

where "$mercurialname " matches what you added to hgpasswd earlier. This isn't secure - mercurial by default does not allow push over http, with good reason, you have to disable via push_ssl. If you can get a https setup running in TextDrive, you should do so (and tell me what you did ;).

To pull a repository down via HTTP use "hg clone":

    # hg clone http://$yourdomain/hg/weblog weblog

To commit (you'll be challenged for auth details):

    # cd weblog
    do work
    # hg ci -m "my changes"
    # hg push http://$yourdomain/hg/weblog
    pushing to http://$yourdomain/hg/weblog
    searching for changes
    http authorization required
    realm: My Repository
    user: $mercurialname
    password: 
    adding changesets
    adding manifests
    adding file changes
    added 1 changesets with 1 changes to 1 files

See also: Mercurial, Part I, first impressions.

April 6, 2007 07:55 PM

Comments

(April 6, 2007 08:27 PM #)

This is great! Thanks! When you twittered that you were doing this I'd hoped you'd type it up.

Just to double check, the above setup is in-secure (unecrypted?), right? Getting SSL stuff setup at textdrive (and probably anywhere) always seems tedious.

Does hg not work over SSH?

Cote'
(April 6, 2007 08:28 PM #)

Oh, sorry: that last comment was from me. I'm always forgetting to put in my name with your username info at the bottom of these comment forms

Bill de hOra
(April 6, 2007 09:10 PM #)

ssh: It does; but I'm no good at setting it up.

Post a comment

(you may use HTML tags for style)




Remember Me?

Trackback Pings

TrackBack URL for this entry:
http://www.dehora.net/mt/mt-tb.cgi/2069