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>] [--force] [-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')
32 --force Ignore validation errors when converting, and pass --force
36 .
"$(git --exec-path)/git-sh-setup"
39 while case "$#" in 0) break ;; esac
42 -r|
--r|
--re|
--rep|
--repo)
46 --q|
--qu|
--qui|
--quie|
--quiet)
47 GFI_OPTS
="$GFI_OPTS --quiet"
50 # pass --force to git-fast-import and hg-fast-export.py
51 GFI_OPTS
="$GFI_OPTS --force"
55 # pass any other options down to hg2git.py
65 # for convenience: get default repo from state file
66 if [ x
"$REPO" = x
-a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
67 REPO
="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
68 echo "Using last hg repository \"$REPO\""
71 if [ -z "$REPO" ]; then
72 echo "no repo given, use -r flag"
76 # make sure we have a marks cache
77 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
78 touch "$GIT_DIR/$PFX-$SFX_MARKS"
82 trap 'rm -f "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"' 0
87 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
89 exec 4>&3 3>&1 1>&4 4>&-
92 GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
94 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
95 --mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \
96 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
97 --status "$GIT_DIR/$PFX-$SFX_STATE" \
103 git fast-import $GFI_OPTS --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" 3>&- || _e2=$?
109 [ "$_err1" = 0 -a "$_err2" = 0 ] ||
exit 1
111 # move recent marks cache out of the way...
112 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
113 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
115 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
118 # ...to create a new merged one
119 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
120 |
uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
122 # save SHA1s of current heads for incremental imports
123 # and connectivity (plus sanity checking)
124 for head in `git branch | sed 's#^..##'` ; do
125 id
="`git rev-parse $head`"
127 done > "$GIT_DIR/$PFX-$SFX_HEADS"
129 # check diff with color:
130 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r