from mercurial import repo,hg,cmdutil,util,ui,revlog,node
from tempfile import mkstemp
+from optparse import OptionParser
import re
import sys
import os
min=int(state_cache.get('tip',0))
max=_max
- if _max<0:
+ if _max<=0:
max=tip
c=0
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))
ROOT="`dirname $0`"
REPO=""
-MAX="-1"
PFX="hg2git"
SFX_MARKS="marks"
SFX_HEADS="heads"
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
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'