mirror of
https://github.com/frej/fast-export.git
synced 2026-02-01 02:49:02 +01:00
Basic support for command line options in hg2git.py
Signed-off-by: Rocco Rutte <pdmef@gmx.net>
This commit is contained in:
36
hg2git.py
36
hg2git.py
@@ -9,6 +9,7 @@ Usage: hg2git.py <hg repo url> <marks file> <heads file> <tip file>
|
||||
|
||||
from mercurial import repo,hg,cmdutil,util,ui,revlog,node
|
||||
from tempfile import mkstemp
|
||||
from optparse import OptionParser
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
@@ -322,7 +323,7 @@ def hg2git(repourl,m,marksfile,headsfile,tipfile,authors={}):
|
||||
|
||||
min=int(state_cache.get('tip',0))
|
||||
max=_max
|
||||
if _max<0:
|
||||
if _max<=0:
|
||||
max=tip
|
||||
|
||||
c=0
|
||||
@@ -341,6 +342,33 @@ def hg2git(repourl,m,marksfile,headsfile,tipfile,authors={}):
|
||||
return 0
|
||||
|
||||
if __name__=='__main__':
|
||||
if len(sys.argv)!=6: sys.exit(usage(1))
|
||||
repourl,m,marksfile,headsfile,tipfile=sys.argv[1:]
|
||||
sys.exit(hg2git(repourl,m,marksfile,headsfile,tipfile))
|
||||
def bail(parser,opt):
|
||||
sys.stderr.write('Error: No %s option given\n' % opt)
|
||||
parser.print_help()
|
||||
sys.exit(2)
|
||||
|
||||
parser=OptionParser()
|
||||
|
||||
parser.add_option("-m","--max",type="int",dest="max",
|
||||
help="Maximum hg revision to import")
|
||||
parser.add_option("--marks",dest="marksfile",
|
||||
help="File to read git-fast-import's marks from")
|
||||
parser.add_option("--heads",dest="headsfile",
|
||||
help="File to read last run's git heads from")
|
||||
parser.add_option("--status",dest="statusfile",
|
||||
help="File to read status from")
|
||||
parser.add_option("-r","--repo",dest="repourl",
|
||||
help="URL of repo to import")
|
||||
|
||||
(options,args)=parser.parse_args()
|
||||
|
||||
m=0
|
||||
if options.max!=None: m=options.max
|
||||
|
||||
if options.marksfile==None: bail(parser,'--marks')
|
||||
if options.marksfile==None: bail(parser,'--heads')
|
||||
if options.marksfile==None: bail(parser,'--status')
|
||||
if options.marksfile==None: bail(parser,'--repo')
|
||||
|
||||
sys.exit(hg2git(options.repourl,m,options.marksfile,options.headsfile,
|
||||
options.headsfile))
|
||||
|
||||
29
hg2git.sh
29
hg2git.sh
@@ -2,7 +2,6 @@
|
||||
|
||||
ROOT="`dirname $0`"
|
||||
REPO=""
|
||||
MAX="-1"
|
||||
PFX="hg2git"
|
||||
SFX_MARKS="marks"
|
||||
SFX_HEADS="heads"
|
||||
@@ -20,15 +19,16 @@ cd_to_toplevel
|
||||
while case "$#" in 0) break ;; esac
|
||||
do
|
||||
case "$1" in
|
||||
-m)
|
||||
-r|--r|--re|--rep|--repo)
|
||||
shift
|
||||
MAX="$1"
|
||||
REPO="$1"
|
||||
;;
|
||||
--q|--qu|--qui|--quie|--quiet)
|
||||
QUIET="--quiet"
|
||||
;;
|
||||
-*)
|
||||
usage
|
||||
# pass any other options down to hg2git.py
|
||||
break
|
||||
;;
|
||||
*)
|
||||
break
|
||||
@@ -38,31 +38,22 @@ do
|
||||
done
|
||||
|
||||
# for convenience: get default repo from state file
|
||||
if [ "$#" != 1 -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
|
||||
if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
|
||||
REPO="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
|
||||
echo "Using last hg repository \"$REPO\""
|
||||
fi
|
||||
|
||||
if [ x"$REPO" = x ] ; then
|
||||
if [ "$#" != 1 ] ; then
|
||||
usage
|
||||
exit 1
|
||||
else
|
||||
REPO="$1"
|
||||
fi
|
||||
fi
|
||||
|
||||
# make sure we have a marks cache
|
||||
if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
|
||||
touch "$GIT_DIR/$PFX-$SFX_MARKS"
|
||||
fi
|
||||
|
||||
GIT_DIR="$GIT_DIR" python "$ROOT/hg2git.py" \
|
||||
"$REPO" \
|
||||
"$MAX" \
|
||||
"$GIT_DIR/$PFX-$SFX_MARKS" \
|
||||
"$GIT_DIR/$PFX-$SFX_HEADS" \
|
||||
"$GIT_DIR/$PFX-$SFX_STATE" \
|
||||
--repo "$REPO" \
|
||||
--marks "$GIT_DIR/$PFX-$SFX_MARKS" \
|
||||
--heads "$GIT_DIR/$PFX-$SFX_HEADS" \
|
||||
--status "$GIT_DIR/$PFX-$SFX_STATE" \
|
||||
"$@" \
|
||||
| git-fast-import $QUIET --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
|
||||
|| die 'Git fast-import failed'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user