hg2git.sh: Complete --help output's option listing
[fast-export/fast-export-unix-compliant.git] / hg2git.sh
blob3dd9d5b1380b019948147e178724c28b2d8d381c
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] [-s] [-A <file>] [-r <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 Options:
17 -m Maximum revision to import
18 --quiet Passed to git-fast-import(1)
19 -s Enable parsing Signed-off-by lines
20 -A Read author map from file
21 (Same as in git-svnimport(1) and git-cvsimport(1))
22 -r Mercurial repository to import
25 . git-sh-setup
26 cd_to_toplevel
28 while case "$#" in 0) break ;; esac
30 case "$1" in
31 -r|--r|--re|--rep|--repo)
32 shift
33 REPO="$1"
35 --q|--qu|--qui|--quie|--quiet)
36 QUIET="--quiet"
38 -*)
39 # pass any other options down to hg2git.py
40 break
43 break
45 esac
46 shift
47 done
49 # for convenience: get default repo from state file
50 if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
51 REPO="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
52 echo "Using last hg repository \"$REPO\""
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 "$REPO" \
62 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
63 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
64 --status "$GIT_DIR/$PFX-$SFX_STATE" \
65 "$@" \
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