3 # Copyright (c) 2007 Rocco Rutte <pdmef@gmx.net>
4 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
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.
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
33 while case "$#" in 0) break ;; esac
36 -r|
--r|
--re|
--rep|
--repo)
40 --q|
--qu|
--qui|
--quie|
--quiet)
44 # pass any other options down to hg2git.py
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" \
67 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
68 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
69 --status "$GIT_DIR/$PFX-$SFX_STATE" \
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"
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"
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`"
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