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

[StGit PATCH 2/5] Treat filename '-' as stdin/stdout in edit

From
Karl Hasselström <kha@treskal.com>
Date
Dec 14, 2007, 06:25 UTC
Message-ID
<20071214062509.29148.23933.stgit@yoghurt>
In-Reply-To
<20071214062251.29148.86191.stgit@yoghurt>
From: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
 stgit/commands/edit.py |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/stgit/commands/edit.py b/stgit/commands/edit.py
index ec2c4ae..4d1475f 100644
--- a/stgit/commands/edit.py
+++ b/stgit/commands/edit.py
@@ -96,7 +96,10 @@ def __update_patch(pname, fname, options):
     bottom = patch.get_bottom()
     top = patch.get_top()
 
-    f = open(fname)
+    if fname == '-':
+        f = sys.stdin
+    else:
+        f = open(fname)
     message, author_name, author_email, author_date, diff = parse_patch(f)
     f.close()
 
@@ -171,9 +174,12 @@ def __generate_file(pname, fname, options):
     text = tmpl % tmpl_dict
 
     # write the file to be edited
-    f = open(fname, 'w+')
-    f.write(text)
-    f.close()
+    if fname == '-':
+        sys.stdout.write(text)
+    else:
+        f = open(fname, 'w+')
+        f.write(text)
+        f.close()
 
 def __edit_update_patch(pname, options):
     """Edit the given patch interactively.
Previous: Karl HasselströmNext: Karl Hasselström
Message 3 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.