hg2git.py: Only print verification message for branches we have
[fast-export/rorcz.git] / hg2git.sh
blob8bd96f42ca40db8c7ab62bd13ebb48162b3bc921
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="[--quiet] [-r <repo>] [-m <max>] [-s] [-A <file>]"
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 Note: The argument order matters.
18 Options:
19 -m Maximum revision to import
20 --quiet Passed to git-fast-import(1)
21 -s Enable parsing Signed-off-by lines
22 -A Read author map from file
23 (Same as in git-svnimport(1) and git-cvsimport(1))
24 -r Mercurial repository to import
27 . git-sh-setup
28 cd_to_toplevel
30 while case "$#" in 0) break ;; esac
32 case "$1" in
33 -r|--r|--re|--rep|--repo)
34 shift
35 REPO="$1"
37 --q|--qu|--qui|--quie|--quiet)
38 QUIET="--quiet"
40 -*)
41 # pass any other options down to hg2git.py
42 break
45 break
47 esac
48 shift
49 done
51 # for convenience: get default repo from state file
52 if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
53 REPO="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
54 echo "Using last hg repository \"$REPO\""
57 # make sure we have a marks cache
58 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
59 touch "$GIT_DIR/$PFX-$SFX_MARKS"
62 GIT_DIR="$GIT_DIR" python "$ROOT/hg2git.py" \
63 --repo "$REPO" \
64 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
65 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
66 --status "$GIT_DIR/$PFX-$SFX_STATE" \
67 "$@" \
68 | git-fast-import $QUIET --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
69 || die 'Git fast-import failed'
71 # move recent marks cache out of the way...
72 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
73 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
74 else
75 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
78 # ...to create a new merged one
79 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
80 | uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
82 # cleanup
83 rm -rf "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"
85 # save SHA1s of current heads for incremental imports
86 # and connectivity (plus sanity checking)
87 for head in `git branch | sed 's#^..##'` ; do
88 id="`git-rev-parse $head`"
89 echo ":$head $id"
90 done > "$GIT_DIR/$PFX-$SFX_HEADS"
92 # check diff with color:
93 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r