[PATCH 01 of 10] Use getopt for command line options
Edouard Gomez
ed.gomez at free.fr
Sun Dec 17 15:31:47 UTC 2006
# HG changeset patch
# User Edouard Gomez <ed.gomez at free.fr>
# Date 1166365116 -3600
# Node ID 50cf5a2bec63f22693c37ca4e6120919230e98f6
# Parent c72dfa2de0ed620fb98e84d284b929c342e1e3e2
Use getopt for command line options
Leverage the bad cmd line UI using the getopt module. Improves thing a bit
and allows further improvement in later patches.
diff -r c72dfa2de0ed -r 50cf5a2bec63 hg-cvs-import
--- a/hg-cvs-import Mon Jul 10 15:45:55 2006 -0400
+++ b/hg-cvs-import Sun Dec 17 15:18:36 2006 +0100
@@ -1,25 +1,53 @@
#!/usr/bin/env python
-# make a copy of your cvs repository (not a checkout, but a copy)
-# cp cvsroot tmpdir
-# checkout the copy, cd into the checkout
-# TZ=UTC cvsps -u -A -q > ../cvsps.dump
-# cd ..
-# TZ=UTC hg-cvs-import cvsroot cvsmodule hg-rep mapfile < cvsps.dump
-#
-# module is the cvs module (ie cvs checkout module)
-# mapfile should be empty the first time the import is run. It records a
-# mapping of hg csets to cvsps commits
-#
-# As your cvs repo updates, you can run cvsps again and then run the
-# importer again to update. As long as you use the same mapfile, it will
-# pick up where it left off last time.
-
-import sys, os, time
+import sys, os, time, getopt
from mercurial import ui, hg, revlog, commands, util
-version = 0.6
-cvsroot, module, hgpath, mapfile = sys.argv[1:]
+version = 0.7
+optlist, args = getopt.getopt(sys.argv[1:], 'd:M:C:m:')
+
+cvsroot = None
+module = None
+hgpath = None
+mapfile = None
+for name, value in optlist:
+ if name == '-d':
+ cvsroot = value
+ elif name == '-M':
+ module = value
+ elif name == '-C':
+ hgpath = value
+ elif name == '-m':
+ mapfile = value
+
+if not cvsroot or not module or not hgpath:
+ sys.stderr.write(
+"""Usage: hg-cvs-import <-d path> <-M modulename> <-C path> [OPTIONS]
+
+Mandatory options:
+ -C path: path to an initialized hg repository where patchsets will be pushed
+ -d path: path to the CVS repository
+ -M modulename: name of the CVS module to convert
+
+Optional options:
+ -m mapfile: file where (cvs,hg) node couples are saved (default: map)
+
+Inline manual
+1. Use cvsps to generate patchset information
+ $ TZ=UTC cvsps -u -A -q --cvs-direct --root /path/to/cvsrepo > cvsps.output
+2. Use hg-cvs-import to import the patches to an initiailized hgrepository
+ $ TZ=UTC \\
+ hg-cvs-import -d cvsroot -M cvsmodule -C hg-rep -m mapfile cvsps.output
+
+As your cvs repo updates, you can run cvsps again and then run the
+importer again to update. As long as you use the same mapfile, it will
+pick up where it left off last time.
+""")
+ sys.exit(1)
+
+if not mapfile:
+ mapfile = 'map'
+
cvsroot = os.path.abspath(cvsroot)
hgpatch = os.path.abspath(hgpath)
mapfile = os.path.abspath(mapfile)
More information about the Mercurial-devel
mailing list