Don't restore checkpoint count from cache
[fast-export/barak.git] / hg2git.sh
blobea25f9a7a0ba6b416fcb57ef87cdc2bed9ca8128
1 #!/bin/sh
3 USAGE='[-m max] repo'
4 LONG_USAGE='Import hg repository <repo> up to either tip or <max>'
5 ROOT="`dirname $0`"
6 REPO=""
7 MAX="-1"
8 PFX="hg2git"
9 SFX_MARKS="marks"
10 SFX_HEADS="heads"
11 SFX_STATE="state"
13 . git-sh-setup
14 cd_to_toplevel
16 while case "$#" in 0) break ;; esac
18 case "$1" in
19 -m)
20 shift
21 MAX="$1"
23 -*)
24 usage
27 break
29 esac
30 shift
31 done
33 if [ "$#" != 1 ] ; then
34 usage
35 exit 1
38 REPO="$1"
40 # make sure we have a marks cache
41 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
42 touch "$GIT_DIR/$PFX-$SFX_MARKS"
45 GIT_DIR="$GIT_DIR" python "$ROOT/hg2git.py" \
46 "$REPO" \
47 "$MAX" \
48 "$GIT_DIR/$PFX-$SFX_MARKS" \
49 "$GIT_DIR/$PFX-$SFX_HEADS" \
50 "$GIT_DIR/$PFX-$SFX_STATE" \
51 | git-fast-import --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
52 || die 'Git fast-import failed'
54 # move recent marks cache out of the way...
55 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
56 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
57 else
58 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
61 # ...to create a new merged one
62 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
63 | uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
65 # cleanup
66 rm -rf "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"
68 # save SHA1s of current heads for incremental imports
69 # and connectivity (plus sanity checking)
70 for head in `git branch | sed 's#^..##'` ; do
71 id="`git-rev-parse $head`"
72 echo ":$head $id"
73 done > "$GIT_DIR/$PFX-$SFX_HEADS"
75 # check diff with color:
76 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r