Commit 511c84be authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

cmdutil: pass ctx to makefileobj() in place of repo/node pair (API)

parent 33ed8b511185
......@@ -1359,8 +1359,7 @@ def overridecat(orig, ui, repo, file1, *pats, **opts):
m.visitdir = lfvisitdirfn
for f in ctx.walk(m):
with cmdutil.makefileobj(repo, opts.get('output'), ctx.node(),
pathname=f) as fp:
with cmdutil.makefileobj(ctx, opts.get('output'), pathname=f) as fp:
lf = lfutil.splitstandin(f)
if lf is None or origmatchfn(f):
# duplicating unreachable code from commands.cat
......
......@@ -956,19 +956,19 @@ class _unclosablefile(object):
def __exit__(self, exc_type, exc_value, exc_tb):
pass
def makefileobj(repo, pat, node, desc=None, total=None,
def makefileobj(ctx, pat, desc=None, total=None,
seqno=None, revwidth=None, mode='wb', modemap=None,
pathname=None):
writable = mode not in ('r', 'rb')
if isstdiofilename(pat):
repo = ctx.repo()
if writable:
fp = repo.ui.fout
else:
fp = repo.ui.fin
return _unclosablefile(fp)
ctx = repo[node]
fn = makefilename(ctx, pat, desc, total, seqno, revwidth, pathname)
if modemap is not None:
mode = modemap.get(fn, mode)
......@@ -1546,7 +1546,7 @@ def export(repo, revs, fntemplate='hg-%h.patch', fp=None, switch_parent=False,
if not fp and fntemplate:
desc_lines = ctx.description().rstrip().split('\n')
desc = desc_lines[0] #Commit always has a first line.
fo = makefileobj(repo, fntemplate, ctx.node(), desc=desc,
fo = makefileobj(ctx, fntemplate, desc=desc,
total=total, seqno=seqno, revwidth=revwidth,
mode='wb', modemap=filemode)
dest = fo.name
......
......@@ -486,7 +486,7 @@ def archive(ui, repo, dest, **opts):
if dest == '-':
if kind == 'files':
raise error.Abort(_('cannot archive plain files to stdout'))
dest = cmdutil.makefileobj(repo, dest, node)
dest = cmdutil.makefileobj(ctx, dest)
if not prefix:
prefix = os.path.basename(repo.root) + '-%h'
......
......@@ -1642,8 +1642,7 @@ class gitsubrepo(abstractsubrepo):
# TODO: add support for non-plain formatter (see cmdutil.cat())
for f in match.files():
output = self._gitcommand(["show", "%s:%s" % (rev, f)])
fp = cmdutil.makefileobj(self._subparent, fntemplate,
self._ctx.node(),
fp = cmdutil.makefileobj(self._ctx, fntemplate,
pathname=self.wvfs.reljoin(prefix, f))
fp.write(output)
fp.close()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment