1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#!/bin/sh
# Copyright (c) 2007, 2008 Rocco Rutte <pdmef@gmx.net> and others.
# License: MIT <http://www.opensource.org/licenses/mit-license.php>
if [ -n "$BASH" ]; then
set -o pipefail
fi
ROOT="/usr/share/hg-fast-export"
REPO=""
PFX="hg2git"
SFX_MAPPING="mapping"
SFX_MARKS="marks"
SFX_HEADS="heads"
SFX_STATE="state"
GFI_OPTS=""
PYTHON=${PYTHON:-python}
USAGE="[--quiet] [-r <repo>] [--force] [-m <max>] [-s] [-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')
--force Ignore validation errors when converting, and pass --force
to git-fast-import(1)
"
. "$(git --exec-path)/git-sh-setup"
cd_to_toplevel
while case "$#" in 0) break ;; esac
do
case "$1" in
-r|--r|--re|--rep|--repo)
shift
REPO="$1"
;;
--q|--qu|--qui|--quie|--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
break
;;
*)
break
;;
esac
shift
done
# for convenience: get default repo from state file
if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
REPO="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
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
# cleanup on exit
trap 'rm -f "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"' 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" \
"$@" \
| git fast-import $GFI_OPTS --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" || exit 1
# move recent marks cache out of the way...
if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
else
touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
fi
# ...to create a new merged one
cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
| uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
# save SHA1s of current heads for incremental imports
# and connectivity (plus sanity checking)
for head in `git branch | sed 's#^..##'` ; do
id="`git rev-parse $head`"
echo ":$head $id"
done > "$GIT_DIR/$PFX-$SFX_HEADS"
# check diff with color:
# ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r
|