hg2git: Update copyrights and maintainership information.
[fast-export/fast-export-unix-compliant.git] / hg-fast-export.sh
blob2f721e23bb8d3f243a06b5c76b823a85d6321ea8
1 #!/bin/sh
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="`dirname $0`"
7 REPO=""
8 PFX="hg2git"
9 SFX_MARKS="marks"
10 SFX_HEADS="heads"
11 SFX_STATE="state"
12 QUIET=""
13 PYTHON=${PYTHON:-python}
15 USAGE="[--quiet] [-r <repo>] [-m <max>] [-s] [-A <file>] [-M <branch_name>]"
16 LONG_USAGE="Import hg repository <repo> up to either tip or <max>
17 If <repo> is omitted, use last hg repository as obtained from state file,
18 GIT_DIR/$PFX-$SFX_STATE by default.
20 Note: The argument order matters.
22 Options:
23 -m Maximum revision to import
24 --quiet Passed to git-fast-import(1)
25 -s Enable parsing Signed-off-by lines
26 -A Read author map from file
27 (Same as in git-svnimport(1) and git-cvsimport(1))
28 -r Mercurial repository to import
29 -M Set the default branch name
32 . "$(git --exec-path)/git-sh-setup"
33 cd_to_toplevel
35 while case "$#" in 0) break ;; esac
37 case "$1" in
38 -r|--r|--re|--rep|--repo)
39 shift
40 REPO="$1"
42 --q|--qu|--qui|--quie|--quiet)
43 QUIET="--quiet"
45 -*)
46 # pass any other options down to hg2git.py
47 break
50 break
52 esac
53 shift
54 done
56 # for convenience: get default repo from state file
57 if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
58 REPO="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
59 echo "Using last hg repository \"$REPO\""
62 # make sure we have a marks cache
63 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
64 touch "$GIT_DIR/$PFX-$SFX_MARKS"
67 GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
68 --repo "$REPO" \
69 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
70 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
71 --status "$GIT_DIR/$PFX-$SFX_STATE" \
72 "$@" \
73 | git fast-import $QUIET --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
74 || die 'Git fast-import failed'
76 # move recent marks cache out of the way...
77 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
78 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
79 else
80 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
83 # ...to create a new merged one
84 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
85 | uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
87 # cleanup
88 rm -rf "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"
90 # save SHA1s of current heads for incremental imports
91 # and connectivity (plus sanity checking)
92 for head in `git branch | sed 's#^..##'` ; do
93 id="`git rev-parse $head`"
94 echo ":$head $id"
95 done > "$GIT_DIR/$PFX-$SFX_HEADS"
97 # check diff with color:
98 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r