##// END OF EJS Templates
cat: factor out a function that populates the formatter...
Matt Harbison -
r35680:91f0979f default
parent child Browse files
Show More
@@ -2962,6 +2962,18 b' def remove(ui, repo, m, prefix, after, f'
2962
2962
2963 return ret
2963 return ret
2964
2964
2965 def _updatecatformatter(fm, ctx, matcher, path, decode):
2966 """Hook for adding data to the formatter used by ``hg cat``.
2967
2968 Extensions (e.g., lfs) can wrap this to inject keywords/data, but must call
2969 this method first."""
2970 data = ctx[path].data()
2971 if decode:
2972 data = ctx.repo().wwritedata(path, data)
2973 fm.startitem()
2974 fm.write('data', '%s', data)
2975 fm.data(abspath=path, path=matcher.rel(path))
2976
2965 def cat(ui, repo, ctx, matcher, basefm, fntemplate, prefix, **opts):
2977 def cat(ui, repo, ctx, matcher, basefm, fntemplate, prefix, **opts):
2966 err = 1
2978 err = 1
2967 opts = pycompat.byteskwargs(opts)
2979 opts = pycompat.byteskwargs(opts)
@@ -2977,12 +2989,7 b' def cat(ui, repo, ctx, matcher, basefm, '
2977 except OSError:
2989 except OSError:
2978 pass
2990 pass
2979 with formatter.maybereopen(basefm, filename, opts) as fm:
2991 with formatter.maybereopen(basefm, filename, opts) as fm:
2980 data = ctx[path].data()
2992 _updatecatformatter(fm, ctx, matcher, path, opts.get('decode'))
2981 if opts.get('decode'):
2982 data = repo.wwritedata(path, data)
2983 fm.startitem()
2984 fm.write('data', '%s', data)
2985 fm.data(abspath=path, path=matcher.rel(path))
2986
2993
2987 # Automation often uses hg cat on single files, so special case it
2994 # Automation often uses hg cat on single files, so special case it
2988 # for performance to avoid the cost of parsing the manifest.
2995 # for performance to avoid the cost of parsing the manifest.
General Comments 0
You need to be logged in to leave comments. Login now