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