hg2git.py: Use git-rev-parse to get SHA1s instead of reading files below refs/ directly
[fast-export/dharding.git] / hg-fast-export.sh
blobf9d1dd68584e58ef24ec62c7a3d237f8f4c38cce
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_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>]"
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
31 . git-sh-setup
32 cd_to_toplevel
34 while case "$#" in 0) break ;; esac
36 case "$1" in
37 -r|--r|--re|--rep|--repo)
38 shift
39 REPO="$1"
41 --q|--qu|--qui|--quie|--quiet)
42 QUIET="--quiet"
44 -*)
45 # pass any other options down to hg2git.py
46 break
49 break
51 esac
52 shift
53 done
55 # for convenience: get default repo from state file
56 if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
57 REPO="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
58 echo "Using last hg repository \"$REPO\""
61 # make sure we have a marks cache
62 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
63 touch "$GIT_DIR/$PFX-$SFX_MARKS"
66 GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
67 --repo "$REPO" \
68 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
69 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
70 --status "$GIT_DIR/$PFX-$SFX_STATE" \
71 "$@" \
72 | git-fast-import $QUIET --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
73 || die 'Git fast-import failed'
75 # move recent marks cache out of the way...
76 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
77 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
78 else
79 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
82 # ...to create a new merged one
83 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
84 | uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
86 # cleanup
87 rm -rf "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"
89 # save SHA1s of current heads for incremental imports
90 # and connectivity (plus sanity checking)
91 for head in `git branch | sed 's#^..##'` ; do
92 id="`git-rev-parse $head`"
93 echo ":$head $id"
94 done > "$GIT_DIR/$PFX-$SFX_HEADS"
96 # check diff with color:
97 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r