chiark / gitweb /
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 384038753ceb727fd3eeb417e46a4f992afbc83b..7cf700e157f29db11959ea986f2d282093ec30ed 100644 (file)
@@ -482,11 +482,11 @@ def parse_mail(msg):
 
     return (descr, authname, authemail, authdate, diff)
 
 
     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)
     """
     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.
     descr, authname, authemail, authdate = __parse_description(descr)
 
     # we don't yet have an agreed place for the creation date.
index 4d1475f3b37f9b755a5c1dd8614db6dc504ec704..65b54d960e24679244c18a2bbcb401e3a91f18a6 100644 (file)
@@ -100,7 +100,8 @@ def __update_patch(pname, fname, options):
         f = sys.stdin
     else:
         f = open(fname)
         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)
     f.close()
 
     out.start('Updating patch "%s"' % pname)
index 1c21a745280a4539a434d01a10a5b003226ea66d..4a4b7929f3ed3c02d56148e8cb2fe1f11668edac 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_mail(msg)
     else:
         message, author_name, author_email, author_date, diff = \
-                 parse_patch(f)
+                 parse_patch(f.read())
 
     if filename:
         f.close()
 
     if filename:
         f.close()