Add some simpe readme with legal stuff, usage and some notes
[fast-export/benizi.git] / hg2git.sh
blob46ce727b64e4e3608ff3255c9718264321bd075f
1 #!/bin/sh
3 USAGE='[-m max] [--quiet] 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"
12 QUIET=""
14 . git-sh-setup
15 cd_to_toplevel
17 while case "$#" in 0) break ;; esac
19 case "$1" in
20 -m)
21 shift
22 MAX="$1"
24 --q|--qu|--qui|--quie|--quiet)
25 QUIET="--quiet"
27 -*)
28 usage
31 break
33 esac
34 shift
35 done
37 if [ "$#" != 1 ] ; then
38 usage
39 exit 1
42 REPO="$1"
44 # make sure we have a marks cache
45 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
46 touch "$GIT_DIR/$PFX-$SFX_MARKS"
49 GIT_DIR="$GIT_DIR" python "$ROOT/hg2git.py" \
50 "$REPO" \
51 "$MAX" \
52 "$GIT_DIR/$PFX-$SFX_MARKS" \
53 "$GIT_DIR/$PFX-$SFX_HEADS" \
54 "$GIT_DIR/$PFX-$SFX_STATE" \
55 | git-fast-import $QUIET --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
56 || die 'Git fast-import failed'
58 # move recent marks cache out of the way...
59 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
60 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
61 else
62 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
65 # ...to create a new merged one
66 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
67 | uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
69 # cleanup
70 rm -rf "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"
72 # save SHA1s of current heads for incremental imports
73 # and connectivity (plus sanity checking)
74 for head in `git branch | sed 's#^..##'` ; do
75 id="`git-rev-parse $head`"
76 echo ":$head $id"
77 done > "$GIT_DIR/$PFX-$SFX_HEADS"
79 # check diff with color:
80 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r