[StGit PATCH 2/5] Treat filename '-' as stdin/stdout in edit
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.