If the argument to make_file can act like a file, return it.
authorBryan O'Sullivan <bos@serpentine.com>
Wed, 20 Jul 2005 03:55:16 -0800
changeset 738 32a97c9d8e98
parent 737 8db4d406b3d3
child 739 36edb39e8e8c
If the argument to make_file can act like a file, return it. This is useful for code that calls command functions, but doesn't want to send I/O through the filesystem.
mercurial/commands.py
--- a/mercurial/commands.py	Wed Jul 20 03:52:06 2005 -0800
+++ b/mercurial/commands.py	Wed Jul 20 03:55:16 2005 -0800
@@ -121,6 +121,10 @@
     if not pat or pat == '-':
         if 'w' in mode: return sys.stdout
         else: return sys.stdin
+    if hasattr(pat, 'write') and 'w' in mode:
+        return pat
+    if hasattr(pat, 'read') and 'r' in mode:
+        return pat
     node_expander = {
         'H': lambda: hg.hex(node),
         'R': lambda: str(r.rev(node)),