SFX_MARKS="marks"
SFX_HEADS="heads"
SFX_STATE="state"
-QUIET=""
+GFI_OPTS=""
PYTHON=${PYTHON:-python}
-USAGE="[--quiet] [-r <repo>] [-m <max>] [-s] [-A <file>] [-M <name>] [-o <name>]"
+USAGE="[--quiet] [-r <repo>] [--force] [-m <max>] [-s] [--hgtags] [-A <file>] [-M <name>] [-o <name>]"
LONG_USAGE="Import hg repository <repo> up to either tip or <max>
If <repo> is omitted, use last hg repository as obtained from state file,
GIT_DIR/$PFX-$SFX_STATE by default.
Note: The argument order matters.
Options:
- -m Maximum revision to import
- --quiet Passed to git-fast-import(1)
- -s Enable parsing Signed-off-by lines
- -A Read author map from file
- (Same as in git-svnimport(1) and git-cvsimport(1))
- -r Mercurial repository to import
- -M Set the default branch name (default to 'master')
- -o Use <name> as branch namespace to track upstream (eg 'origin')
+ -m Maximum revision to import
+ --quiet Passed to git-fast-import(1)
+ -s Enable parsing Signed-off-by lines
+ --hgtags Enable exporting .hgtags files
+ -A Read author map from file
+ (Same as in git-svnimport(1) and git-cvsimport(1))
+ -r Mercurial repository to import
+ -M Set the default branch name (default to 'master')
+ -o Use <name> as branch namespace to track upstream (eg 'origin')
+ --force Ignore validation errors when converting, and pass --force
+ to git-fast-import(1)
"
. "$(git --exec-path)/git-sh-setup"
REPO="$1"
;;
--q|--qu|--qui|--quie|--quiet)
- QUIET="--quiet"
+ GFI_OPTS="$GFI_OPTS --quiet"
+ ;;
+ --force)
+ # pass --force to git-fast-import and hg-fast-export.py
+ GFI_OPTS="$GFI_OPTS --force"
+ break
;;
-*)
# pass any other options down to hg2git.py
echo "Using last hg repository \"$REPO\""
fi
+if [ -z "$REPO" ]; then
+ echo "no repo given, use -r flag"
+ exit 1
+fi
+
# make sure we have a marks cache
if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
touch "$GIT_DIR/$PFX-$SFX_MARKS"
fi
-GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
- --repo "$REPO" \
- --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
- --mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \
- --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
- --status "$GIT_DIR/$PFX-$SFX_STATE" \
- "$@" \
-| git fast-import $QUIET --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp"
+# cleanup on exit
+trap 'rm -f "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"' 0
+
+_err1=
+_err2=
+exec 3>&1
+{ read -r _err1 || :; read -r _err2 || :; } <<-EOT
+$(
+ exec 4>&3 3>&1 1>&4 4>&-
+ {
+ _e1=0
+ GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
+ --repo "$REPO" \
+ --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
+ --mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \
+ --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
+ --status "$GIT_DIR/$PFX-$SFX_STATE" \
+ "$@" 3>&- || _e1=$?
+ echo $_e1 >&3
+ } | \
+ {
+ _e2=0
+ git fast-import $GFI_OPTS --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" 3>&- || _e2=$?
+ echo $_e2 >&3
+ }
+)
+EOT
+exec 3>&-
+[ "$_err1" = 0 -a "$_err2" = 0 ] || exit 1
# move recent marks cache out of the way...
if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
| uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
-# cleanup
-rm -rf "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"
-
# save SHA1s of current heads for incremental imports
# and connectivity (plus sanity checking)
for head in `git branch | sed 's#^..##'` ; do