3 # Copyright (c) 2007, 2008 Rocco Rutte <pdmef@gmx.net> and others.
4 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
6 ROOT
="$(cd "$
(dirname "$0")" && pwd -P)"
14 PYTHON
=${PYTHON:-python}
16 USAGE
="[--quiet] [-r <repo>] [--force] [-m <max>] [-s] [--hgtags] [--flatten] [-A <file>] [-U <addr>] [-M <name>] [-o <name>] [--hg-hash]"
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 --quiet Passed to git-fast-import(1)
25 -r <repo> Mercurial repository to import
26 --force Ignore validation errors when converting, and pass --force
28 -m <max> Maximum revision to import
29 -s Enable parsing Signed-off-by lines
30 --hgtags Enable exporting .hgtags files
31 --flatten Create one-level ref names (convert '/' to '_')
32 -A <file> Read author map from file
33 (Same as in git-svnimport(1) and git-cvsimport(1))
34 -U <addr> Use <addr> as unknown email instead of 'unknown'
35 (previous default was 'devnull@localhost')
36 -M <name> Set the default branch name (defaults to 'master')
37 -o <name> Use <name> as branch namespace to track upstream (eg 'origin')
38 --hg-hash Annotate commits with the hg hash as git notes in the
43 echo "usage: $(basename "$0") $USAGE"
48 .
"$(git --exec-path)/git-sh-setup"
51 while case "$#" in 0) break ;; esac
54 -r|
--r|
--re|
--rep|
--repo)
58 --q|
--qu|
--qui|
--quie|
--quiet)
59 GFI_OPTS
="$GFI_OPTS --quiet"
62 # pass --force to git-fast-import and hg-fast-export.py
63 GFI_OPTS
="$GFI_OPTS --force"
67 # pass any other options down to hg2git.py
77 # for convenience: get default repo from state file
78 if [ x
"$REPO" = x
-a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
79 REPO
="`grep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
80 echo "Using last hg repository \"$REPO\""
83 if [ -z "$REPO" ]; then
84 echo "no repo given, use -r flag"
88 # make sure we have a marks cache
89 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
90 touch "$GIT_DIR/$PFX-$SFX_MARKS"
92 rm -f "$GIT_DIR/$PFX-$SFX_MARKS.new"
95 trap 'rm -f "$GIT_DIR/$PFX-$SFX_MARKS.new"' 0
100 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
102 exec 4>&3 3>&1 1>&4 4>&-
105 GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
107 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
108 --mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \
109 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
110 --status "$GIT_DIR/$PFX-$SFX_STATE" \
117 --import-marks="$GIT_DIR/$PFX-$SFX_MARKS" \
118 --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.new" \
119 $GFI_OPTS 3>&- || _e2=$?
125 [ "$_err1" = 0 -a "$_err2" = 0 ] ||
exit 1
126 mv -f "$GIT_DIR/$PFX-$SFX_MARKS.new" "$GIT_DIR/$PFX-$SFX_MARKS"
128 # save SHA1s of current heads for incremental imports
129 # and connectivity (plus sanity checking)
131 git for-each-ref
--format='%(refname) %(objectname)' refs
/heads | \
132 LC_ALL
=C
sed -e 's,^refs/heads/,:,' > "$GIT_DIR/$PFX-$SFX_HEADS"