Skip to content

Instantly share code, notes, and snippets.

@jsoriano
Created December 30, 2013 09:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jsoriano/8179957 to your computer and use it in GitHub Desktop.
Save jsoriano/8179957 to your computer and use it in GitHub Desktop.
Uses hg convert to truncate a repository from an initial revision. If no revision is specified, the whole repository is converted. It optionally uses an intermediate repository (cache) in case the source repository can be written during the convert operation.
#!/bin/bash
#
# Uses hg convert to strip a repository from <start revision>
# If no revision is specified, the whole repository is converted.
# Optionally a "cache" repository can be used, to be sure that the
# source repository is not written during the convert operation.
#
while getopts "r:s:d:c:h?" opt; do
case $opt in
r)
REVISION=$OPTARG
;;
s)
SOURCE=$OPTARG
;;
d)
DESTINATION=$OPTARG
;;
c)
CACHE=$OPTARG
;;
*)
echo "Usage: $0 -s <source> -d <destination> [-r <start revision>] [-c <cache>]"
exit 1
;;
esac
done
if test -z "$SOURCE" -o -z "$DESTINATION"; then
echo "You must specify source and destination"
exit 1
fi
if [ ! -d "$SOURCE/.hg" ]; then
echo "$SOURCE is not a mercurial repository"
exit 1
fi
if [ -n "$REVISION" ]; then
HG_CONFIG="--config convert.hg.startrev=$REVISION"
fi
if [ -n "$CACHE" ]; then
if [ -d "$CACHE/.hg" ]; then
hg -R $CACHE pull $SOURCE
else
hg clone -U $SOURCE $CACHE
fi
REAL_SOURCE=$CACHE
else
REAL_SOURCE=$SOURCE
fi
hg $HG_CONFIG convert $REAL_SOURCE $DESTINATION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment