Skip to content

Instantly share code, notes, and snippets.

@tailhook
Created Aug 4, 2016
Embed
What would you like to do?
Mercurial sync
#!/bin/sh
WORKDIR=/tmp/repo-sync-workdir
# Read all the branches in the last 24 hours when starting to make sure we
# don't get out of sync
branches="$(hg log --template '{branch}\n' -d 'yesterday to now')"
trap "true" USR1 # This is a signal to wakeup from sleeping
echo $$ > "$WORKDIR/syncer.pid"
if [ -f "$WORKDIR/branches" ]; then
mv -f "$WORKDIR/branches" "$WORKDIR/tmpbranches"
branches="$branches $(cat $WORKDIR/tmpbranches)"
rm "$WORKDIR/tmpbranches"
fi
branches="$(echo $branches | sort -u)"
git fetch origin $branches
git push origin $branches
while true; do
if [ -f "$WORKDIR/branches" ]; then
mv -f "$WORKDIR/branches" "$WORKDIR/tmpbranches"
branches="$(cat $WORKDIR/tmpbranches | sort -u)"
rm "$WORKDIR/tmpbranches"
git fetch origin $branches
git push origin $branches
sleep 1 # Don't wakeup more frequently than every one second
else
sleep 600 # recheck in ten minutes or on signal
fi
done
#!/bin/sh
WORKDIR=/tmp/repo-sync-workdir
branch="$(hg log -r $HG_NODE -T "{branch}")"
[ -d $WORKDIR ] || mkdir $WORKDIR
echo $branch >> $WORKDIR/branches
kill -USR1 "$(cat $WORKDIR/syncer.pid)" || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment