hg2git.sh: Try to get last hg repo url from state file
[fast-export/barak.git] / hg2git.sh
blob5de327088b17c77054eb72f4aff598c47d57f7eb
1 #!/bin/sh
3 ROOT="`dirname $0`"
4 REPO=""
5 MAX="-1"
6 PFX="hg2git"
7 SFX_MARKS="marks"
8 SFX_HEADS="heads"
9 SFX_STATE="state"
10 QUIET=""
12 USAGE="[-m <max>] [--quiet] [<repo>]"
13 LONG_USAGE="Import hg repository <repo> up to either tip or <max>
14 If <repo> is omitted, use last hg repository as obtained from state file,
15 GIT_DIR/$PFX-$SFX_STATE by default."
17 . git-sh-setup
18 cd_to_toplevel
20 while case "$#" in 0) break ;; esac
22 case "$1" in
23 -m)
24 shift
25 MAX="$1"
27 --q|--qu|--qui|--quie|--quiet)
28 QUIET="--quiet"
30 -*)
31 usage
34 break
36 esac
37 shift
38 done
40 # for convenience: get default repo from state file
41 if [ "$#" != 1 -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
42 REPO="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
43 echo "Using last hg repository \"$REPO\""
46 if [ x"$REPO" = x ] ; then
47 if [ "$#" != 1 ] ; then
48 usage
49 exit 1
50 else
51 REPO="$1"
55 # make sure we have a marks cache
56 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
57 touch "$GIT_DIR/$PFX-$SFX_MARKS"
60 GIT_DIR="$GIT_DIR" python "$ROOT/hg2git.py" \
61 "$REPO" \
62 "$MAX" \
63 "$GIT_DIR/$PFX-$SFX_MARKS" \
64 "$GIT_DIR/$PFX-$SFX_HEADS" \
65 "$GIT_DIR/$PFX-$SFX_STATE" \
66 | git-fast-import $QUIET --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
67 || die 'Git fast-import failed'
69 # move recent marks cache out of the way...
70 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
71 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
72 else
73 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
76 # ...to create a new merged one
77 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
78 | uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
80 # cleanup
81 rm -rf "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"
83 # save SHA1s of current heads for incremental imports
84 # and connectivity (plus sanity checking)
85 for head in `git branch | sed 's#^..##'` ; do
86 id="`git-rev-parse $head`"
87 echo ":$head $id"
88 done > "$GIT_DIR/$PFX-$SFX_HEADS"
90 # check diff with color:
91 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r