hg2git.py: Display our max revision as progress, not tip
[fast-export/barak.git] / hg2git.sh
blob34d5227bdf9f289f0691b0542b22c765d6be1d81
1 #!/bin/sh
3 ROOT="`dirname $0`"
4 REPO=""
5 PFX="hg2git"
6 SFX_MARKS="marks"
7 SFX_HEADS="heads"
8 SFX_STATE="state"
9 QUIET=""
11 USAGE="[-m <max>] [--quiet] [<repo>]"
12 LONG_USAGE="Import hg repository <repo> up to either tip or <max>
13 If <repo> is omitted, use last hg repository as obtained from state file,
14 GIT_DIR/$PFX-$SFX_STATE by default."
16 . git-sh-setup
17 cd_to_toplevel
19 while case "$#" in 0) break ;; esac
21 case "$1" in
22 -r|--r|--re|--rep|--repo)
23 shift
24 REPO="$1"
26 --q|--qu|--qui|--quie|--quiet)
27 QUIET="--quiet"
29 -*)
30 # pass any other options down to hg2git.py
31 break
34 break
36 esac
37 shift
38 done
40 # for convenience: get default repo from state file
41 if [ x"$REPO" = x -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 # make sure we have a marks cache
47 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
48 touch "$GIT_DIR/$PFX-$SFX_MARKS"
51 GIT_DIR="$GIT_DIR" python "$ROOT/hg2git.py" \
52 --repo "$REPO" \
53 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
54 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
55 --status "$GIT_DIR/$PFX-$SFX_STATE" \
56 "$@" \
57 | git-fast-import $QUIET --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
58 || die 'Git fast-import failed'
60 # move recent marks cache out of the way...
61 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
62 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
63 else
64 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
67 # ...to create a new merged one
68 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
69 | uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
71 # cleanup
72 rm -rf "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"
74 # save SHA1s of current heads for incremental imports
75 # and connectivity (plus sanity checking)
76 for head in `git branch | sed 's#^..##'` ; do
77 id="`git-rev-parse $head`"
78 echo ":$head $id"
79 done > "$GIT_DIR/$PFX-$SFX_HEADS"
81 # check diff with color:
82 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r