chris@1544: #!/bin/sh chris@1544: chris@1544: # Copyright (c) 2007, 2008 Rocco Rutte and others. chris@1544: # License: MIT chris@1544: chris@1544: ROOT="`dirname $0`" chris@1544: REPO="" chris@1544: PFX="hg2git" chris@1544: SFX_MARKS="marks" chris@1544: SFX_MAPPING="mapping" chris@1544: SFX_HEADS="heads" chris@1544: SFX_STATE="state" chris@1544: QUIET="" chris@1544: PYTHON=${PYTHON:-python} chris@1544: chris@1544: USAGE="[-r ] -R " chris@1544: LONG_USAGE="Print SHA1s of latest changes per branch up to useful chris@1544: to reset import and restart at . chris@1544: If is omitted, use last hg repository as obtained from state file, chris@1544: GIT_DIR/$PFX-$SFX_STATE by default. chris@1544: chris@1544: Options: chris@1544: -R Hg revision to reset to chris@1544: -r Mercurial repository to use chris@1544: " chris@1544: Chris@1567: IS_BARE=$(git rev-parse --is-bare-repository) \ Chris@1567: || (echo "Could not find git repo" ; exit 1) Chris@1567: if test "z$IS_BARE" != ztrue; then Chris@1567: # This is not a bare repo, cd to the toplevel Chris@1567: TOPLEVEL=$(git rev-parse --show-toplevel) \ Chris@1567: || (echo "Could not find git repo toplevel" ; exit 1) Chris@1567: cd $TOPLEVEL || exit 1 Chris@1567: fi Chris@1567: GIT_DIR=$(git rev-parse --git-dir) || (echo "Could not find git repo" ; exit 1) chris@1544: chris@1544: while case "$#" in 0) break ;; esac chris@1544: do chris@1544: case "$1" in chris@1544: -r|--r|--re|--rep|--repo) chris@1544: shift chris@1544: REPO="$1" chris@1544: ;; chris@1544: -*) chris@1544: # pass any other options down to hg2git.py chris@1544: break chris@1544: ;; chris@1544: *) chris@1544: break chris@1544: ;; chris@1544: esac chris@1544: shift chris@1544: done chris@1544: chris@1544: # for convenience: get default repo from state file chris@1544: if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then chris@1544: REPO="`grep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`" chris@1544: echo "Using last hg repository \"$REPO\"" chris@1544: fi chris@1544: chris@1544: # make sure we have a marks cache chris@1544: if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then chris@1544: touch "$GIT_DIR/$PFX-$SFX_MARKS" chris@1544: fi chris@1544: chris@1544: GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-reset.py" \ chris@1544: --repo "$REPO" \ chris@1544: --marks "$GIT_DIR/$PFX-$SFX_MARKS" \ chris@1544: --mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \ chris@1544: --heads "$GIT_DIR/$PFX-$SFX_HEADS" \ chris@1544: --status "$GIT_DIR/$PFX-$SFX_STATE" \ chris@1544: "$@" chris@1544: chris@1544: exit $?