Created
December 30, 2013 09:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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