mirroring repositories
PATCH 1/1 mirroring repositories
The attached patch adds the two programs cg-mirror-add and cg-mirror-sync. Say you do all of your work on your laptop and you want to make a mirror of your repository available to the public. You specify the location of the mirror with cg-mirror-add:
$ cg-mirror-add scp://my.server:/var/www/repos/project.git
which locally creates the file .git/mirrors. Whenever you want to upload your changes, you run cg-mirror-sync.
Michael
cg-mirror-add +22 -0
@@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# Add new mirror to the GIT repository. +# Copyright (c) Michael Frank, 2005 +# +# Takes the mirror location as parameter. Location can be +# an rsync URI, as in: +# $ cg-mirror add rsync://your.server:/path/to/project.git +# +# or an scp URI (rsync is still used to copy the files): +# $ cg-mirror add scp://[email protected]:/project/path.git +# + +. ${COGITO_LIB}cg-Xlib + +location=$1 + +([ "$location" ]) || die "usage: cg-mirror-add MIRROR_LOC" +if [ -e $_git/mirrors ]; then + grep -xq $location $_git/mirrors && die "mirror already exists" +fi +echo "$location" >> $_git/mirrors
cg-mirror-sync +25 -0
@@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# +# Pushes changes from the local GIT repository to mirrors. +# Copyright (c) Michael Frank, 2005 +# + +. ${COGITO_LIB}cg-Xlib + +[ -r $_git/mirrors ] || die "No mirrors to sync!" + +uri= +for mirror in `cat $_git/mirrors`; do + if echo $mirror | grep -q "^scp://"; then + uri=`echo $mirror | sed -e "s/^scp:\/\///"` + echo "syncing $mirror ..." + rsync -a -v -z --exclude=mirrors $_git/* $uri + echo "" + elif echo $mirror | grep -q "^rsync://"; then + echo "syncing $mirror ..." + rsync -a -v -z --exclude=mirrors $_git/* $mirror + echo "" + else + echo "skipping $mirror; mirror uses unknown transport" + fi +done
Makefile +2 -1
@@ -55,7 +55,8 @@ PROG= git-update-cache git-diff-files SCRIPT= commit-id tree-id parent-id cg-add cg-admin-lsobj cg-admin-uncommit \ cg-branch-add cg-branch-ls cg-cancel cg-clone cg-commit cg-diff \ cg-export cg-help cg-init cg-log cg-ls cg-merge cg-mkpatch cg-patch \ - cg-pull cg-restore cg-rm cg-seek cg-status cg-tag cg-tag-ls cg-update + cg-pull cg-restore cg-rm cg-seek cg-status cg-tag cg-tag-ls cg-update \ + cg-mirror-add cg-mirror-sync LIB_SCRIPT=cg-Xlib cg-Xdiffdo cg-Xmergefile
Dear diary, on Sun, May 29, 2005 at 11:41:23PM CEST, I got a letter where Michael Frank <[email protected]> told me that...
Quoted 9 lines
The attached patch adds the two programs cg-mirror-add and cg-mirror-sync. Say you do all of your work on your laptop and you want to make a mirror of your repository available to the public. You specify the location of the mirror with cg-mirror-add:
$ cg-mirror-add scp://my.server:/var/www/repos/project.gitwhich locally creates the file .git/mirrors. Whenever you want to upload your changes, you run cg-mirror-sync.
FWIW, I think this is the wrong approach - full-blown pushing makes much more sense since it's a full superset of mirroring and it's more universal, and not *that* more complicated to do (basically just the HEAD stuff - and I think the race conditions around that don't matter that much in the real life if you take some basic crude protections).
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor