Use revision directly instead of revnode
[fast-export.git] / hg-reset.sh
blob7370e342336d570bda8c7f8f2182dfff4e14c575
1 #!/bin/sh
3 # Copyright (c) 2007, 2008 Rocco Rutte <pdmef@gmx.net> and others.
4 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
6 ROOT="`dirname $0`"
7 REPO=""
8 PFX="hg2git"
9 SFX_MARKS="marks"
10 SFX_MAPPING="mapping"
11 SFX_HEADS="heads"
12 SFX_STATE="state"
13 QUIET=""
15 if [ -z "${PYTHON}" ]; then
16 # $PYTHON is not set, so we try to find a working python with mercurial:
17 for python_cmd in python2 python python3; do
18 if command -v $python_cmd > /dev/null; then
19 $python_cmd -c 'import mercurial' 2> /dev/null
20 if [ $? -eq 0 ]; then
21 PYTHON=$python_cmd
22 break
25 done
27 if [ -z "${PYTHON}" ]; then
28 echo "Could not find a python interpreter with the mercurial module available. " \
29 "Please use the 'PYTHON'environment variable to specify the interpreter to use."
30 exit 1
33 USAGE="[-r <repo>] -R <rev>"
34 LONG_USAGE="Print SHA1s of latest changes per branch up to <rev> useful
35 to reset import and restart at <rev>.
36 If <repo> is omitted, use last hg repository as obtained from state file,
37 GIT_DIR/$PFX-$SFX_STATE by default.
39 Options:
40 -R Hg revision to reset to
41 -r Mercurial repository to use
44 IS_BARE=$(git rev-parse --is-bare-repository) \
45 || (echo "Could not find git repo" ; exit 1)
46 if test "z$IS_BARE" != ztrue; then
47 # This is not a bare repo, cd to the toplevel
48 TOPLEVEL=$(git rev-parse --show-toplevel) \
49 || (echo "Could not find git repo toplevel" ; exit 1)
50 cd $TOPLEVEL || exit 1
52 GIT_DIR=$(git rev-parse --git-dir) || (echo "Could not find git repo" ; exit 1)
54 while case "$#" in 0) break ;; esac
56 case "$1" in
57 -r|--r|--re|--rep|--repo)
58 shift
59 REPO="$1"
61 -*)
62 # pass any other options down to hg2git.py
63 break
66 break
68 esac
69 shift
70 done
72 # for convenience: get default repo from state file
73 if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
74 REPO="`grep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
75 echo "Using last hg repository \"$REPO\""
78 # make sure we have a marks cache
79 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
80 touch "$GIT_DIR/$PFX-$SFX_MARKS"
83 GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-reset.py" \
84 --repo "$REPO" \
85 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
86 --mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \
87 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
88 --status "$GIT_DIR/$PFX-$SFX_STATE" \
89 "$@"
91 exit $?