Replace some references from hg2git to hg-fast-import
[fast-export/fast-export-unix-compliant.git] / hg-fast-export.sh
blob5d5674a47b14a879f94ec8fce33b1e1c2bc2f01b
1 #!/bin/sh
3 # Copyright (c) 2007 Rocco Rutte <pdmef@gmx.net>
4 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
6 ROOT="`dirname $0`"
7 REPO=""
8 PFX="hg2git"
9 SFX_MARKS="marks"
10 SFX_HEADS="heads"
11 SFX_STATE="state"
12 QUIET=""
14 USAGE="[--quiet] [-r <repo>] [-m <max>] [-s] [-A <file>]"
15 LONG_USAGE="Import hg repository <repo> up to either tip or <max>
16 If <repo> is omitted, use last hg repository as obtained from state file,
17 GIT_DIR/$PFX-$SFX_STATE by default.
19 Note: The argument order matters.
21 Options:
22 -m Maximum revision to import
23 --quiet Passed to git-fast-import(1)
24 -s Enable parsing Signed-off-by lines
25 -A Read author map from file
26 (Same as in git-svnimport(1) and git-cvsimport(1))
27 -r Mercurial repository to import
30 . git-sh-setup
31 cd_to_toplevel
33 while case "$#" in 0) break ;; esac
35 case "$1" in
36 -r|--r|--re|--rep|--repo)
37 shift
38 REPO="$1"
40 --q|--qu|--qui|--quie|--quiet)
41 QUIET="--quiet"
43 -*)
44 # pass any other options down to hg2git.py
45 break
48 break
50 esac
51 shift
52 done
54 # for convenience: get default repo from state file
55 if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
56 REPO="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
57 echo "Using last hg repository \"$REPO\""
60 # make sure we have a marks cache
61 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
62 touch "$GIT_DIR/$PFX-$SFX_MARKS"
65 GIT_DIR="$GIT_DIR" python "$ROOT/hg-fast-export.py" \
66 --repo "$REPO" \
67 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
68 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
69 --status "$GIT_DIR/$PFX-$SFX_STATE" \
70 "$@" \
71 | git-fast-import $QUIET --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
72 || die 'Git fast-import failed'
74 # move recent marks cache out of the way...
75 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
76 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
77 else
78 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
81 # ...to create a new merged one
82 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
83 | uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
85 # cleanup
86 rm -rf "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"
88 # save SHA1s of current heads for incremental imports
89 # and connectivity (plus sanity checking)
90 for head in `git branch | sed 's#^..##'` ; do
91 id="`git-rev-parse $head`"
92 echo ":$head $id"
93 done > "$GIT_DIR/$PFX-$SFX_HEADS"
95 # check diff with color:
96 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r