##// END OF EJS Templates
cmdutil: prevent code repetition by abstraction in changeset_templater
Dirkjan Ochtman -
r8013:9ec25db3 default
parent child Browse files
Show More
@@ -862,36 +862,40 b' class changeset_templater(changeset_prin'
862 props = props.copy()
862 props = props.copy()
863 props.update(defprops)
863 props.update(defprops)
864
864
865 # find correct templates for current mode
866
867 tmplmodes = [
868 (True, None),
869 (self.ui.verbose, 'verbose'),
870 (self.ui.quiet, 'quiet'),
871 (self.ui.debugflag, 'debug'),
872 ]
873
874 types = {'header': '', 'changeset': 'changeset'}
875 for mode, postfix in tmplmodes:
876 for type in types:
877 cur = postfix and ('%s_%s' % (type, postfix)) or type
878 if mode and cur in self.t:
879 types[type] = cur
880
865 try:
881 try:
866 if self.ui.debugflag and 'header_debug' in self.t:
882
867 key = 'header_debug'
883 # write header
868 elif self.ui.quiet and 'header_quiet' in self.t:
884 if types['header']:
869 key = 'header_quiet'
885 h = templater.stringify(self.t(types['header'], **props))
870 elif self.ui.verbose and 'header_verbose' in self.t:
871 key = 'header_verbose'
872 elif 'header' in self.t:
873 key = 'header'
874 else:
875 key = ''
876 if key:
877 h = templater.stringify(self.t(key, **props))
878 if self.buffered:
886 if self.buffered:
879 self.header[ctx.rev()] = h
887 self.header[ctx.rev()] = h
880 else:
888 else:
881 self.ui.write(h)
889 self.ui.write(h)
882 if self.ui.debugflag and 'changeset_debug' in self.t:
890
883 key = 'changeset_debug'
891 # write changeset metadata, then patch if requested
884 elif self.ui.quiet and 'changeset_quiet' in self.t:
892 key = types['changeset']
885 key = 'changeset_quiet'
886 elif self.ui.verbose and 'changeset_verbose' in self.t:
887 key = 'changeset_verbose'
888 else:
889 key = 'changeset'
890 self.ui.write(templater.stringify(self.t(key, **props)))
893 self.ui.write(templater.stringify(self.t(key, **props)))
891 self.showpatch(ctx.node())
894 self.showpatch(ctx.node())
895
892 except KeyError, inst:
896 except KeyError, inst:
893 raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile,
897 msg = _("%s: no key named '%s'")
894 inst.args[0]))
898 raise util.Abort(msg % (self.t.mapfile, inst.args[0]))
895 except SyntaxError, inst:
899 except SyntaxError, inst:
896 raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0]))
900 raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0]))
897
901
General Comments 0
You need to be logged in to leave comments. Login now