Skip to content

Instantly share code, notes, and snippets.

@tailhook
Created August 4, 2016 10:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tailhook/702005e1765ef3f749dd4a95422fbc95 to your computer and use it in GitHub Desktop.
Save tailhook/702005e1765ef3f749dd4a95422fbc95 to your computer and use it in GitHub Desktop.
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