evan.musing << current

life and tech stuff by Evan Phoenix

Maintaining an svn mirror directly from git

with 3 comments

When rubinius switched to git recently, we wanted the ability to keep a read-only svn repo running that had the same changes in it. This would let casual people who don’t wish to use git to at least check out the latest code easily. So with some jiggering, I came up with the follow recipe.

1) Setup tailor

Tailor is a python program with is used to translate changes in one version control system into another. It does this by using the native tools for the systems and working copy of code. When there is a change, it simple updates the working copy from the source, then checks them into the target. It’s basically a brute force way, but works quite well.

I use the following tailor config file for rubinius:


[DEFAULT]
verbose = True

[rbx]
target = svn:target
start-revision = c6f4d90df72b103884fa5470a433f5513d2c524d
root-directory = /home/evan/work/tailor/output
state-file = tailor.state
source = git:source
subdir = .

[git:source]
repository = /var/cache/git/code

[svn:target]
module = /rubinius/trunk
repository = file:///home/evan/work/rbx-git-tailor

  • start-revision was about 10 commits back from HEAD at the time I did the import. I did this so I didn’t have to wait for tailor to replay all of the commits in git, but still included the last 10. Moving forward, it does all commits.
  • root-directory is the working copy directory tailor uses to pull in and commit changes. Make sure it’s an empty directory.
  • /var/cache/git/code is a bare git repo, so be sure that repository points to a bare git. In fact, most people will tell you to only use a bare git repo (not one that also contains a working copy) on servers which you push to. push does not update the working copy and it can get quite confusing otherwise.
  • The svn target repository should a path that doesn’t exist. Tailor will create the repo the first time it runs. Do NOT point it at an existing one!

2) Git hook

Next, I used the post-update hook in git to automatically run tailor. Heres my post-update hook currently:


echo ""
echo "Updating http://git.rubini.us/svn for the less git inclined"

lockfile -1 ~/tailor.lock

/usr/bin/tailor -c /home/evan/work/tailor/config > ~/tailor.log

sudo -u evan /bin/kill -USR2 `cat /home/evan/work/matzbot/matzbot.pid` > /dev/null 2>&1 || true

rm -f ~/tailor.lock

exec git-update-server-info

The output of the post-update hook goes to the client doing the push, so the echo’s are for the git developers benefit (they’ll probably wonder why their commit pauses at the end if git is sooooo fast otherwise).

I use the lockfile program so that 2 commits don’t try and run tailor at the same time. I don’t know what would happen and personally don’t want to know. Better safe than sorry.

The kill -USR2 tells an irc bot we run in #rubinius that there are new commits to show people. Thats available in git.

Caveats

I have all my git developers pushing via ssh, all as the git user, ie git clone git@git.rubini.us/code. This means the post-update hook is run as the git user. So while the tailor working copy is in my home directory, I’ve chgrp it to git and run chmod g+r -R so the git user can properly use it.

I have the ouput from running tailor redirected into a file, so I can monitor it. So far, the only problem I’ve had with this is that my git user didn’t have a name in /etc/passwd, so git complained about not being able to properly form the author field.

This is read only. Do NOT let people check directly into the svn repo tailor is updating.

Written by evanphx

August 17, 2007 at 1:11 pm

Posted in git, rubinius

3 Responses to 'Maintaining an svn mirror directly from git'

Subscribe to comments with RSS

  1. Could you Rubinius developers fill out the Git survey [1] please? The official announcement is in [2]. Thank you.

    [1] http://www.survey.net.nz/survey.php?94e135ff41e871a1ea5bcda3ee1856d9
    [2] http://article.gmane.org/gmane.comp.version-control.git/56116

    pclouds

    18 Aug 07 at 5:13 pm

  2. thanks for the GREAT post! Very useful…

    Whatever-ishere

    21 Nov 07 at 9:07 am

  3. The post looks promising but unfortunately doesn’t meet my needs, and the Tailor documentation is lacking… I’d like to commit my local Git repository to an external Subversion repository, yet I can’t find out how to. Any help would be appreciated ;)
    (Yes I’m following comments on this post :) )

    Vincent

    4 Mar 08 at 2:21 pm

Leave a Reply