Patchwork [4,of,6] cat: stop using makefileobj()

login
register
mail settings
Submitter Yuya Nishihara
Date May 30, 2017, 4:07 p.m.
Message ID <d403731c94f481cb5349.1496160432@mimosa>
Download mbox | patch
Permalink /patch/21071/
State Accepted
Headers show

Comments

Yuya Nishihara - May 30, 2017, 4:07 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1495716189 -32400
#      Thu May 25 21:43:09 2017 +0900
# Node ID d403731c94f481cb5349580f374e8a8564fed2f4
# Parent  aa8b8c29ea0f3345ee490275a42c279fbe1f6e39
cat: stop using makefileobj()

Prepares for porting to the formatter API. We won't be able to utilize the
abstraction provided by makefilename() because formatter must be instantiated
per file.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2636,8 +2636,12 @@  def cat(ui, repo, ctx, matcher, fntempla
     err = 1
 
     def write(path):
-        fp = makefileobj(repo, fntemplate, ctx.node(),
-                         pathname=os.path.join(prefix, path))
+        if fntemplate:
+            filename = makefilename(repo, fntemplate, ctx.node(),
+                                    pathname=os.path.join(prefix, path))
+            fp = open(filename, 'wb')
+        else:
+            fp = _unclosablefile(ui.fout)
         data = ctx[path].data()
         if opts.get('decode'):
             data = repo.wwritedata(path, data)