Let parse_patch take a string instead of a file parameter
authorKarl Hasselström <kha@treskal.com>
Wed, 12 Dec 2007 21:33:32 +0000 (22:33 +0100)
committerKarl Hasselström <kha@treskal.com>
Thu, 13 Dec 2007 20:17:10 +0000 (21:17 +0100)
This makes it more generally useful, since all future callers may not
have the input in a file.

Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/common.py
stgit/commands/edit.py
stgit/commands/imprt.py

index 3840387..7cf700e 100644 (file)
@@ -482,11 +482,11 @@ def parse_mail(msg):
 
     return (descr, authname, authemail, authdate, diff)
 
-def parse_patch(fobj):
-    """Parse the input file and return (description, authname,
+def parse_patch(text):
+    """Parse the input text and return (description, authname,
     authemail, authdate, diff)
     """
-    descr, diff = __split_descr_diff(fobj.read())
+    descr, diff = __split_descr_diff(text)
     descr, authname, authemail, authdate = __parse_description(descr)
 
     # we don't yet have an agreed place for the creation date.
index 4d1475f..65b54d9 100644 (file)
@@ -100,7 +100,8 @@ def __update_patch(pname, fname, options):
         f = sys.stdin
     else:
         f = open(fname)
-    message, author_name, author_email, author_date, diff = parse_patch(f)
+    (message, author_name, author_email, author_date, diff
+     ) = parse_patch(f.read())
     f.close()
 
     out.start('Updating patch "%s"' % pname)
index 1c21a74..4a4b792 100644 (file)
@@ -192,7 +192,7 @@ def __import_file(filename, options, patch = None):
                  parse_mail(msg)
     else:
         message, author_name, author_email, author_date, diff = \
-                 parse_patch(f)
+                 parse_patch(f.read())
 
     if filename:
         f.close()