Mercurial > hg
changeset 35662:91f0979f16c0
cat: factor out a function that populates the formatter
This will allow extensions to add data to the templater.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 16 Jan 2018 19:56:00 -0500 |
parents | 1c0ee0befba0 |
children | a985834961f7 |
files | mercurial/cmdutil.py |
diffstat | 1 files changed, 13 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Sun Jan 14 12:07:06 2018 -0500 +++ b/mercurial/cmdutil.py Tue Jan 16 19:56:00 2018 -0500 @@ -2962,6 +2962,18 @@ return ret +def _updatecatformatter(fm, ctx, matcher, path, decode): + """Hook for adding data to the formatter used by ``hg cat``. + + Extensions (e.g., lfs) can wrap this to inject keywords/data, but must call + this method first.""" + data = ctx[path].data() + if decode: + data = ctx.repo().wwritedata(path, data) + fm.startitem() + fm.write('data', '%s', data) + fm.data(abspath=path, path=matcher.rel(path)) + def cat(ui, repo, ctx, matcher, basefm, fntemplate, prefix, **opts): err = 1 opts = pycompat.byteskwargs(opts) @@ -2977,12 +2989,7 @@ except OSError: pass with formatter.maybereopen(basefm, filename, opts) as fm: - data = ctx[path].data() - if opts.get('decode'): - data = repo.wwritedata(path, data) - fm.startitem() - fm.write('data', '%s', data) - fm.data(abspath=path, path=matcher.rel(path)) + _updatecatformatter(fm, ctx, matcher, path, opts.get('decode')) # Automation often uses hg cat on single files, so special case it # for performance to avoid the cost of parsing the manifest.