comparison mercurial/cmdutil.py @ 25511:c2a4dfe2a336

formatter: move most of template option helper to formatter We want to share this function between formatter and cmdutils. It doesn't belong in templater because it imports knowledge of ui layers that shouldn't be there. We'd prefer cmdutil to layer on the formatter rather than vice-versa. Since the formatter is the handler for -T options for all non-log commands, let's move the helper there. We leave the bits specific to the old --style option behind.
author Matt Mackall <mpm@selenic.com>
date Wed, 10 Jun 2015 14:29:13 -0500
parents aaede04c0ba6
children dcc56e10c23b
comparison
equal deleted inserted replaced
25510:dd511b5cb818 25511:c2a4dfe2a336
12 import match as matchmod 12 import match as matchmod
13 import context, repair, graphmod, revset, phases, obsolete, pathutil 13 import context, repair, graphmod, revset, phases, obsolete, pathutil
14 import changelog 14 import changelog
15 import bookmarks 15 import bookmarks
16 import encoding 16 import encoding
17 import formatter
17 import crecord as crecordmod 18 import crecord as crecordmod
18 import lock as lockmod 19 import lock as lockmod
19 20
20 def ishunk(x): 21 def ishunk(x):
21 hunkclasses = (crecordmod.uihunk, patch.recordhunk) 22 hunkclasses = (crecordmod.uihunk, patch.recordhunk)
1491 return None, mapfile 1492 return None, mapfile
1492 1493
1493 if not tmpl: 1494 if not tmpl:
1494 return None, None 1495 return None, None
1495 1496
1496 # looks like a literal template? 1497 return formatter.lookuptemplate(ui, 'changeset', tmpl)
1497 if '{' in tmpl:
1498 return tmpl, None
1499
1500 # perhaps a stock style?
1501 if not os.path.split(tmpl)[0]:
1502 mapname = (templater.templatepath('map-cmdline.' + tmpl)
1503 or templater.templatepath(tmpl))
1504 if mapname and os.path.isfile(mapname):
1505 return None, mapname
1506
1507 # perhaps it's a reference to [templates]
1508 t = ui.config('templates', tmpl)
1509 if t:
1510 try:
1511 tmpl = templater.unquotestring(t)
1512 except SyntaxError:
1513 tmpl = t
1514 return tmpl, None
1515
1516 if tmpl == 'list':
1517 ui.write(_("available styles: %s\n") % templater.stylelist())
1518 raise util.Abort(_("specify a template"))
1519
1520 # perhaps it's a path to a map or a template
1521 if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl):
1522 # is it a mapfile for a style?
1523 if os.path.basename(tmpl).startswith("map-"):
1524 return None, os.path.realpath(tmpl)
1525 tmpl = open(tmpl).read()
1526 return tmpl, None
1527
1528 # constant string?
1529 return tmpl, None
1530 1498
1531 def show_changeset(ui, repo, opts, buffered=False): 1499 def show_changeset(ui, repo, opts, buffered=False):
1532 """show one changeset using template or regular display. 1500 """show one changeset using template or regular display.
1533 1501
1534 Display format will be the first non-empty hit of: 1502 Display format will be the first non-empty hit of: