hg export: Support tag movement
[fast-export/fast-export-unix-compliant.git] / hg-fast-export.sh
blob5cfc575378bea9919c8b0bfc6e74f54dc23874f2
1 #!/bin/sh
3 # Copyright (c) 2007 Rocco Rutte <pdmef@gmx.net>
4 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
6 ROOT="`dirname $0`"
7 REPO=""
8 PFX="hg2git"
9 SFX_MAPPING="mapping"
10 SFX_MARKS="marks"
11 SFX_HEADS="heads"
12 SFX_STATE="state"
13 QUIET=""
14 PYTHON=${PYTHON:-python}
16 USAGE="[--quiet] [-r <repo>] [-m <max>] [-s] [-A <file>] [-M <branch_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.
23 Options:
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
33 . "$(git --exec-path)/git-sh-setup"
34 cd_to_toplevel
36 while case "$#" in 0) break ;; esac
38 case "$1" in
39 -r|--r|--re|--rep|--repo)
40 shift
41 REPO="$1"
43 --q|--qu|--qui|--quie|--quiet)
44 QUIET="--quiet"
46 -*)
47 # pass any other options down to hg2git.py
48 break
51 break
53 esac
54 shift
55 done
57 # for convenience: get default repo from state file
58 if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
59 REPO="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
60 echo "Using last hg repository \"$REPO\""
63 # make sure we have a marks cache
64 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
65 touch "$GIT_DIR/$PFX-$SFX_MARKS"
68 GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
69 --repo "$REPO" \
70 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
71 --mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \
72 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
73 --status "$GIT_DIR/$PFX-$SFX_STATE" \
74 "$@" \
75 | git fast-import $QUIET --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp"
77 # move recent marks cache out of the way...
78 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
79 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
80 else
81 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
84 # ...to create a new merged one
85 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
86 | uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
88 # cleanup
89 rm -rf "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"
91 # save SHA1s of current heads for incremental imports
92 # and connectivity (plus sanity checking)
93 for head in `git branch | sed 's#^..##'` ; do
94 id="`git rev-parse $head`"
95 echo ":$head $id"
96 done > "$GIT_DIR/$PFX-$SFX_HEADS"
98 # check diff with color:
99 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r