3 # Copyright (c) 2007, 2008 Rocco Rutte <pdmef@gmx.net> and others.
4 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
13 PYTHON
=${PYTHON:-python}
15 USAGE
="[--quiet] [-r <repo>] [-m <max>] [-s] [-A <file>] [-M <branch_name>]"
16 LONG_USAGE
="Import hg repository <repo> up to either tip or <max>
17 If <repo> is omitted, use last hg repository as obtained from state file,
18 GIT_DIR/$PFX-$SFX_STATE by default.
20 Note: The argument order matters.
23 -m Maximum revision to import
24 --quiet Passed to git-fast-import(1)
25 -s Enable parsing Signed-off-by lines
26 -A Read author map from file
27 (Same as in git-svnimport(1) and git-cvsimport(1))
28 -r Mercurial repository to import
29 -M Set the default branch name
32 .
"$(git --exec-path)/git-sh-setup"
35 while case "$#" in 0) break ;; esac
38 -r|
--r|
--re|
--rep|
--repo)
42 --q|
--qu|
--qui|
--quie|
--quiet)
46 # pass any other options down to hg2git.py
56 # for convenience: get default repo from state file
57 if [ x
"$REPO" = x
-a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
58 REPO
="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
59 echo "Using last hg repository \"$REPO\""
62 # make sure we have a marks cache
63 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
64 touch "$GIT_DIR/$PFX-$SFX_MARKS"
67 GIT_DIR
="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
69 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
70 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
71 --status "$GIT_DIR/$PFX-$SFX_STATE" \
73 | git fast-import
$QUIET --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
74 || die
'Git fast-import failed'
76 # move recent marks cache out of the way...
77 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
78 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
80 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
83 # ...to create a new merged one
84 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
85 |
uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
88 rm -rf "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"
90 # save SHA1s of current heads for incremental imports
91 # and connectivity (plus sanity checking)
92 for head in `git branch | sed 's#^..##'` ; do
93 id
="`git rev-parse $head`"
95 done > "$GIT_DIR/$PFX-$SFX_HEADS"
97 # check diff with color:
98 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r