To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / extra / fast-export / hg-fast-export.sh @ 1548:fd4cc11ae096
History | View | Annotate | Download (4.03 KB)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
|
| 3 |
# Copyright (c) 2007, 2008 Rocco Rutte <pdmef@gmx.net> and others. |
| 4 |
# License: MIT <http://www.opensource.org/licenses/mit-license.php> |
| 5 |
|
| 6 |
ROOT="$(dirname "$(which "$0")")" |
| 7 |
REPO="" |
| 8 |
PFX="hg2git" |
| 9 |
SFX_MAPPING="mapping" |
| 10 |
SFX_MARKS="marks" |
| 11 |
SFX_HEADS="heads" |
| 12 |
SFX_STATE="state" |
| 13 |
GFI_OPTS="" |
| 14 |
PYTHON=${PYTHON:-python}
|
| 15 |
|
| 16 |
USAGE="[--quiet] [-r <repo>] [--force] [-m <max>] [-s] [--hgtags] [-A <file>] [-B <file>] [-T <file>] [-M <name>] [-o <name>] [--hg-hash] [-e <encoding>]" |
| 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. |
| 20 |
|
| 21 |
Note: The argument order matters. |
| 22 |
|
| 23 |
Options: |
| 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 |
| 27 |
to git-fast-import(1) |
| 28 |
-m <max> Maximum revision to import |
| 29 |
-s Enable parsing Signed-off-by lines |
| 30 |
--hgtags Enable exporting .hgtags files |
| 31 |
-A <file> Read author map from file |
| 32 |
(Same as in git-svnimport(1) and git-cvsimport(1)) |
| 33 |
-B <file> Read branch map from file |
| 34 |
-T <file> Read tags map from file |
| 35 |
-M <name> Set the default branch name (defaults to 'master') |
| 36 |
-o <name> Use <name> as branch namespace to track upstream (eg 'origin') |
| 37 |
--hg-hash Annotate commits with the hg hash as git notes in the |
| 38 |
hg namespace. |
| 39 |
-e <encoding> Assume commit and author strings retrieved from |
| 40 |
Mercurial are encoded in <encoding> |
| 41 |
--fe <filename_encoding> Assume filenames from Mercurial are encoded |
| 42 |
in <filename_encoding> |
| 43 |
" |
| 44 |
case "$1" in |
| 45 |
-h|--help) |
| 46 |
echo "usage: $(basename "$0") $USAGE" |
| 47 |
echo "" |
| 48 |
echo "$LONG_USAGE" |
| 49 |
exit 0 |
| 50 |
esac |
| 51 |
. "$(git --exec-path)/git-sh-setup" |
| 52 |
cd_to_toplevel |
| 53 |
|
| 54 |
while case "$#" in 0) break ;; esac |
| 55 |
do |
| 56 |
case "$1" in |
| 57 |
-r|--r|--re|--rep|--repo) |
| 58 |
shift |
| 59 |
REPO="$1" |
| 60 |
;; |
| 61 |
--q|--qu|--qui|--quie|--quiet) |
| 62 |
GFI_OPTS="$GFI_OPTS --quiet" |
| 63 |
;; |
| 64 |
--force) |
| 65 |
# pass --force to git-fast-import and hg-fast-export.py |
| 66 |
GFI_OPTS="$GFI_OPTS --force" |
| 67 |
break |
| 68 |
;; |
| 69 |
-*) |
| 70 |
# pass any other options down to hg2git.py |
| 71 |
break |
| 72 |
;; |
| 73 |
*) |
| 74 |
break |
| 75 |
;; |
| 76 |
esac |
| 77 |
shift |
| 78 |
done |
| 79 |
|
| 80 |
# for convenience: get default repo from state file |
| 81 |
if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then |
| 82 |
REPO="`grep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`" |
| 83 |
echo "Using last hg repository \"$REPO\"" |
| 84 |
fi |
| 85 |
|
| 86 |
if [ -z "$REPO" ]; then |
| 87 |
echo "no repo given, use -r flag" |
| 88 |
exit 1 |
| 89 |
fi |
| 90 |
|
| 91 |
# make sure we have a marks cache |
| 92 |
if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then |
| 93 |
touch "$GIT_DIR/$PFX-$SFX_MARKS" |
| 94 |
fi |
| 95 |
|
| 96 |
# cleanup on exit |
| 97 |
trap 'rm -f "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"' 0 |
| 98 |
|
| 99 |
_err1= |
| 100 |
_err2= |
| 101 |
exec 3>&1 |
| 102 |
{ read -r _err1 || :; read -r _err2 || :; } <<-EOT
|
| 103 |
$( |
| 104 |
exec 4>&3 3>&1 1>&4 4>&- |
| 105 |
{
|
| 106 |
_e1=0 |
| 107 |
GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \ |
| 108 |
--repo "$REPO" \ |
| 109 |
--marks "$GIT_DIR/$PFX-$SFX_MARKS" \ |
| 110 |
--mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \ |
| 111 |
--heads "$GIT_DIR/$PFX-$SFX_HEADS" \ |
| 112 |
--status "$GIT_DIR/$PFX-$SFX_STATE" \ |
| 113 |
"$@" 3>&- || _e1=$? |
| 114 |
echo $_e1 >&3 |
| 115 |
} | \ |
| 116 |
{
|
| 117 |
_e2=0 |
| 118 |
git fast-import $GFI_OPTS --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" 3>&- || _e2=$? |
| 119 |
echo $_e2 >&3 |
| 120 |
} |
| 121 |
) |
| 122 |
EOT |
| 123 |
exec 3>&- |
| 124 |
[ "$_err1" = 0 -a "$_err2" = 0 ] || exit 1 |
| 125 |
|
| 126 |
# move recent marks cache out of the way... |
| 127 |
if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then |
| 128 |
mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old" |
| 129 |
else |
| 130 |
touch "$GIT_DIR/$PFX-$SFX_MARKS.old" |
| 131 |
fi |
| 132 |
|
| 133 |
# ...to create a new merged one |
| 134 |
cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \ |
| 135 |
| uniq > "$GIT_DIR/$PFX-$SFX_MARKS" |
| 136 |
|
| 137 |
# save SHA1s of current heads for incremental imports |
| 138 |
# and connectivity (plus sanity checking) |
| 139 |
for head in `git branch | sed 's#^..##'` ; do |
| 140 |
id="`git rev-parse refs/heads/$head`" |
| 141 |
echo ":$head $id" |
| 142 |
done > "$GIT_DIR/$PFX-$SFX_HEADS" |
| 143 |
|
| 144 |
# check diff with color: |
| 145 |
# ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r |