Merge pull request #22 from TracyWebTech/master
[fast-export.git] / hg-fast-export.sh
blob346d6513e4efd44fada240c9c2693cd3119828a1
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 if [ -n "$BASH" ]; then
7 set -o pipefail
8 fi
10 ROOT="`dirname $0`"
11 REPO=""
12 PFX="hg2git"
13 SFX_MAPPING="mapping"
14 SFX_MARKS="marks"
15 SFX_HEADS="heads"
16 SFX_STATE="state"
17 GFI_OPTS=""
18 PYTHON=${PYTHON:-python}
20 USAGE="[--quiet] [-r <repo>] [--force] [-m <max>] [-s] [-A <file>] [-M <name>] [-o <name>]"
21 LONG_USAGE="Import hg repository <repo> up to either tip or <max>
22 If <repo> is omitted, use last hg repository as obtained from state file,
23 GIT_DIR/$PFX-$SFX_STATE by default.
25 Note: The argument order matters.
27 Options:
28 -m Maximum revision to import
29 --quiet Passed to git-fast-import(1)
30 -s Enable parsing Signed-off-by lines
31 -A Read author map from file
32 (Same as in git-svnimport(1) and git-cvsimport(1))
33 -r Mercurial repository to import
34 -M Set the default branch name (default to 'master')
35 -o Use <name> as branch namespace to track upstream (eg 'origin')
36 --force Ignore validation errors when converting, and pass --force
37 to git-fast-import(1)
40 . "$(git --exec-path)/git-sh-setup"
41 cd_to_toplevel
43 while case "$#" in 0) break ;; esac
45 case "$1" in
46 -r|--r|--re|--rep|--repo)
47 shift
48 REPO="$1"
50 --q|--qu|--qui|--quie|--quiet)
51 GFI_OPTS="$GFI_OPTS --quiet"
53 --force)
54 # pass --force to git-fast-import and hg-fast-export.py
55 GFI_OPTS="$GFI_OPTS --force"
56 break
58 -*)
59 # pass any other options down to hg2git.py
60 break
63 break
65 esac
66 shift
67 done
69 # for convenience: get default repo from state file
70 if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
71 REPO="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
72 echo "Using last hg repository \"$REPO\""
75 if [ -z "$REPO" ]; then
76 echo "no repo given, use -r flag"
77 exit 1
80 # make sure we have a marks cache
81 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
82 touch "$GIT_DIR/$PFX-$SFX_MARKS"
85 # cleanup on exit
86 trap 'rm -f "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"' 0
88 GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
89 --repo "$REPO" \
90 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
91 --mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \
92 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
93 --status "$GIT_DIR/$PFX-$SFX_STATE" \
94 "$@" \
95 | git fast-import $GFI_OPTS --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" || exit 1
97 # move recent marks cache out of the way...
98 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
99 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
100 else
101 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
104 # ...to create a new merged one
105 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
106 | uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
108 # save SHA1s of current heads for incremental imports
109 # and connectivity (plus sanity checking)
110 for head in `git branch | sed 's#^..##'` ; do
111 id="`git rev-parse $head`"
112 echo ":$head $id"
113 done > "$GIT_DIR/$PFX-$SFX_HEADS"
115 # check diff with color:
116 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r