git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGit PATCH 3/5] Let parse_patch take a string instead of a file parameter

From
Karl Hasselström <kha@treskal.com>
Date
Dec 14, 2007, 06:25 UTC
Message-ID
<20071214062515.29148.4402.stgit@yoghurt>
In-Reply-To
<20071214062251.29148.86191.stgit@yoghurt>

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 |    6 +++---
 stgit/commands/edit.py   |    3 ++-
 stgit/commands/imprt.py  |    2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/stgit/commands/common.py b/stgit/commands/common.py
index 3840387..7cf700e 100644
--- a/stgit/commands/common.py
+++ b/stgit/commands/common.py
@@ -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.
diff --git a/stgit/commands/edit.py b/stgit/commands/edit.py
index 4d1475f..65b54d9 100644
--- a/stgit/commands/edit.py
+++ b/stgit/commands/edit.py
@@ -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)
diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py
index 1c21a74..4a4b792 100644
--- a/stgit/commands/imprt.py
+++ b/stgit/commands/imprt.py
@@ -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()
Previous: Karl HasselströmNext: Karl Hasselström
Message 4 of 8 in “Various odds and ends”
  1. 0/5 Various odds and endsKarl Hasselström, Dec 14, 2007
  2. 1/5 Added --save-template flag to edit commandKarl Hasselström, Dec 14, 2007
  3. 2/5 Treat filename '-' as stdin/stdout in editKarl Hasselström, Dec 14, 2007
  4. 3/5 Let parse_patch take a string instead of a file parameterKarl Hasselström, Dec 14, 2007
  5. 4/5 Make generic --message/--file/--save-template flagsKarl Hasselström, Dec 14, 2007
  6. Karl HasselströmDec 14, 2007
  7. 5/5 Name the exit codes to improve legibilityKarl Hasselström, Dec 14, 2007
  8. Karl HasselströmDec 14, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.