Mercurial > hg-stable
diff mercurial/cmdutil.py @ 32610:746e12a767b3
cat: add formatter support
This is an example showing how formatter can handle the --output option.
git subrepo isn't supported for now.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 25 May 2017 21:53:44 +0900 |
parents | 7bfa1b199972 |
children | d3e1c5b4986c |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Sat May 27 17:58:36 2017 +0900 +++ b/mercurial/cmdutil.py Thu May 25 21:53:44 2017 +0900 @@ -2632,21 +2632,21 @@ return ret -def cat(ui, repo, ctx, matcher, fntemplate, prefix, **opts): +def cat(ui, repo, ctx, matcher, basefm, fntemplate, prefix, **opts): err = 1 def write(path): + filename = None if fntemplate: filename = makefilename(repo, fntemplate, ctx.node(), pathname=os.path.join(prefix, path)) - fp = open(filename, 'wb') - else: - fp = _unclosablefile(ui.fout) - with fp: + with formatter.maybereopen(basefm, filename, opts) as fm: data = ctx[path].data() if opts.get('decode'): data = repo.wwritedata(path, data) - fp.write(data) + fm.startitem() + fm.write('data', '%s', data) + fm.data(abspath=path, path=matcher.rel(path)) # Automation often uses hg cat on single files, so special case it # for performance to avoid the cost of parsing the manifest. @@ -2670,7 +2670,7 @@ try: submatch = matchmod.subdirmatcher(subpath, matcher) - if not sub.cat(submatch, fntemplate, + if not sub.cat(submatch, basefm, fntemplate, os.path.join(prefix, sub._path), **opts): err = 0 except error.RepoLookupError: