[PATCH 02 of 12] Pass cvsps output through file instead of stdin

Edouard Gomez ed.gomez at free.fr
Tue Dec 19 06:05:43 UTC 2006


# HG changeset patch
# User Edouard Gomez <ed.gomez at free.fr>
# Date 1166511815 -3600
# Node ID c1fc3744581c8c009f6fcdc200ea3dc05b1d79f7
# Parent  facfb4a8c485a45d2cd5edb3a450c325102bdbca
Pass cvsps output through file instead of stdin

Using stdin inconditionnaly makes it hard to plug pdb when debugging. So
make cvsps input possible from file or stdin (default)

diff -r facfb4a8c485 -r c1fc3744581c hg-cvs-import
--- a/hg-cvs-import	Tue Dec 19 08:03:35 2006 +0100
+++ b/hg-cvs-import	Tue Dec 19 08:03:35 2006 +0100
@@ -22,7 +22,7 @@ for name, value in optlist:
 
 if not cvsroot or not module or not hgpath:
     sys.stderr.write(
-"""Usage: hg-cvs-import <-d path> <-M modulename> <-C path> [OPTIONS]
+"""Usage: hg-cvs-import <-d path> <-M modulename> <-C path> [OPTIONS] [cvsps file]
 
 Mandatory options:
  -C path: path to an initialized hg repository where patchsets will be pushed
@@ -30,6 +30,7 @@ Mandatory options:
  -M modulename: name of the CVS module to convert
 
 Optional options:
+ cvsps file: filename of the cvsps file. Can be '-' for stdin (default: stdin)
  -m mapfile: file where (cvs,hg) node couples are saved (default: map)
 
 Inline manual
@@ -257,14 +258,23 @@ def addrev(branch, tag, r, user, date, l
             addtag(branch, hg.hex(n))
         addtag(tag, hg.hex(n))
 
-cvspipe = sys.stdin
+if args is None or len(args) == 0:
+    args = ['-']
+
+cvspipe = None
+if args[0] == '-':
+    cvspipe = sys.stdin
+else:
+    try:
+        cvspipe = open(args[0], 'r')
+    except IOError:
+        sys.stderr.write('Could not read %s\n' % args[0])
+        sys.exit(1)
+
 time.tzset()
 lastpatch = None
-while True:
-    try:
-        l = raw_input()
-    except EOFError:
-        break
+for l in cvspipe:
+    l = l.rstrip()
     if l.startswith('PatchSet') and (state == 'dashes' or patchset == None):
         if patchset != None:
             addrev(branch, tag, patchset, user, date, log, files)



More information about the Mercurial-devel mailing list