3 # Copyright (c) 2007, 2008 Rocco Rutte <pdmef@gmx.net> and others.
4 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
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
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."
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.
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
57 -r|
--r|
--re|
--rep|
--repo)
62 # pass any other options down to hg2git.py
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" \
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" \