##// END OF EJS Templates
templater: use unfiltered changelog to calculate shortest() at constant time...
Yuya Nishihara -
r30232:362740e0 stable
parent child Browse files
Show More
@@ -1,1264 +1,1267
1 1 # templater.py - template expansion for output
2 2 #
3 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from __future__ import absolute_import
9 9
10 10 import os
11 11 import re
12 12 import types
13 13
14 14 from .i18n import _
15 15 from . import (
16 16 config,
17 17 error,
18 18 minirst,
19 19 parser,
20 20 registrar,
21 21 revset as revsetmod,
22 22 templatefilters,
23 23 templatekw,
24 24 util,
25 25 )
26 26
27 27 # template parsing
28 28
29 29 elements = {
30 30 # token-type: binding-strength, primary, prefix, infix, suffix
31 31 "(": (20, None, ("group", 1, ")"), ("func", 1, ")"), None),
32 32 ",": (2, None, None, ("list", 2), None),
33 33 "|": (5, None, None, ("|", 5), None),
34 34 "%": (6, None, None, ("%", 6), None),
35 35 ")": (0, None, None, None, None),
36 36 "+": (3, None, None, ("+", 3), None),
37 37 "-": (3, None, ("negate", 10), ("-", 3), None),
38 38 "*": (4, None, None, ("*", 4), None),
39 39 "/": (4, None, None, ("/", 4), None),
40 40 "integer": (0, "integer", None, None, None),
41 41 "symbol": (0, "symbol", None, None, None),
42 42 "string": (0, "string", None, None, None),
43 43 "template": (0, "template", None, None, None),
44 44 "end": (0, None, None, None, None),
45 45 }
46 46
47 47 def tokenize(program, start, end, term=None):
48 48 """Parse a template expression into a stream of tokens, which must end
49 49 with term if specified"""
50 50 pos = start
51 51 while pos < end:
52 52 c = program[pos]
53 53 if c.isspace(): # skip inter-token whitespace
54 54 pass
55 55 elif c in "(,)%|+-*/": # handle simple operators
56 56 yield (c, None, pos)
57 57 elif c in '"\'': # handle quoted templates
58 58 s = pos + 1
59 59 data, pos = _parsetemplate(program, s, end, c)
60 60 yield ('template', data, s)
61 61 pos -= 1
62 62 elif c == 'r' and program[pos:pos + 2] in ("r'", 'r"'):
63 63 # handle quoted strings
64 64 c = program[pos + 1]
65 65 s = pos = pos + 2
66 66 while pos < end: # find closing quote
67 67 d = program[pos]
68 68 if d == '\\': # skip over escaped characters
69 69 pos += 2
70 70 continue
71 71 if d == c:
72 72 yield ('string', program[s:pos], s)
73 73 break
74 74 pos += 1
75 75 else:
76 76 raise error.ParseError(_("unterminated string"), s)
77 77 elif c.isdigit():
78 78 s = pos
79 79 while pos < end:
80 80 d = program[pos]
81 81 if not d.isdigit():
82 82 break
83 83 pos += 1
84 84 yield ('integer', program[s:pos], s)
85 85 pos -= 1
86 86 elif (c == '\\' and program[pos:pos + 2] in (r"\'", r'\"')
87 87 or c == 'r' and program[pos:pos + 3] in (r"r\'", r'r\"')):
88 88 # handle escaped quoted strings for compatibility with 2.9.2-3.4,
89 89 # where some of nested templates were preprocessed as strings and
90 90 # then compiled. therefore, \"...\" was allowed. (issue4733)
91 91 #
92 92 # processing flow of _evalifliteral() at 5ab28a2e9962:
93 93 # outer template string -> stringify() -> compiletemplate()
94 94 # ------------------------ ------------ ------------------
95 95 # {f("\\\\ {g(\"\\\"\")}"} \\ {g("\"")} [r'\\', {g("\"")}]
96 96 # ~~~~~~~~
97 97 # escaped quoted string
98 98 if c == 'r':
99 99 pos += 1
100 100 token = 'string'
101 101 else:
102 102 token = 'template'
103 103 quote = program[pos:pos + 2]
104 104 s = pos = pos + 2
105 105 while pos < end: # find closing escaped quote
106 106 if program.startswith('\\\\\\', pos, end):
107 107 pos += 4 # skip over double escaped characters
108 108 continue
109 109 if program.startswith(quote, pos, end):
110 110 # interpret as if it were a part of an outer string
111 111 data = parser.unescapestr(program[s:pos])
112 112 if token == 'template':
113 113 data = _parsetemplate(data, 0, len(data))[0]
114 114 yield (token, data, s)
115 115 pos += 1
116 116 break
117 117 pos += 1
118 118 else:
119 119 raise error.ParseError(_("unterminated string"), s)
120 120 elif c.isalnum() or c in '_':
121 121 s = pos
122 122 pos += 1
123 123 while pos < end: # find end of symbol
124 124 d = program[pos]
125 125 if not (d.isalnum() or d == "_"):
126 126 break
127 127 pos += 1
128 128 sym = program[s:pos]
129 129 yield ('symbol', sym, s)
130 130 pos -= 1
131 131 elif c == term:
132 132 yield ('end', None, pos + 1)
133 133 return
134 134 else:
135 135 raise error.ParseError(_("syntax error"), pos)
136 136 pos += 1
137 137 if term:
138 138 raise error.ParseError(_("unterminated template expansion"), start)
139 139 yield ('end', None, pos)
140 140
141 141 def _parsetemplate(tmpl, start, stop, quote=''):
142 142 r"""
143 143 >>> _parsetemplate('foo{bar}"baz', 0, 12)
144 144 ([('string', 'foo'), ('symbol', 'bar'), ('string', '"baz')], 12)
145 145 >>> _parsetemplate('foo{bar}"baz', 0, 12, quote='"')
146 146 ([('string', 'foo'), ('symbol', 'bar')], 9)
147 147 >>> _parsetemplate('foo"{bar}', 0, 9, quote='"')
148 148 ([('string', 'foo')], 4)
149 149 >>> _parsetemplate(r'foo\"bar"baz', 0, 12, quote='"')
150 150 ([('string', 'foo"'), ('string', 'bar')], 9)
151 151 >>> _parsetemplate(r'foo\\"bar', 0, 10, quote='"')
152 152 ([('string', 'foo\\')], 6)
153 153 """
154 154 parsed = []
155 155 sepchars = '{' + quote
156 156 pos = start
157 157 p = parser.parser(elements)
158 158 while pos < stop:
159 159 n = min((tmpl.find(c, pos, stop) for c in sepchars),
160 160 key=lambda n: (n < 0, n))
161 161 if n < 0:
162 162 parsed.append(('string', parser.unescapestr(tmpl[pos:stop])))
163 163 pos = stop
164 164 break
165 165 c = tmpl[n]
166 166 bs = (n - pos) - len(tmpl[pos:n].rstrip('\\'))
167 167 if bs % 2 == 1:
168 168 # escaped (e.g. '\{', '\\\{', but not '\\{')
169 169 parsed.append(('string', parser.unescapestr(tmpl[pos:n - 1]) + c))
170 170 pos = n + 1
171 171 continue
172 172 if n > pos:
173 173 parsed.append(('string', parser.unescapestr(tmpl[pos:n])))
174 174 if c == quote:
175 175 return parsed, n + 1
176 176
177 177 parseres, pos = p.parse(tokenize(tmpl, n + 1, stop, '}'))
178 178 parsed.append(parseres)
179 179
180 180 if quote:
181 181 raise error.ParseError(_("unterminated string"), start)
182 182 return parsed, pos
183 183
184 184 def _unnesttemplatelist(tree):
185 185 """Expand list of templates to node tuple
186 186
187 187 >>> def f(tree):
188 188 ... print prettyformat(_unnesttemplatelist(tree))
189 189 >>> f(('template', []))
190 190 ('string', '')
191 191 >>> f(('template', [('string', 'foo')]))
192 192 ('string', 'foo')
193 193 >>> f(('template', [('string', 'foo'), ('symbol', 'rev')]))
194 194 (template
195 195 ('string', 'foo')
196 196 ('symbol', 'rev'))
197 197 >>> f(('template', [('symbol', 'rev')])) # template(rev) -> str
198 198 (template
199 199 ('symbol', 'rev'))
200 200 >>> f(('template', [('template', [('string', 'foo')])]))
201 201 ('string', 'foo')
202 202 """
203 203 if not isinstance(tree, tuple):
204 204 return tree
205 205 op = tree[0]
206 206 if op != 'template':
207 207 return (op,) + tuple(_unnesttemplatelist(x) for x in tree[1:])
208 208
209 209 assert len(tree) == 2
210 210 xs = tuple(_unnesttemplatelist(x) for x in tree[1])
211 211 if not xs:
212 212 return ('string', '') # empty template ""
213 213 elif len(xs) == 1 and xs[0][0] == 'string':
214 214 return xs[0] # fast path for string with no template fragment "x"
215 215 else:
216 216 return (op,) + xs
217 217
218 218 def parse(tmpl):
219 219 """Parse template string into tree"""
220 220 parsed, pos = _parsetemplate(tmpl, 0, len(tmpl))
221 221 assert pos == len(tmpl), 'unquoted template should be consumed'
222 222 return _unnesttemplatelist(('template', parsed))
223 223
224 224 def _parseexpr(expr):
225 225 """Parse a template expression into tree
226 226
227 227 >>> _parseexpr('"foo"')
228 228 ('string', 'foo')
229 229 >>> _parseexpr('foo(bar)')
230 230 ('func', ('symbol', 'foo'), ('symbol', 'bar'))
231 231 >>> _parseexpr('foo(')
232 232 Traceback (most recent call last):
233 233 ...
234 234 ParseError: ('not a prefix: end', 4)
235 235 >>> _parseexpr('"foo" "bar"')
236 236 Traceback (most recent call last):
237 237 ...
238 238 ParseError: ('invalid token', 7)
239 239 """
240 240 p = parser.parser(elements)
241 241 tree, pos = p.parse(tokenize(expr, 0, len(expr)))
242 242 if pos != len(expr):
243 243 raise error.ParseError(_('invalid token'), pos)
244 244 return _unnesttemplatelist(tree)
245 245
246 246 def prettyformat(tree):
247 247 return parser.prettyformat(tree, ('integer', 'string', 'symbol'))
248 248
249 249 def compileexp(exp, context, curmethods):
250 250 """Compile parsed template tree to (func, data) pair"""
251 251 t = exp[0]
252 252 if t in curmethods:
253 253 return curmethods[t](exp, context)
254 254 raise error.ParseError(_("unknown method '%s'") % t)
255 255
256 256 # template evaluation
257 257
258 258 def getsymbol(exp):
259 259 if exp[0] == 'symbol':
260 260 return exp[1]
261 261 raise error.ParseError(_("expected a symbol, got '%s'") % exp[0])
262 262
263 263 def getlist(x):
264 264 if not x:
265 265 return []
266 266 if x[0] == 'list':
267 267 return getlist(x[1]) + [x[2]]
268 268 return [x]
269 269
270 270 def gettemplate(exp, context):
271 271 """Compile given template tree or load named template from map file;
272 272 returns (func, data) pair"""
273 273 if exp[0] in ('template', 'string'):
274 274 return compileexp(exp, context, methods)
275 275 if exp[0] == 'symbol':
276 276 # unlike runsymbol(), here 'symbol' is always taken as template name
277 277 # even if it exists in mapping. this allows us to override mapping
278 278 # by web templates, e.g. 'changelogtag' is redefined in map file.
279 279 return context._load(exp[1])
280 280 raise error.ParseError(_("expected template specifier"))
281 281
282 282 def evalfuncarg(context, mapping, arg):
283 283 func, data = arg
284 284 # func() may return string, generator of strings or arbitrary object such
285 285 # as date tuple, but filter does not want generator.
286 286 thing = func(context, mapping, data)
287 287 if isinstance(thing, types.GeneratorType):
288 288 thing = stringify(thing)
289 289 return thing
290 290
291 291 def evalboolean(context, mapping, arg):
292 292 """Evaluate given argument as boolean, but also takes boolean literals"""
293 293 func, data = arg
294 294 if func is runsymbol:
295 295 thing = func(context, mapping, data, default=None)
296 296 if thing is None:
297 297 # not a template keyword, takes as a boolean literal
298 298 thing = util.parsebool(data)
299 299 else:
300 300 thing = func(context, mapping, data)
301 301 if isinstance(thing, bool):
302 302 return thing
303 303 # other objects are evaluated as strings, which means 0 is True, but
304 304 # empty dict/list should be False as they are expected to be ''
305 305 return bool(stringify(thing))
306 306
307 307 def evalinteger(context, mapping, arg, err):
308 308 v = evalfuncarg(context, mapping, arg)
309 309 try:
310 310 return int(v)
311 311 except (TypeError, ValueError):
312 312 raise error.ParseError(err)
313 313
314 314 def evalstring(context, mapping, arg):
315 315 func, data = arg
316 316 return stringify(func(context, mapping, data))
317 317
318 318 def evalstringliteral(context, mapping, arg):
319 319 """Evaluate given argument as string template, but returns symbol name
320 320 if it is unknown"""
321 321 func, data = arg
322 322 if func is runsymbol:
323 323 thing = func(context, mapping, data, default=data)
324 324 else:
325 325 thing = func(context, mapping, data)
326 326 return stringify(thing)
327 327
328 328 def runinteger(context, mapping, data):
329 329 return int(data)
330 330
331 331 def runstring(context, mapping, data):
332 332 return data
333 333
334 334 def _recursivesymbolblocker(key):
335 335 def showrecursion(**args):
336 336 raise error.Abort(_("recursive reference '%s' in template") % key)
337 337 return showrecursion
338 338
339 339 def _runrecursivesymbol(context, mapping, key):
340 340 raise error.Abort(_("recursive reference '%s' in template") % key)
341 341
342 342 def runsymbol(context, mapping, key, default=''):
343 343 v = mapping.get(key)
344 344 if v is None:
345 345 v = context._defaults.get(key)
346 346 if v is None:
347 347 # put poison to cut recursion. we can't move this to parsing phase
348 348 # because "x = {x}" is allowed if "x" is a keyword. (issue4758)
349 349 safemapping = mapping.copy()
350 350 safemapping[key] = _recursivesymbolblocker(key)
351 351 try:
352 352 v = context.process(key, safemapping)
353 353 except TemplateNotFound:
354 354 v = default
355 355 if callable(v):
356 356 return v(**mapping)
357 357 return v
358 358
359 359 def buildtemplate(exp, context):
360 360 ctmpl = [compileexp(e, context, methods) for e in exp[1:]]
361 361 return (runtemplate, ctmpl)
362 362
363 363 def runtemplate(context, mapping, template):
364 364 for func, data in template:
365 365 yield func(context, mapping, data)
366 366
367 367 def buildfilter(exp, context):
368 368 arg = compileexp(exp[1], context, methods)
369 369 n = getsymbol(exp[2])
370 370 if n in context._filters:
371 371 filt = context._filters[n]
372 372 return (runfilter, (arg, filt))
373 373 if n in funcs:
374 374 f = funcs[n]
375 375 return (f, [arg])
376 376 raise error.ParseError(_("unknown function '%s'") % n)
377 377
378 378 def runfilter(context, mapping, data):
379 379 arg, filt = data
380 380 thing = evalfuncarg(context, mapping, arg)
381 381 try:
382 382 return filt(thing)
383 383 except (ValueError, AttributeError, TypeError):
384 384 if isinstance(arg[1], tuple):
385 385 dt = arg[1][1]
386 386 else:
387 387 dt = arg[1]
388 388 raise error.Abort(_("template filter '%s' is not compatible with "
389 389 "keyword '%s'") % (filt.func_name, dt))
390 390
391 391 def buildmap(exp, context):
392 392 func, data = compileexp(exp[1], context, methods)
393 393 tfunc, tdata = gettemplate(exp[2], context)
394 394 return (runmap, (func, data, tfunc, tdata))
395 395
396 396 def runmap(context, mapping, data):
397 397 func, data, tfunc, tdata = data
398 398 d = func(context, mapping, data)
399 399 if util.safehasattr(d, 'itermaps'):
400 400 diter = d.itermaps()
401 401 else:
402 402 try:
403 403 diter = iter(d)
404 404 except TypeError:
405 405 if func is runsymbol:
406 406 raise error.ParseError(_("keyword '%s' is not iterable") % data)
407 407 else:
408 408 raise error.ParseError(_("%r is not iterable") % d)
409 409
410 410 for i in diter:
411 411 lm = mapping.copy()
412 412 if isinstance(i, dict):
413 413 lm.update(i)
414 414 lm['originalnode'] = mapping.get('node')
415 415 yield tfunc(context, lm, tdata)
416 416 else:
417 417 # v is not an iterable of dicts, this happen when 'key'
418 418 # has been fully expanded already and format is useless.
419 419 # If so, return the expanded value.
420 420 yield i
421 421
422 422 def buildnegate(exp, context):
423 423 arg = compileexp(exp[1], context, exprmethods)
424 424 return (runnegate, arg)
425 425
426 426 def runnegate(context, mapping, data):
427 427 data = evalinteger(context, mapping, data,
428 428 _('negation needs an integer argument'))
429 429 return -data
430 430
431 431 def buildarithmetic(exp, context, func):
432 432 left = compileexp(exp[1], context, exprmethods)
433 433 right = compileexp(exp[2], context, exprmethods)
434 434 return (runarithmetic, (func, left, right))
435 435
436 436 def runarithmetic(context, mapping, data):
437 437 func, left, right = data
438 438 left = evalinteger(context, mapping, left,
439 439 _('arithmetic only defined on integers'))
440 440 right = evalinteger(context, mapping, right,
441 441 _('arithmetic only defined on integers'))
442 442 try:
443 443 return func(left, right)
444 444 except ZeroDivisionError:
445 445 raise error.Abort(_('division by zero is not defined'))
446 446
447 447 def buildfunc(exp, context):
448 448 n = getsymbol(exp[1])
449 449 args = [compileexp(x, context, exprmethods) for x in getlist(exp[2])]
450 450 if n in funcs:
451 451 f = funcs[n]
452 452 return (f, args)
453 453 if n in context._filters:
454 454 if len(args) != 1:
455 455 raise error.ParseError(_("filter %s expects one argument") % n)
456 456 f = context._filters[n]
457 457 return (runfilter, (args[0], f))
458 458 raise error.ParseError(_("unknown function '%s'") % n)
459 459
460 460 # dict of template built-in functions
461 461 funcs = {}
462 462
463 463 templatefunc = registrar.templatefunc(funcs)
464 464
465 465 @templatefunc('date(date[, fmt])')
466 466 def date(context, mapping, args):
467 467 """Format a date. See :hg:`help dates` for formatting
468 468 strings. The default is a Unix date format, including the timezone:
469 469 "Mon Sep 04 15:13:13 2006 0700"."""
470 470 if not (1 <= len(args) <= 2):
471 471 # i18n: "date" is a keyword
472 472 raise error.ParseError(_("date expects one or two arguments"))
473 473
474 474 date = evalfuncarg(context, mapping, args[0])
475 475 fmt = None
476 476 if len(args) == 2:
477 477 fmt = evalstring(context, mapping, args[1])
478 478 try:
479 479 if fmt is None:
480 480 return util.datestr(date)
481 481 else:
482 482 return util.datestr(date, fmt)
483 483 except (TypeError, ValueError):
484 484 # i18n: "date" is a keyword
485 485 raise error.ParseError(_("date expects a date information"))
486 486
487 487 @templatefunc('diff([includepattern [, excludepattern]])')
488 488 def diff(context, mapping, args):
489 489 """Show a diff, optionally
490 490 specifying files to include or exclude."""
491 491 if len(args) > 2:
492 492 # i18n: "diff" is a keyword
493 493 raise error.ParseError(_("diff expects zero, one, or two arguments"))
494 494
495 495 def getpatterns(i):
496 496 if i < len(args):
497 497 s = evalstring(context, mapping, args[i]).strip()
498 498 if s:
499 499 return [s]
500 500 return []
501 501
502 502 ctx = mapping['ctx']
503 503 chunks = ctx.diff(match=ctx.match([], getpatterns(0), getpatterns(1)))
504 504
505 505 return ''.join(chunks)
506 506
507 507 @templatefunc('files(pattern)')
508 508 def files(context, mapping, args):
509 509 """All files of the current changeset matching the pattern. See
510 510 :hg:`help patterns`."""
511 511 if not len(args) == 1:
512 512 # i18n: "files" is a keyword
513 513 raise error.ParseError(_("files expects one argument"))
514 514
515 515 raw = evalstring(context, mapping, args[0])
516 516 ctx = mapping['ctx']
517 517 m = ctx.match([raw])
518 518 files = list(ctx.matches(m))
519 519 return templatekw.showlist("file", files, **mapping)
520 520
521 521 @templatefunc('fill(text[, width[, initialident[, hangindent]]])')
522 522 def fill(context, mapping, args):
523 523 """Fill many
524 524 paragraphs with optional indentation. See the "fill" filter."""
525 525 if not (1 <= len(args) <= 4):
526 526 # i18n: "fill" is a keyword
527 527 raise error.ParseError(_("fill expects one to four arguments"))
528 528
529 529 text = evalstring(context, mapping, args[0])
530 530 width = 76
531 531 initindent = ''
532 532 hangindent = ''
533 533 if 2 <= len(args) <= 4:
534 534 width = evalinteger(context, mapping, args[1],
535 535 # i18n: "fill" is a keyword
536 536 _("fill expects an integer width"))
537 537 try:
538 538 initindent = evalstring(context, mapping, args[2])
539 539 hangindent = evalstring(context, mapping, args[3])
540 540 except IndexError:
541 541 pass
542 542
543 543 return templatefilters.fill(text, width, initindent, hangindent)
544 544
545 545 @templatefunc('pad(text, width[, fillchar=\' \'[, left=False]])')
546 546 def pad(context, mapping, args):
547 547 """Pad text with a
548 548 fill character."""
549 549 if not (2 <= len(args) <= 4):
550 550 # i18n: "pad" is a keyword
551 551 raise error.ParseError(_("pad() expects two to four arguments"))
552 552
553 553 width = evalinteger(context, mapping, args[1],
554 554 # i18n: "pad" is a keyword
555 555 _("pad() expects an integer width"))
556 556
557 557 text = evalstring(context, mapping, args[0])
558 558
559 559 left = False
560 560 fillchar = ' '
561 561 if len(args) > 2:
562 562 fillchar = evalstring(context, mapping, args[2])
563 563 if len(args) > 3:
564 564 left = evalboolean(context, mapping, args[3])
565 565
566 566 if left:
567 567 return text.rjust(width, fillchar)
568 568 else:
569 569 return text.ljust(width, fillchar)
570 570
571 571 @templatefunc('indent(text, indentchars[, firstline])')
572 572 def indent(context, mapping, args):
573 573 """Indents all non-empty lines
574 574 with the characters given in the indentchars string. An optional
575 575 third parameter will override the indent for the first line only
576 576 if present."""
577 577 if not (2 <= len(args) <= 3):
578 578 # i18n: "indent" is a keyword
579 579 raise error.ParseError(_("indent() expects two or three arguments"))
580 580
581 581 text = evalstring(context, mapping, args[0])
582 582 indent = evalstring(context, mapping, args[1])
583 583
584 584 if len(args) == 3:
585 585 firstline = evalstring(context, mapping, args[2])
586 586 else:
587 587 firstline = indent
588 588
589 589 # the indent function doesn't indent the first line, so we do it here
590 590 return templatefilters.indent(firstline + text, indent)
591 591
592 592 @templatefunc('get(dict, key)')
593 593 def get(context, mapping, args):
594 594 """Get an attribute/key from an object. Some keywords
595 595 are complex types. This function allows you to obtain the value of an
596 596 attribute on these types."""
597 597 if len(args) != 2:
598 598 # i18n: "get" is a keyword
599 599 raise error.ParseError(_("get() expects two arguments"))
600 600
601 601 dictarg = evalfuncarg(context, mapping, args[0])
602 602 if not util.safehasattr(dictarg, 'get'):
603 603 # i18n: "get" is a keyword
604 604 raise error.ParseError(_("get() expects a dict as first argument"))
605 605
606 606 key = evalfuncarg(context, mapping, args[1])
607 607 return dictarg.get(key)
608 608
609 609 @templatefunc('if(expr, then[, else])')
610 610 def if_(context, mapping, args):
611 611 """Conditionally execute based on the result of
612 612 an expression."""
613 613 if not (2 <= len(args) <= 3):
614 614 # i18n: "if" is a keyword
615 615 raise error.ParseError(_("if expects two or three arguments"))
616 616
617 617 test = evalboolean(context, mapping, args[0])
618 618 if test:
619 619 yield args[1][0](context, mapping, args[1][1])
620 620 elif len(args) == 3:
621 621 yield args[2][0](context, mapping, args[2][1])
622 622
623 623 @templatefunc('ifcontains(needle, haystack, then[, else])')
624 624 def ifcontains(context, mapping, args):
625 625 """Conditionally execute based
626 626 on whether the item "needle" is in "haystack"."""
627 627 if not (3 <= len(args) <= 4):
628 628 # i18n: "ifcontains" is a keyword
629 629 raise error.ParseError(_("ifcontains expects three or four arguments"))
630 630
631 631 needle = evalstring(context, mapping, args[0])
632 632 haystack = evalfuncarg(context, mapping, args[1])
633 633
634 634 if needle in haystack:
635 635 yield args[2][0](context, mapping, args[2][1])
636 636 elif len(args) == 4:
637 637 yield args[3][0](context, mapping, args[3][1])
638 638
639 639 @templatefunc('ifeq(expr1, expr2, then[, else])')
640 640 def ifeq(context, mapping, args):
641 641 """Conditionally execute based on
642 642 whether 2 items are equivalent."""
643 643 if not (3 <= len(args) <= 4):
644 644 # i18n: "ifeq" is a keyword
645 645 raise error.ParseError(_("ifeq expects three or four arguments"))
646 646
647 647 test = evalstring(context, mapping, args[0])
648 648 match = evalstring(context, mapping, args[1])
649 649 if test == match:
650 650 yield args[2][0](context, mapping, args[2][1])
651 651 elif len(args) == 4:
652 652 yield args[3][0](context, mapping, args[3][1])
653 653
654 654 @templatefunc('join(list, sep)')
655 655 def join(context, mapping, args):
656 656 """Join items in a list with a delimiter."""
657 657 if not (1 <= len(args) <= 2):
658 658 # i18n: "join" is a keyword
659 659 raise error.ParseError(_("join expects one or two arguments"))
660 660
661 661 joinset = args[0][0](context, mapping, args[0][1])
662 662 if util.safehasattr(joinset, 'itermaps'):
663 663 jf = joinset.joinfmt
664 664 joinset = [jf(x) for x in joinset.itermaps()]
665 665
666 666 joiner = " "
667 667 if len(args) > 1:
668 668 joiner = evalstring(context, mapping, args[1])
669 669
670 670 first = True
671 671 for x in joinset:
672 672 if first:
673 673 first = False
674 674 else:
675 675 yield joiner
676 676 yield x
677 677
678 678 @templatefunc('label(label, expr)')
679 679 def label(context, mapping, args):
680 680 """Apply a label to generated content. Content with
681 681 a label applied can result in additional post-processing, such as
682 682 automatic colorization."""
683 683 if len(args) != 2:
684 684 # i18n: "label" is a keyword
685 685 raise error.ParseError(_("label expects two arguments"))
686 686
687 687 ui = mapping['ui']
688 688 thing = evalstring(context, mapping, args[1])
689 689 # preserve unknown symbol as literal so effects like 'red', 'bold',
690 690 # etc. don't need to be quoted
691 691 label = evalstringliteral(context, mapping, args[0])
692 692
693 693 return ui.label(thing, label)
694 694
695 695 @templatefunc('latesttag([pattern])')
696 696 def latesttag(context, mapping, args):
697 697 """The global tags matching the given pattern on the
698 698 most recent globally tagged ancestor of this changeset."""
699 699 if len(args) > 1:
700 700 # i18n: "latesttag" is a keyword
701 701 raise error.ParseError(_("latesttag expects at most one argument"))
702 702
703 703 pattern = None
704 704 if len(args) == 1:
705 705 pattern = evalstring(context, mapping, args[0])
706 706
707 707 return templatekw.showlatesttags(pattern, **mapping)
708 708
709 709 @templatefunc('localdate(date[, tz])')
710 710 def localdate(context, mapping, args):
711 711 """Converts a date to the specified timezone.
712 712 The default is local date."""
713 713 if not (1 <= len(args) <= 2):
714 714 # i18n: "localdate" is a keyword
715 715 raise error.ParseError(_("localdate expects one or two arguments"))
716 716
717 717 date = evalfuncarg(context, mapping, args[0])
718 718 try:
719 719 date = util.parsedate(date)
720 720 except AttributeError: # not str nor date tuple
721 721 # i18n: "localdate" is a keyword
722 722 raise error.ParseError(_("localdate expects a date information"))
723 723 if len(args) >= 2:
724 724 tzoffset = None
725 725 tz = evalfuncarg(context, mapping, args[1])
726 726 if isinstance(tz, str):
727 727 tzoffset, remainder = util.parsetimezone(tz)
728 728 if remainder:
729 729 tzoffset = None
730 730 if tzoffset is None:
731 731 try:
732 732 tzoffset = int(tz)
733 733 except (TypeError, ValueError):
734 734 # i18n: "localdate" is a keyword
735 735 raise error.ParseError(_("localdate expects a timezone"))
736 736 else:
737 737 tzoffset = util.makedate()[1]
738 738 return (date[0], tzoffset)
739 739
740 740 @templatefunc('mod(a, b)')
741 741 def mod(context, mapping, args):
742 742 """Calculate a mod b such that a / b + a mod b == a"""
743 743 if not len(args) == 2:
744 744 # i18n: "mod" is a keyword
745 745 raise error.ParseError(_("mod expects two arguments"))
746 746
747 747 func = lambda a, b: a % b
748 748 return runarithmetic(context, mapping, (func, args[0], args[1]))
749 749
750 750 @templatefunc('relpath(path)')
751 751 def relpath(context, mapping, args):
752 752 """Convert a repository-absolute path into a filesystem path relative to
753 753 the current working directory."""
754 754 if len(args) != 1:
755 755 # i18n: "relpath" is a keyword
756 756 raise error.ParseError(_("relpath expects one argument"))
757 757
758 758 repo = mapping['ctx'].repo()
759 759 path = evalstring(context, mapping, args[0])
760 760 return repo.pathto(path)
761 761
762 762 @templatefunc('revset(query[, formatargs...])')
763 763 def revset(context, mapping, args):
764 764 """Execute a revision set query. See
765 765 :hg:`help revset`."""
766 766 if not len(args) > 0:
767 767 # i18n: "revset" is a keyword
768 768 raise error.ParseError(_("revset expects one or more arguments"))
769 769
770 770 raw = evalstring(context, mapping, args[0])
771 771 ctx = mapping['ctx']
772 772 repo = ctx.repo()
773 773
774 774 def query(expr):
775 775 m = revsetmod.match(repo.ui, expr)
776 776 return m(repo)
777 777
778 778 if len(args) > 1:
779 779 formatargs = [evalfuncarg(context, mapping, a) for a in args[1:]]
780 780 revs = query(revsetmod.formatspec(raw, *formatargs))
781 781 revs = list(revs)
782 782 else:
783 783 revsetcache = mapping['cache'].setdefault("revsetcache", {})
784 784 if raw in revsetcache:
785 785 revs = revsetcache[raw]
786 786 else:
787 787 revs = query(raw)
788 788 revs = list(revs)
789 789 revsetcache[raw] = revs
790 790
791 791 return templatekw.showrevslist("revision", revs, **mapping)
792 792
793 793 @templatefunc('rstdoc(text, style)')
794 794 def rstdoc(context, mapping, args):
795 795 """Format ReStructuredText."""
796 796 if len(args) != 2:
797 797 # i18n: "rstdoc" is a keyword
798 798 raise error.ParseError(_("rstdoc expects two arguments"))
799 799
800 800 text = evalstring(context, mapping, args[0])
801 801 style = evalstring(context, mapping, args[1])
802 802
803 803 return minirst.format(text, style=style, keep=['verbose'])
804 804
805 805 @templatefunc('separate(sep, args)')
806 806 def separate(context, mapping, args):
807 807 """Add a separator between non-empty arguments."""
808 808 if not args:
809 809 # i18n: "separate" is a keyword
810 810 raise error.ParseError(_("separate expects at least one argument"))
811 811
812 812 sep = evalstring(context, mapping, args[0])
813 813 first = True
814 814 for arg in args[1:]:
815 815 argstr = evalstring(context, mapping, arg)
816 816 if not argstr:
817 817 continue
818 818 if first:
819 819 first = False
820 820 else:
821 821 yield sep
822 822 yield argstr
823 823
824 824 @templatefunc('shortest(node, minlength=4)')
825 825 def shortest(context, mapping, args):
826 826 """Obtain the shortest representation of
827 827 a node."""
828 828 if not (1 <= len(args) <= 2):
829 829 # i18n: "shortest" is a keyword
830 830 raise error.ParseError(_("shortest() expects one or two arguments"))
831 831
832 832 node = evalstring(context, mapping, args[0])
833 833
834 834 minlength = 4
835 835 if len(args) > 1:
836 836 minlength = evalinteger(context, mapping, args[1],
837 837 # i18n: "shortest" is a keyword
838 838 _("shortest() expects an integer minlength"))
839 839
840 cl = mapping['ctx']._repo.changelog
840 # _partialmatch() of filtered changelog could take O(len(repo)) time,
841 # which would be unacceptably slow. so we look for hash collision in
842 # unfiltered space, which means some hashes may be slightly longer.
843 cl = mapping['ctx']._repo.unfiltered().changelog
841 844 def isvalid(test):
842 845 try:
843 846 if cl._partialmatch(test) is None:
844 847 return False
845 848
846 849 try:
847 850 i = int(test)
848 851 # if we are a pure int, then starting with zero will not be
849 852 # confused as a rev; or, obviously, if the int is larger than
850 853 # the value of the tip rev
851 854 if test[0] == '0' or i > len(cl):
852 855 return True
853 856 return False
854 857 except ValueError:
855 858 return True
856 859 except error.RevlogError:
857 860 return False
858 861
859 862 shortest = node
860 863 startlength = max(6, minlength)
861 864 length = startlength
862 865 while True:
863 866 test = node[:length]
864 867 if isvalid(test):
865 868 shortest = test
866 869 if length == minlength or length > startlength:
867 870 return shortest
868 871 length -= 1
869 872 else:
870 873 length += 1
871 874 if len(shortest) <= length:
872 875 return shortest
873 876
874 877 @templatefunc('strip(text[, chars])')
875 878 def strip(context, mapping, args):
876 879 """Strip characters from a string. By default,
877 880 strips all leading and trailing whitespace."""
878 881 if not (1 <= len(args) <= 2):
879 882 # i18n: "strip" is a keyword
880 883 raise error.ParseError(_("strip expects one or two arguments"))
881 884
882 885 text = evalstring(context, mapping, args[0])
883 886 if len(args) == 2:
884 887 chars = evalstring(context, mapping, args[1])
885 888 return text.strip(chars)
886 889 return text.strip()
887 890
888 891 @templatefunc('sub(pattern, replacement, expression)')
889 892 def sub(context, mapping, args):
890 893 """Perform text substitution
891 894 using regular expressions."""
892 895 if len(args) != 3:
893 896 # i18n: "sub" is a keyword
894 897 raise error.ParseError(_("sub expects three arguments"))
895 898
896 899 pat = evalstring(context, mapping, args[0])
897 900 rpl = evalstring(context, mapping, args[1])
898 901 src = evalstring(context, mapping, args[2])
899 902 try:
900 903 patre = re.compile(pat)
901 904 except re.error:
902 905 # i18n: "sub" is a keyword
903 906 raise error.ParseError(_("sub got an invalid pattern: %s") % pat)
904 907 try:
905 908 yield patre.sub(rpl, src)
906 909 except re.error:
907 910 # i18n: "sub" is a keyword
908 911 raise error.ParseError(_("sub got an invalid replacement: %s") % rpl)
909 912
910 913 @templatefunc('startswith(pattern, text)')
911 914 def startswith(context, mapping, args):
912 915 """Returns the value from the "text" argument
913 916 if it begins with the content from the "pattern" argument."""
914 917 if len(args) != 2:
915 918 # i18n: "startswith" is a keyword
916 919 raise error.ParseError(_("startswith expects two arguments"))
917 920
918 921 patn = evalstring(context, mapping, args[0])
919 922 text = evalstring(context, mapping, args[1])
920 923 if text.startswith(patn):
921 924 return text
922 925 return ''
923 926
924 927 @templatefunc('word(number, text[, separator])')
925 928 def word(context, mapping, args):
926 929 """Return the nth word from a string."""
927 930 if not (2 <= len(args) <= 3):
928 931 # i18n: "word" is a keyword
929 932 raise error.ParseError(_("word expects two or three arguments, got %d")
930 933 % len(args))
931 934
932 935 num = evalinteger(context, mapping, args[0],
933 936 # i18n: "word" is a keyword
934 937 _("word expects an integer index"))
935 938 text = evalstring(context, mapping, args[1])
936 939 if len(args) == 3:
937 940 splitter = evalstring(context, mapping, args[2])
938 941 else:
939 942 splitter = None
940 943
941 944 tokens = text.split(splitter)
942 945 if num >= len(tokens) or num < -len(tokens):
943 946 return ''
944 947 else:
945 948 return tokens[num]
946 949
947 950 # methods to interpret function arguments or inner expressions (e.g. {_(x)})
948 951 exprmethods = {
949 952 "integer": lambda e, c: (runinteger, e[1]),
950 953 "string": lambda e, c: (runstring, e[1]),
951 954 "symbol": lambda e, c: (runsymbol, e[1]),
952 955 "template": buildtemplate,
953 956 "group": lambda e, c: compileexp(e[1], c, exprmethods),
954 957 # ".": buildmember,
955 958 "|": buildfilter,
956 959 "%": buildmap,
957 960 "func": buildfunc,
958 961 "+": lambda e, c: buildarithmetic(e, c, lambda a, b: a + b),
959 962 "-": lambda e, c: buildarithmetic(e, c, lambda a, b: a - b),
960 963 "negate": buildnegate,
961 964 "*": lambda e, c: buildarithmetic(e, c, lambda a, b: a * b),
962 965 "/": lambda e, c: buildarithmetic(e, c, lambda a, b: a // b),
963 966 }
964 967
965 968 # methods to interpret top-level template (e.g. {x}, {x|_}, {x % "y"})
966 969 methods = exprmethods.copy()
967 970 methods["integer"] = exprmethods["symbol"] # '{1}' as variable
968 971
969 972 class _aliasrules(parser.basealiasrules):
970 973 """Parsing and expansion rule set of template aliases"""
971 974 _section = _('template alias')
972 975 _parse = staticmethod(_parseexpr)
973 976
974 977 @staticmethod
975 978 def _trygetfunc(tree):
976 979 """Return (name, args) if tree is func(...) or ...|filter; otherwise
977 980 None"""
978 981 if tree[0] == 'func' and tree[1][0] == 'symbol':
979 982 return tree[1][1], getlist(tree[2])
980 983 if tree[0] == '|' and tree[2][0] == 'symbol':
981 984 return tree[2][1], [tree[1]]
982 985
983 986 def expandaliases(tree, aliases):
984 987 """Return new tree of aliases are expanded"""
985 988 aliasmap = _aliasrules.buildmap(aliases)
986 989 return _aliasrules.expand(aliasmap, tree)
987 990
988 991 # template engine
989 992
990 993 stringify = templatefilters.stringify
991 994
992 995 def _flatten(thing):
993 996 '''yield a single stream from a possibly nested set of iterators'''
994 997 if isinstance(thing, str):
995 998 yield thing
996 999 elif thing is None:
997 1000 pass
998 1001 elif not util.safehasattr(thing, '__iter__'):
999 1002 yield str(thing)
1000 1003 else:
1001 1004 for i in thing:
1002 1005 if isinstance(i, str):
1003 1006 yield i
1004 1007 elif i is None:
1005 1008 pass
1006 1009 elif not util.safehasattr(i, '__iter__'):
1007 1010 yield str(i)
1008 1011 else:
1009 1012 for j in _flatten(i):
1010 1013 yield j
1011 1014
1012 1015 def unquotestring(s):
1013 1016 '''unwrap quotes if any; otherwise returns unmodified string'''
1014 1017 if len(s) < 2 or s[0] not in "'\"" or s[0] != s[-1]:
1015 1018 return s
1016 1019 return s[1:-1]
1017 1020
1018 1021 class engine(object):
1019 1022 '''template expansion engine.
1020 1023
1021 1024 template expansion works like this. a map file contains key=value
1022 1025 pairs. if value is quoted, it is treated as string. otherwise, it
1023 1026 is treated as name of template file.
1024 1027
1025 1028 templater is asked to expand a key in map. it looks up key, and
1026 1029 looks for strings like this: {foo}. it expands {foo} by looking up
1027 1030 foo in map, and substituting it. expansion is recursive: it stops
1028 1031 when there is no more {foo} to replace.
1029 1032
1030 1033 expansion also allows formatting and filtering.
1031 1034
1032 1035 format uses key to expand each item in list. syntax is
1033 1036 {key%format}.
1034 1037
1035 1038 filter uses function to transform value. syntax is
1036 1039 {key|filter1|filter2|...}.'''
1037 1040
1038 1041 def __init__(self, loader, filters=None, defaults=None, aliases=()):
1039 1042 self._loader = loader
1040 1043 if filters is None:
1041 1044 filters = {}
1042 1045 self._filters = filters
1043 1046 if defaults is None:
1044 1047 defaults = {}
1045 1048 self._defaults = defaults
1046 1049 self._aliasmap = _aliasrules.buildmap(aliases)
1047 1050 self._cache = {} # key: (func, data)
1048 1051
1049 1052 def _load(self, t):
1050 1053 '''load, parse, and cache a template'''
1051 1054 if t not in self._cache:
1052 1055 # put poison to cut recursion while compiling 't'
1053 1056 self._cache[t] = (_runrecursivesymbol, t)
1054 1057 try:
1055 1058 x = parse(self._loader(t))
1056 1059 if self._aliasmap:
1057 1060 x = _aliasrules.expand(self._aliasmap, x)
1058 1061 self._cache[t] = compileexp(x, self, methods)
1059 1062 except: # re-raises
1060 1063 del self._cache[t]
1061 1064 raise
1062 1065 return self._cache[t]
1063 1066
1064 1067 def process(self, t, mapping):
1065 1068 '''Perform expansion. t is name of map element to expand.
1066 1069 mapping contains added elements for use during expansion. Is a
1067 1070 generator.'''
1068 1071 func, data = self._load(t)
1069 1072 return _flatten(func(self, mapping, data))
1070 1073
1071 1074 engines = {'default': engine}
1072 1075
1073 1076 def stylelist():
1074 1077 paths = templatepaths()
1075 1078 if not paths:
1076 1079 return _('no templates found, try `hg debuginstall` for more info')
1077 1080 dirlist = os.listdir(paths[0])
1078 1081 stylelist = []
1079 1082 for file in dirlist:
1080 1083 split = file.split(".")
1081 1084 if split[-1] in ('orig', 'rej'):
1082 1085 continue
1083 1086 if split[0] == "map-cmdline":
1084 1087 stylelist.append(split[1])
1085 1088 return ", ".join(sorted(stylelist))
1086 1089
1087 1090 def _readmapfile(mapfile):
1088 1091 """Load template elements from the given map file"""
1089 1092 if not os.path.exists(mapfile):
1090 1093 raise error.Abort(_("style '%s' not found") % mapfile,
1091 1094 hint=_("available styles: %s") % stylelist())
1092 1095
1093 1096 base = os.path.dirname(mapfile)
1094 1097 conf = config.config(includepaths=templatepaths())
1095 1098 conf.read(mapfile)
1096 1099
1097 1100 cache = {}
1098 1101 tmap = {}
1099 1102 for key, val in conf[''].items():
1100 1103 if not val:
1101 1104 raise error.ParseError(_('missing value'), conf.source('', key))
1102 1105 if val[0] in "'\"":
1103 1106 if val[0] != val[-1]:
1104 1107 raise error.ParseError(_('unmatched quotes'),
1105 1108 conf.source('', key))
1106 1109 cache[key] = unquotestring(val)
1107 1110 elif key == "__base__":
1108 1111 # treat as a pointer to a base class for this style
1109 1112 path = util.normpath(os.path.join(base, val))
1110 1113
1111 1114 # fallback check in template paths
1112 1115 if not os.path.exists(path):
1113 1116 for p in templatepaths():
1114 1117 p2 = util.normpath(os.path.join(p, val))
1115 1118 if os.path.isfile(p2):
1116 1119 path = p2
1117 1120 break
1118 1121 p3 = util.normpath(os.path.join(p2, "map"))
1119 1122 if os.path.isfile(p3):
1120 1123 path = p3
1121 1124 break
1122 1125
1123 1126 bcache, btmap = _readmapfile(path)
1124 1127 for k in bcache:
1125 1128 if k not in cache:
1126 1129 cache[k] = bcache[k]
1127 1130 for k in btmap:
1128 1131 if k not in tmap:
1129 1132 tmap[k] = btmap[k]
1130 1133 else:
1131 1134 val = 'default', val
1132 1135 if ':' in val[1]:
1133 1136 val = val[1].split(':', 1)
1134 1137 tmap[key] = val[0], os.path.join(base, val[1])
1135 1138 return cache, tmap
1136 1139
1137 1140 class TemplateNotFound(error.Abort):
1138 1141 pass
1139 1142
1140 1143 class templater(object):
1141 1144
1142 1145 def __init__(self, filters=None, defaults=None, cache=None, aliases=(),
1143 1146 minchunk=1024, maxchunk=65536):
1144 1147 '''set up template engine.
1145 1148 filters is dict of functions. each transforms a value into another.
1146 1149 defaults is dict of default map definitions.
1147 1150 aliases is list of alias (name, replacement) pairs.
1148 1151 '''
1149 1152 if filters is None:
1150 1153 filters = {}
1151 1154 if defaults is None:
1152 1155 defaults = {}
1153 1156 if cache is None:
1154 1157 cache = {}
1155 1158 self.cache = cache.copy()
1156 1159 self.map = {}
1157 1160 self.filters = templatefilters.filters.copy()
1158 1161 self.filters.update(filters)
1159 1162 self.defaults = defaults
1160 1163 self._aliases = aliases
1161 1164 self.minchunk, self.maxchunk = minchunk, maxchunk
1162 1165 self.ecache = {}
1163 1166
1164 1167 @classmethod
1165 1168 def frommapfile(cls, mapfile, filters=None, defaults=None, cache=None,
1166 1169 minchunk=1024, maxchunk=65536):
1167 1170 """Create templater from the specified map file"""
1168 1171 t = cls(filters, defaults, cache, [], minchunk, maxchunk)
1169 1172 cache, tmap = _readmapfile(mapfile)
1170 1173 t.cache.update(cache)
1171 1174 t.map = tmap
1172 1175 return t
1173 1176
1174 1177 def __contains__(self, key):
1175 1178 return key in self.cache or key in self.map
1176 1179
1177 1180 def load(self, t):
1178 1181 '''Get the template for the given template name. Use a local cache.'''
1179 1182 if t not in self.cache:
1180 1183 try:
1181 1184 self.cache[t] = util.readfile(self.map[t][1])
1182 1185 except KeyError as inst:
1183 1186 raise TemplateNotFound(_('"%s" not in template map') %
1184 1187 inst.args[0])
1185 1188 except IOError as inst:
1186 1189 raise IOError(inst.args[0], _('template file %s: %s') %
1187 1190 (self.map[t][1], inst.args[1]))
1188 1191 return self.cache[t]
1189 1192
1190 1193 def __call__(self, t, **mapping):
1191 1194 ttype = t in self.map and self.map[t][0] or 'default'
1192 1195 if ttype not in self.ecache:
1193 1196 try:
1194 1197 ecls = engines[ttype]
1195 1198 except KeyError:
1196 1199 raise error.Abort(_('invalid template engine: %s') % ttype)
1197 1200 self.ecache[ttype] = ecls(self.load, self.filters, self.defaults,
1198 1201 self._aliases)
1199 1202 proc = self.ecache[ttype]
1200 1203
1201 1204 stream = proc.process(t, mapping)
1202 1205 if self.minchunk:
1203 1206 stream = util.increasingchunks(stream, min=self.minchunk,
1204 1207 max=self.maxchunk)
1205 1208 return stream
1206 1209
1207 1210 def templatepaths():
1208 1211 '''return locations used for template files.'''
1209 1212 pathsrel = ['templates']
1210 1213 paths = [os.path.normpath(os.path.join(util.datapath, f))
1211 1214 for f in pathsrel]
1212 1215 return [p for p in paths if os.path.isdir(p)]
1213 1216
1214 1217 def templatepath(name):
1215 1218 '''return location of template file. returns None if not found.'''
1216 1219 for p in templatepaths():
1217 1220 f = os.path.join(p, name)
1218 1221 if os.path.exists(f):
1219 1222 return f
1220 1223 return None
1221 1224
1222 1225 def stylemap(styles, paths=None):
1223 1226 """Return path to mapfile for a given style.
1224 1227
1225 1228 Searches mapfile in the following locations:
1226 1229 1. templatepath/style/map
1227 1230 2. templatepath/map-style
1228 1231 3. templatepath/map
1229 1232 """
1230 1233
1231 1234 if paths is None:
1232 1235 paths = templatepaths()
1233 1236 elif isinstance(paths, str):
1234 1237 paths = [paths]
1235 1238
1236 1239 if isinstance(styles, str):
1237 1240 styles = [styles]
1238 1241
1239 1242 for style in styles:
1240 1243 # only plain name is allowed to honor template paths
1241 1244 if (not style
1242 1245 or style in (os.curdir, os.pardir)
1243 1246 or os.sep in style
1244 1247 or os.altsep and os.altsep in style):
1245 1248 continue
1246 1249 locations = [os.path.join(style, 'map'), 'map-' + style]
1247 1250 locations.append('map')
1248 1251
1249 1252 for path in paths:
1250 1253 for location in locations:
1251 1254 mapfile = os.path.join(path, location)
1252 1255 if os.path.isfile(mapfile):
1253 1256 return style, mapfile
1254 1257
1255 1258 raise RuntimeError("No hgweb templates found in %r" % paths)
1256 1259
1257 1260 def loadfunction(ui, extname, registrarobj):
1258 1261 """Load template function from specified registrarobj
1259 1262 """
1260 1263 for name, func in registrarobj._table.iteritems():
1261 1264 funcs[name] = func
1262 1265
1263 1266 # tell hggettext to extract docstrings from these functions:
1264 1267 i18nfunctions = funcs.values()
@@ -1,4125 +1,4126
1 1 $ hg init a
2 2 $ cd a
3 3 $ echo a > a
4 4 $ hg add a
5 5 $ echo line 1 > b
6 6 $ echo line 2 >> b
7 7 $ hg commit -l b -d '1000000 0' -u 'User Name <user@hostname>'
8 8
9 9 $ hg add b
10 10 $ echo other 1 > c
11 11 $ echo other 2 >> c
12 12 $ echo >> c
13 13 $ echo other 3 >> c
14 14 $ hg commit -l c -d '1100000 0' -u 'A. N. Other <other@place>'
15 15
16 16 $ hg add c
17 17 $ hg commit -m 'no person' -d '1200000 0' -u 'other@place'
18 18 $ echo c >> c
19 19 $ hg commit -m 'no user, no domain' -d '1300000 0' -u 'person'
20 20
21 21 $ echo foo > .hg/branch
22 22 $ hg commit -m 'new branch' -d '1400000 0' -u 'person'
23 23
24 24 $ hg co -q 3
25 25 $ echo other 4 >> d
26 26 $ hg add d
27 27 $ hg commit -m 'new head' -d '1500000 0' -u 'person'
28 28
29 29 $ hg merge -q foo
30 30 $ hg commit -m 'merge' -d '1500001 0' -u 'person'
31 31
32 32 Test arithmetic operators have the right precedence:
33 33
34 34 $ hg log -l 1 -T '{date(date, "%s") + 5 * 10} {date(date, "%s") - 2 * 3}\n'
35 35 1500051 1499995
36 36 $ hg log -l 1 -T '{date(date, "%s") * 5 + 10} {date(date, "%s") * 3 - 2}\n'
37 37 7500015 4500001
38 38
39 39 Test division:
40 40
41 41 $ hg debugtemplate -r0 -v '{5 / 2} {mod(5, 2)}\n'
42 42 (template
43 43 (/
44 44 ('integer', '5')
45 45 ('integer', '2'))
46 46 ('string', ' ')
47 47 (func
48 48 ('symbol', 'mod')
49 49 (list
50 50 ('integer', '5')
51 51 ('integer', '2')))
52 52 ('string', '\n'))
53 53 2 1
54 54 $ hg debugtemplate -r0 -v '{5 / -2} {mod(5, -2)}\n'
55 55 (template
56 56 (/
57 57 ('integer', '5')
58 58 (negate
59 59 ('integer', '2')))
60 60 ('string', ' ')
61 61 (func
62 62 ('symbol', 'mod')
63 63 (list
64 64 ('integer', '5')
65 65 (negate
66 66 ('integer', '2'))))
67 67 ('string', '\n'))
68 68 -3 -1
69 69 $ hg debugtemplate -r0 -v '{-5 / 2} {mod(-5, 2)}\n'
70 70 (template
71 71 (/
72 72 (negate
73 73 ('integer', '5'))
74 74 ('integer', '2'))
75 75 ('string', ' ')
76 76 (func
77 77 ('symbol', 'mod')
78 78 (list
79 79 (negate
80 80 ('integer', '5'))
81 81 ('integer', '2')))
82 82 ('string', '\n'))
83 83 -3 1
84 84 $ hg debugtemplate -r0 -v '{-5 / -2} {mod(-5, -2)}\n'
85 85 (template
86 86 (/
87 87 (negate
88 88 ('integer', '5'))
89 89 (negate
90 90 ('integer', '2')))
91 91 ('string', ' ')
92 92 (func
93 93 ('symbol', 'mod')
94 94 (list
95 95 (negate
96 96 ('integer', '5'))
97 97 (negate
98 98 ('integer', '2'))))
99 99 ('string', '\n'))
100 100 2 -1
101 101
102 102 Filters bind closer than arithmetic:
103 103
104 104 $ hg debugtemplate -r0 -v '{revset(".")|count - 1}\n'
105 105 (template
106 106 (-
107 107 (|
108 108 (func
109 109 ('symbol', 'revset')
110 110 ('string', '.'))
111 111 ('symbol', 'count'))
112 112 ('integer', '1'))
113 113 ('string', '\n'))
114 114 0
115 115
116 116 But negate binds closer still:
117 117
118 118 $ hg debugtemplate -r0 -v '{1-3|stringify}\n'
119 119 (template
120 120 (-
121 121 ('integer', '1')
122 122 (|
123 123 ('integer', '3')
124 124 ('symbol', 'stringify')))
125 125 ('string', '\n'))
126 126 hg: parse error: arithmetic only defined on integers
127 127 [255]
128 128 $ hg debugtemplate -r0 -v '{-3|stringify}\n'
129 129 (template
130 130 (|
131 131 (negate
132 132 ('integer', '3'))
133 133 ('symbol', 'stringify'))
134 134 ('string', '\n'))
135 135 -3
136 136
137 137 Second branch starting at nullrev:
138 138
139 139 $ hg update null
140 140 0 files updated, 0 files merged, 4 files removed, 0 files unresolved
141 141 $ echo second > second
142 142 $ hg add second
143 143 $ hg commit -m second -d '1000000 0' -u 'User Name <user@hostname>'
144 144 created new head
145 145
146 146 $ echo third > third
147 147 $ hg add third
148 148 $ hg mv second fourth
149 149 $ hg commit -m third -d "2020-01-01 10:01"
150 150
151 151 $ hg log --template '{join(file_copies, ",\n")}\n' -r .
152 152 fourth (second)
153 153 $ hg log -T '{file_copies % "{source} -> {name}\n"}' -r .
154 154 second -> fourth
155 155 $ hg log -T '{rev} {ifcontains("fourth", file_copies, "t", "f")}\n' -r .:7
156 156 8 t
157 157 7 f
158 158
159 159 Working-directory revision has special identifiers, though they are still
160 160 experimental:
161 161
162 162 $ hg log -r 'wdir()' -T '{rev}:{node}\n'
163 163 2147483647:ffffffffffffffffffffffffffffffffffffffff
164 164
165 165 Some keywords are invalid for working-directory revision, but they should
166 166 never cause crash:
167 167
168 168 $ hg log -r 'wdir()' -T '{manifest}\n'
169 169
170 170
171 171 Quoting for ui.logtemplate
172 172
173 173 $ hg tip --config "ui.logtemplate={rev}\n"
174 174 8
175 175 $ hg tip --config "ui.logtemplate='{rev}\n'"
176 176 8
177 177 $ hg tip --config 'ui.logtemplate="{rev}\n"'
178 178 8
179 179 $ hg tip --config 'ui.logtemplate=n{rev}\n'
180 180 n8
181 181
182 182 Make sure user/global hgrc does not affect tests
183 183
184 184 $ echo '[ui]' > .hg/hgrc
185 185 $ echo 'logtemplate =' >> .hg/hgrc
186 186 $ echo 'style =' >> .hg/hgrc
187 187
188 188 Add some simple styles to settings
189 189
190 190 $ echo '[templates]' >> .hg/hgrc
191 191 $ printf 'simple = "{rev}\\n"\n' >> .hg/hgrc
192 192 $ printf 'simple2 = {rev}\\n\n' >> .hg/hgrc
193 193
194 194 $ hg log -l1 -Tsimple
195 195 8
196 196 $ hg log -l1 -Tsimple2
197 197 8
198 198
199 199 Test templates and style maps in files:
200 200
201 201 $ echo "{rev}" > tmpl
202 202 $ hg log -l1 -T./tmpl
203 203 8
204 204 $ hg log -l1 -Tblah/blah
205 205 blah/blah (no-eol)
206 206
207 207 $ printf 'changeset = "{rev}\\n"\n' > map-simple
208 208 $ hg log -l1 -T./map-simple
209 209 8
210 210
211 211 Test template map inheritance
212 212
213 213 $ echo "__base__ = map-cmdline.default" > map-simple
214 214 $ printf 'cset = "changeset: ***{rev}***\\n"\n' >> map-simple
215 215 $ hg log -l1 -T./map-simple
216 216 changeset: ***8***
217 217 tag: tip
218 218 user: test
219 219 date: Wed Jan 01 10:01:00 2020 +0000
220 220 summary: third
221 221
222 222
223 223 Template should precede style option
224 224
225 225 $ hg log -l1 --style default -T '{rev}\n'
226 226 8
227 227
228 228 Add a commit with empty description, to ensure that the templates
229 229 below will omit the description line.
230 230
231 231 $ echo c >> c
232 232 $ hg add c
233 233 $ hg commit -qm ' '
234 234
235 235 Default style is like normal output. Phases style should be the same
236 236 as default style, except for extra phase lines.
237 237
238 238 $ hg log > log.out
239 239 $ hg log --style default > style.out
240 240 $ cmp log.out style.out || diff -u log.out style.out
241 241 $ hg log -T phases > phases.out
242 242 $ diff -U 0 log.out phases.out | egrep -v '^---|^\+\+\+|^@@'
243 243 +phase: draft
244 244 +phase: draft
245 245 +phase: draft
246 246 +phase: draft
247 247 +phase: draft
248 248 +phase: draft
249 249 +phase: draft
250 250 +phase: draft
251 251 +phase: draft
252 252 +phase: draft
253 253
254 254 $ hg log -v > log.out
255 255 $ hg log -v --style default > style.out
256 256 $ cmp log.out style.out || diff -u log.out style.out
257 257 $ hg log -v -T phases > phases.out
258 258 $ diff -U 0 log.out phases.out | egrep -v '^---|^\+\+\+|^@@'
259 259 +phase: draft
260 260 +phase: draft
261 261 +phase: draft
262 262 +phase: draft
263 263 +phase: draft
264 264 +phase: draft
265 265 +phase: draft
266 266 +phase: draft
267 267 +phase: draft
268 268 +phase: draft
269 269
270 270 $ hg log -q > log.out
271 271 $ hg log -q --style default > style.out
272 272 $ cmp log.out style.out || diff -u log.out style.out
273 273 $ hg log -q -T phases > phases.out
274 274 $ cmp log.out phases.out || diff -u log.out phases.out
275 275
276 276 $ hg log --debug > log.out
277 277 $ hg log --debug --style default > style.out
278 278 $ cmp log.out style.out || diff -u log.out style.out
279 279 $ hg log --debug -T phases > phases.out
280 280 $ cmp log.out phases.out || diff -u log.out phases.out
281 281
282 282 Default style of working-directory revision should also be the same (but
283 283 date may change while running tests):
284 284
285 285 $ hg log -r 'wdir()' | sed 's|^date:.*|date:|' > log.out
286 286 $ hg log -r 'wdir()' --style default | sed 's|^date:.*|date:|' > style.out
287 287 $ cmp log.out style.out || diff -u log.out style.out
288 288
289 289 $ hg log -r 'wdir()' -v | sed 's|^date:.*|date:|' > log.out
290 290 $ hg log -r 'wdir()' -v --style default | sed 's|^date:.*|date:|' > style.out
291 291 $ cmp log.out style.out || diff -u log.out style.out
292 292
293 293 $ hg log -r 'wdir()' -q > log.out
294 294 $ hg log -r 'wdir()' -q --style default > style.out
295 295 $ cmp log.out style.out || diff -u log.out style.out
296 296
297 297 $ hg log -r 'wdir()' --debug | sed 's|^date:.*|date:|' > log.out
298 298 $ hg log -r 'wdir()' --debug --style default \
299 299 > | sed 's|^date:.*|date:|' > style.out
300 300 $ cmp log.out style.out || diff -u log.out style.out
301 301
302 302 Default style should also preserve color information (issue2866):
303 303
304 304 $ cp $HGRCPATH $HGRCPATH-bak
305 305 $ cat <<EOF >> $HGRCPATH
306 306 > [extensions]
307 307 > color=
308 308 > EOF
309 309
310 310 $ hg --color=debug log > log.out
311 311 $ hg --color=debug log --style default > style.out
312 312 $ cmp log.out style.out || diff -u log.out style.out
313 313 $ hg --color=debug log -T phases > phases.out
314 314 $ diff -U 0 log.out phases.out | egrep -v '^---|^\+\+\+|^@@'
315 315 +[log.phase|phase: draft]
316 316 +[log.phase|phase: draft]
317 317 +[log.phase|phase: draft]
318 318 +[log.phase|phase: draft]
319 319 +[log.phase|phase: draft]
320 320 +[log.phase|phase: draft]
321 321 +[log.phase|phase: draft]
322 322 +[log.phase|phase: draft]
323 323 +[log.phase|phase: draft]
324 324 +[log.phase|phase: draft]
325 325
326 326 $ hg --color=debug -v log > log.out
327 327 $ hg --color=debug -v log --style default > style.out
328 328 $ cmp log.out style.out || diff -u log.out style.out
329 329 $ hg --color=debug -v log -T phases > phases.out
330 330 $ diff -U 0 log.out phases.out | egrep -v '^---|^\+\+\+|^@@'
331 331 +[log.phase|phase: draft]
332 332 +[log.phase|phase: draft]
333 333 +[log.phase|phase: draft]
334 334 +[log.phase|phase: draft]
335 335 +[log.phase|phase: draft]
336 336 +[log.phase|phase: draft]
337 337 +[log.phase|phase: draft]
338 338 +[log.phase|phase: draft]
339 339 +[log.phase|phase: draft]
340 340 +[log.phase|phase: draft]
341 341
342 342 $ hg --color=debug -q log > log.out
343 343 $ hg --color=debug -q log --style default > style.out
344 344 $ cmp log.out style.out || diff -u log.out style.out
345 345 $ hg --color=debug -q log -T phases > phases.out
346 346 $ cmp log.out phases.out || diff -u log.out phases.out
347 347
348 348 $ hg --color=debug --debug log > log.out
349 349 $ hg --color=debug --debug log --style default > style.out
350 350 $ cmp log.out style.out || diff -u log.out style.out
351 351 $ hg --color=debug --debug log -T phases > phases.out
352 352 $ cmp log.out phases.out || diff -u log.out phases.out
353 353
354 354 $ mv $HGRCPATH-bak $HGRCPATH
355 355
356 356 Remove commit with empty commit message, so as to not pollute further
357 357 tests.
358 358
359 359 $ hg --config extensions.strip= strip -q .
360 360
361 361 Revision with no copies (used to print a traceback):
362 362
363 363 $ hg tip -v --template '\n'
364 364
365 365
366 366 Compact style works:
367 367
368 368 $ hg log -Tcompact
369 369 8[tip] 95c24699272e 2020-01-01 10:01 +0000 test
370 370 third
371 371
372 372 7:-1 29114dbae42b 1970-01-12 13:46 +0000 user
373 373 second
374 374
375 375 6:5,4 d41e714fe50d 1970-01-18 08:40 +0000 person
376 376 merge
377 377
378 378 5:3 13207e5a10d9 1970-01-18 08:40 +0000 person
379 379 new head
380 380
381 381 4 bbe44766e73d 1970-01-17 04:53 +0000 person
382 382 new branch
383 383
384 384 3 10e46f2dcbf4 1970-01-16 01:06 +0000 person
385 385 no user, no domain
386 386
387 387 2 97054abb4ab8 1970-01-14 21:20 +0000 other
388 388 no person
389 389
390 390 1 b608e9d1a3f0 1970-01-13 17:33 +0000 other
391 391 other 1
392 392
393 393 0 1e4e1b8f71e0 1970-01-12 13:46 +0000 user
394 394 line 1
395 395
396 396
397 397 $ hg log -v --style compact
398 398 8[tip] 95c24699272e 2020-01-01 10:01 +0000 test
399 399 third
400 400
401 401 7:-1 29114dbae42b 1970-01-12 13:46 +0000 User Name <user@hostname>
402 402 second
403 403
404 404 6:5,4 d41e714fe50d 1970-01-18 08:40 +0000 person
405 405 merge
406 406
407 407 5:3 13207e5a10d9 1970-01-18 08:40 +0000 person
408 408 new head
409 409
410 410 4 bbe44766e73d 1970-01-17 04:53 +0000 person
411 411 new branch
412 412
413 413 3 10e46f2dcbf4 1970-01-16 01:06 +0000 person
414 414 no user, no domain
415 415
416 416 2 97054abb4ab8 1970-01-14 21:20 +0000 other@place
417 417 no person
418 418
419 419 1 b608e9d1a3f0 1970-01-13 17:33 +0000 A. N. Other <other@place>
420 420 other 1
421 421 other 2
422 422
423 423 other 3
424 424
425 425 0 1e4e1b8f71e0 1970-01-12 13:46 +0000 User Name <user@hostname>
426 426 line 1
427 427 line 2
428 428
429 429
430 430 $ hg log --debug --style compact
431 431 8[tip]:7,-1 95c24699272e 2020-01-01 10:01 +0000 test
432 432 third
433 433
434 434 7:-1,-1 29114dbae42b 1970-01-12 13:46 +0000 User Name <user@hostname>
435 435 second
436 436
437 437 6:5,4 d41e714fe50d 1970-01-18 08:40 +0000 person
438 438 merge
439 439
440 440 5:3,-1 13207e5a10d9 1970-01-18 08:40 +0000 person
441 441 new head
442 442
443 443 4:3,-1 bbe44766e73d 1970-01-17 04:53 +0000 person
444 444 new branch
445 445
446 446 3:2,-1 10e46f2dcbf4 1970-01-16 01:06 +0000 person
447 447 no user, no domain
448 448
449 449 2:1,-1 97054abb4ab8 1970-01-14 21:20 +0000 other@place
450 450 no person
451 451
452 452 1:0,-1 b608e9d1a3f0 1970-01-13 17:33 +0000 A. N. Other <other@place>
453 453 other 1
454 454 other 2
455 455
456 456 other 3
457 457
458 458 0:-1,-1 1e4e1b8f71e0 1970-01-12 13:46 +0000 User Name <user@hostname>
459 459 line 1
460 460 line 2
461 461
462 462
463 463 Test xml styles:
464 464
465 465 $ hg log --style xml -r 'not all()'
466 466 <?xml version="1.0"?>
467 467 <log>
468 468 </log>
469 469
470 470 $ hg log --style xml
471 471 <?xml version="1.0"?>
472 472 <log>
473 473 <logentry revision="8" node="95c24699272ef57d062b8bccc32c878bf841784a">
474 474 <tag>tip</tag>
475 475 <author email="test">test</author>
476 476 <date>2020-01-01T10:01:00+00:00</date>
477 477 <msg xml:space="preserve">third</msg>
478 478 </logentry>
479 479 <logentry revision="7" node="29114dbae42b9f078cf2714dbe3a86bba8ec7453">
480 480 <parent revision="-1" node="0000000000000000000000000000000000000000" />
481 481 <author email="user@hostname">User Name</author>
482 482 <date>1970-01-12T13:46:40+00:00</date>
483 483 <msg xml:space="preserve">second</msg>
484 484 </logentry>
485 485 <logentry revision="6" node="d41e714fe50d9e4a5f11b4d595d543481b5f980b">
486 486 <parent revision="5" node="13207e5a10d9fd28ec424934298e176197f2c67f" />
487 487 <parent revision="4" node="bbe44766e73d5f11ed2177f1838de10c53ef3e74" />
488 488 <author email="person">person</author>
489 489 <date>1970-01-18T08:40:01+00:00</date>
490 490 <msg xml:space="preserve">merge</msg>
491 491 </logentry>
492 492 <logentry revision="5" node="13207e5a10d9fd28ec424934298e176197f2c67f">
493 493 <parent revision="3" node="10e46f2dcbf4823578cf180f33ecf0b957964c47" />
494 494 <author email="person">person</author>
495 495 <date>1970-01-18T08:40:00+00:00</date>
496 496 <msg xml:space="preserve">new head</msg>
497 497 </logentry>
498 498 <logentry revision="4" node="bbe44766e73d5f11ed2177f1838de10c53ef3e74">
499 499 <branch>foo</branch>
500 500 <author email="person">person</author>
501 501 <date>1970-01-17T04:53:20+00:00</date>
502 502 <msg xml:space="preserve">new branch</msg>
503 503 </logentry>
504 504 <logentry revision="3" node="10e46f2dcbf4823578cf180f33ecf0b957964c47">
505 505 <author email="person">person</author>
506 506 <date>1970-01-16T01:06:40+00:00</date>
507 507 <msg xml:space="preserve">no user, no domain</msg>
508 508 </logentry>
509 509 <logentry revision="2" node="97054abb4ab824450e9164180baf491ae0078465">
510 510 <author email="other@place">other</author>
511 511 <date>1970-01-14T21:20:00+00:00</date>
512 512 <msg xml:space="preserve">no person</msg>
513 513 </logentry>
514 514 <logentry revision="1" node="b608e9d1a3f0273ccf70fb85fd6866b3482bf965">
515 515 <author email="other@place">A. N. Other</author>
516 516 <date>1970-01-13T17:33:20+00:00</date>
517 517 <msg xml:space="preserve">other 1
518 518 other 2
519 519
520 520 other 3</msg>
521 521 </logentry>
522 522 <logentry revision="0" node="1e4e1b8f71e05681d422154f5421e385fec3454f">
523 523 <author email="user@hostname">User Name</author>
524 524 <date>1970-01-12T13:46:40+00:00</date>
525 525 <msg xml:space="preserve">line 1
526 526 line 2</msg>
527 527 </logentry>
528 528 </log>
529 529
530 530 $ hg log -v --style xml
531 531 <?xml version="1.0"?>
532 532 <log>
533 533 <logentry revision="8" node="95c24699272ef57d062b8bccc32c878bf841784a">
534 534 <tag>tip</tag>
535 535 <author email="test">test</author>
536 536 <date>2020-01-01T10:01:00+00:00</date>
537 537 <msg xml:space="preserve">third</msg>
538 538 <paths>
539 539 <path action="A">fourth</path>
540 540 <path action="A">third</path>
541 541 <path action="R">second</path>
542 542 </paths>
543 543 <copies>
544 544 <copy source="second">fourth</copy>
545 545 </copies>
546 546 </logentry>
547 547 <logentry revision="7" node="29114dbae42b9f078cf2714dbe3a86bba8ec7453">
548 548 <parent revision="-1" node="0000000000000000000000000000000000000000" />
549 549 <author email="user@hostname">User Name</author>
550 550 <date>1970-01-12T13:46:40+00:00</date>
551 551 <msg xml:space="preserve">second</msg>
552 552 <paths>
553 553 <path action="A">second</path>
554 554 </paths>
555 555 </logentry>
556 556 <logentry revision="6" node="d41e714fe50d9e4a5f11b4d595d543481b5f980b">
557 557 <parent revision="5" node="13207e5a10d9fd28ec424934298e176197f2c67f" />
558 558 <parent revision="4" node="bbe44766e73d5f11ed2177f1838de10c53ef3e74" />
559 559 <author email="person">person</author>
560 560 <date>1970-01-18T08:40:01+00:00</date>
561 561 <msg xml:space="preserve">merge</msg>
562 562 <paths>
563 563 </paths>
564 564 </logentry>
565 565 <logentry revision="5" node="13207e5a10d9fd28ec424934298e176197f2c67f">
566 566 <parent revision="3" node="10e46f2dcbf4823578cf180f33ecf0b957964c47" />
567 567 <author email="person">person</author>
568 568 <date>1970-01-18T08:40:00+00:00</date>
569 569 <msg xml:space="preserve">new head</msg>
570 570 <paths>
571 571 <path action="A">d</path>
572 572 </paths>
573 573 </logentry>
574 574 <logentry revision="4" node="bbe44766e73d5f11ed2177f1838de10c53ef3e74">
575 575 <branch>foo</branch>
576 576 <author email="person">person</author>
577 577 <date>1970-01-17T04:53:20+00:00</date>
578 578 <msg xml:space="preserve">new branch</msg>
579 579 <paths>
580 580 </paths>
581 581 </logentry>
582 582 <logentry revision="3" node="10e46f2dcbf4823578cf180f33ecf0b957964c47">
583 583 <author email="person">person</author>
584 584 <date>1970-01-16T01:06:40+00:00</date>
585 585 <msg xml:space="preserve">no user, no domain</msg>
586 586 <paths>
587 587 <path action="M">c</path>
588 588 </paths>
589 589 </logentry>
590 590 <logentry revision="2" node="97054abb4ab824450e9164180baf491ae0078465">
591 591 <author email="other@place">other</author>
592 592 <date>1970-01-14T21:20:00+00:00</date>
593 593 <msg xml:space="preserve">no person</msg>
594 594 <paths>
595 595 <path action="A">c</path>
596 596 </paths>
597 597 </logentry>
598 598 <logentry revision="1" node="b608e9d1a3f0273ccf70fb85fd6866b3482bf965">
599 599 <author email="other@place">A. N. Other</author>
600 600 <date>1970-01-13T17:33:20+00:00</date>
601 601 <msg xml:space="preserve">other 1
602 602 other 2
603 603
604 604 other 3</msg>
605 605 <paths>
606 606 <path action="A">b</path>
607 607 </paths>
608 608 </logentry>
609 609 <logentry revision="0" node="1e4e1b8f71e05681d422154f5421e385fec3454f">
610 610 <author email="user@hostname">User Name</author>
611 611 <date>1970-01-12T13:46:40+00:00</date>
612 612 <msg xml:space="preserve">line 1
613 613 line 2</msg>
614 614 <paths>
615 615 <path action="A">a</path>
616 616 </paths>
617 617 </logentry>
618 618 </log>
619 619
620 620 $ hg log --debug --style xml
621 621 <?xml version="1.0"?>
622 622 <log>
623 623 <logentry revision="8" node="95c24699272ef57d062b8bccc32c878bf841784a">
624 624 <tag>tip</tag>
625 625 <parent revision="7" node="29114dbae42b9f078cf2714dbe3a86bba8ec7453" />
626 626 <parent revision="-1" node="0000000000000000000000000000000000000000" />
627 627 <author email="test">test</author>
628 628 <date>2020-01-01T10:01:00+00:00</date>
629 629 <msg xml:space="preserve">third</msg>
630 630 <paths>
631 631 <path action="A">fourth</path>
632 632 <path action="A">third</path>
633 633 <path action="R">second</path>
634 634 </paths>
635 635 <copies>
636 636 <copy source="second">fourth</copy>
637 637 </copies>
638 638 <extra key="branch">default</extra>
639 639 </logentry>
640 640 <logentry revision="7" node="29114dbae42b9f078cf2714dbe3a86bba8ec7453">
641 641 <parent revision="-1" node="0000000000000000000000000000000000000000" />
642 642 <parent revision="-1" node="0000000000000000000000000000000000000000" />
643 643 <author email="user@hostname">User Name</author>
644 644 <date>1970-01-12T13:46:40+00:00</date>
645 645 <msg xml:space="preserve">second</msg>
646 646 <paths>
647 647 <path action="A">second</path>
648 648 </paths>
649 649 <extra key="branch">default</extra>
650 650 </logentry>
651 651 <logentry revision="6" node="d41e714fe50d9e4a5f11b4d595d543481b5f980b">
652 652 <parent revision="5" node="13207e5a10d9fd28ec424934298e176197f2c67f" />
653 653 <parent revision="4" node="bbe44766e73d5f11ed2177f1838de10c53ef3e74" />
654 654 <author email="person">person</author>
655 655 <date>1970-01-18T08:40:01+00:00</date>
656 656 <msg xml:space="preserve">merge</msg>
657 657 <paths>
658 658 </paths>
659 659 <extra key="branch">default</extra>
660 660 </logentry>
661 661 <logentry revision="5" node="13207e5a10d9fd28ec424934298e176197f2c67f">
662 662 <parent revision="3" node="10e46f2dcbf4823578cf180f33ecf0b957964c47" />
663 663 <parent revision="-1" node="0000000000000000000000000000000000000000" />
664 664 <author email="person">person</author>
665 665 <date>1970-01-18T08:40:00+00:00</date>
666 666 <msg xml:space="preserve">new head</msg>
667 667 <paths>
668 668 <path action="A">d</path>
669 669 </paths>
670 670 <extra key="branch">default</extra>
671 671 </logentry>
672 672 <logentry revision="4" node="bbe44766e73d5f11ed2177f1838de10c53ef3e74">
673 673 <branch>foo</branch>
674 674 <parent revision="3" node="10e46f2dcbf4823578cf180f33ecf0b957964c47" />
675 675 <parent revision="-1" node="0000000000000000000000000000000000000000" />
676 676 <author email="person">person</author>
677 677 <date>1970-01-17T04:53:20+00:00</date>
678 678 <msg xml:space="preserve">new branch</msg>
679 679 <paths>
680 680 </paths>
681 681 <extra key="branch">foo</extra>
682 682 </logentry>
683 683 <logentry revision="3" node="10e46f2dcbf4823578cf180f33ecf0b957964c47">
684 684 <parent revision="2" node="97054abb4ab824450e9164180baf491ae0078465" />
685 685 <parent revision="-1" node="0000000000000000000000000000000000000000" />
686 686 <author email="person">person</author>
687 687 <date>1970-01-16T01:06:40+00:00</date>
688 688 <msg xml:space="preserve">no user, no domain</msg>
689 689 <paths>
690 690 <path action="M">c</path>
691 691 </paths>
692 692 <extra key="branch">default</extra>
693 693 </logentry>
694 694 <logentry revision="2" node="97054abb4ab824450e9164180baf491ae0078465">
695 695 <parent revision="1" node="b608e9d1a3f0273ccf70fb85fd6866b3482bf965" />
696 696 <parent revision="-1" node="0000000000000000000000000000000000000000" />
697 697 <author email="other@place">other</author>
698 698 <date>1970-01-14T21:20:00+00:00</date>
699 699 <msg xml:space="preserve">no person</msg>
700 700 <paths>
701 701 <path action="A">c</path>
702 702 </paths>
703 703 <extra key="branch">default</extra>
704 704 </logentry>
705 705 <logentry revision="1" node="b608e9d1a3f0273ccf70fb85fd6866b3482bf965">
706 706 <parent revision="0" node="1e4e1b8f71e05681d422154f5421e385fec3454f" />
707 707 <parent revision="-1" node="0000000000000000000000000000000000000000" />
708 708 <author email="other@place">A. N. Other</author>
709 709 <date>1970-01-13T17:33:20+00:00</date>
710 710 <msg xml:space="preserve">other 1
711 711 other 2
712 712
713 713 other 3</msg>
714 714 <paths>
715 715 <path action="A">b</path>
716 716 </paths>
717 717 <extra key="branch">default</extra>
718 718 </logentry>
719 719 <logentry revision="0" node="1e4e1b8f71e05681d422154f5421e385fec3454f">
720 720 <parent revision="-1" node="0000000000000000000000000000000000000000" />
721 721 <parent revision="-1" node="0000000000000000000000000000000000000000" />
722 722 <author email="user@hostname">User Name</author>
723 723 <date>1970-01-12T13:46:40+00:00</date>
724 724 <msg xml:space="preserve">line 1
725 725 line 2</msg>
726 726 <paths>
727 727 <path action="A">a</path>
728 728 </paths>
729 729 <extra key="branch">default</extra>
730 730 </logentry>
731 731 </log>
732 732
733 733
734 734 Test JSON style:
735 735
736 736 $ hg log -k nosuch -Tjson
737 737 []
738 738
739 739 $ hg log -qr . -Tjson
740 740 [
741 741 {
742 742 "rev": 8,
743 743 "node": "95c24699272ef57d062b8bccc32c878bf841784a"
744 744 }
745 745 ]
746 746
747 747 $ hg log -vpr . -Tjson --stat
748 748 [
749 749 {
750 750 "rev": 8,
751 751 "node": "95c24699272ef57d062b8bccc32c878bf841784a",
752 752 "branch": "default",
753 753 "phase": "draft",
754 754 "user": "test",
755 755 "date": [1577872860, 0],
756 756 "desc": "third",
757 757 "bookmarks": [],
758 758 "tags": ["tip"],
759 759 "parents": ["29114dbae42b9f078cf2714dbe3a86bba8ec7453"],
760 760 "files": ["fourth", "second", "third"],
761 761 "diffstat": " fourth | 1 +\n second | 1 -\n third | 1 +\n 3 files changed, 2 insertions(+), 1 deletions(-)\n",
762 762 "diff": "diff -r 29114dbae42b -r 95c24699272e fourth\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/fourth\tWed Jan 01 10:01:00 2020 +0000\n@@ -0,0 +1,1 @@\n+second\ndiff -r 29114dbae42b -r 95c24699272e second\n--- a/second\tMon Jan 12 13:46:40 1970 +0000\n+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +0,0 @@\n-second\ndiff -r 29114dbae42b -r 95c24699272e third\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/third\tWed Jan 01 10:01:00 2020 +0000\n@@ -0,0 +1,1 @@\n+third\n"
763 763 }
764 764 ]
765 765
766 766 honor --git but not format-breaking diffopts
767 767 $ hg --config diff.noprefix=True log --git -vpr . -Tjson
768 768 [
769 769 {
770 770 "rev": 8,
771 771 "node": "95c24699272ef57d062b8bccc32c878bf841784a",
772 772 "branch": "default",
773 773 "phase": "draft",
774 774 "user": "test",
775 775 "date": [1577872860, 0],
776 776 "desc": "third",
777 777 "bookmarks": [],
778 778 "tags": ["tip"],
779 779 "parents": ["29114dbae42b9f078cf2714dbe3a86bba8ec7453"],
780 780 "files": ["fourth", "second", "third"],
781 781 "diff": "diff --git a/second b/fourth\nrename from second\nrename to fourth\ndiff --git a/third b/third\nnew file mode 100644\n--- /dev/null\n+++ b/third\n@@ -0,0 +1,1 @@\n+third\n"
782 782 }
783 783 ]
784 784
785 785 $ hg log -T json
786 786 [
787 787 {
788 788 "rev": 8,
789 789 "node": "95c24699272ef57d062b8bccc32c878bf841784a",
790 790 "branch": "default",
791 791 "phase": "draft",
792 792 "user": "test",
793 793 "date": [1577872860, 0],
794 794 "desc": "third",
795 795 "bookmarks": [],
796 796 "tags": ["tip"],
797 797 "parents": ["29114dbae42b9f078cf2714dbe3a86bba8ec7453"]
798 798 },
799 799 {
800 800 "rev": 7,
801 801 "node": "29114dbae42b9f078cf2714dbe3a86bba8ec7453",
802 802 "branch": "default",
803 803 "phase": "draft",
804 804 "user": "User Name <user@hostname>",
805 805 "date": [1000000, 0],
806 806 "desc": "second",
807 807 "bookmarks": [],
808 808 "tags": [],
809 809 "parents": ["0000000000000000000000000000000000000000"]
810 810 },
811 811 {
812 812 "rev": 6,
813 813 "node": "d41e714fe50d9e4a5f11b4d595d543481b5f980b",
814 814 "branch": "default",
815 815 "phase": "draft",
816 816 "user": "person",
817 817 "date": [1500001, 0],
818 818 "desc": "merge",
819 819 "bookmarks": [],
820 820 "tags": [],
821 821 "parents": ["13207e5a10d9fd28ec424934298e176197f2c67f", "bbe44766e73d5f11ed2177f1838de10c53ef3e74"]
822 822 },
823 823 {
824 824 "rev": 5,
825 825 "node": "13207e5a10d9fd28ec424934298e176197f2c67f",
826 826 "branch": "default",
827 827 "phase": "draft",
828 828 "user": "person",
829 829 "date": [1500000, 0],
830 830 "desc": "new head",
831 831 "bookmarks": [],
832 832 "tags": [],
833 833 "parents": ["10e46f2dcbf4823578cf180f33ecf0b957964c47"]
834 834 },
835 835 {
836 836 "rev": 4,
837 837 "node": "bbe44766e73d5f11ed2177f1838de10c53ef3e74",
838 838 "branch": "foo",
839 839 "phase": "draft",
840 840 "user": "person",
841 841 "date": [1400000, 0],
842 842 "desc": "new branch",
843 843 "bookmarks": [],
844 844 "tags": [],
845 845 "parents": ["10e46f2dcbf4823578cf180f33ecf0b957964c47"]
846 846 },
847 847 {
848 848 "rev": 3,
849 849 "node": "10e46f2dcbf4823578cf180f33ecf0b957964c47",
850 850 "branch": "default",
851 851 "phase": "draft",
852 852 "user": "person",
853 853 "date": [1300000, 0],
854 854 "desc": "no user, no domain",
855 855 "bookmarks": [],
856 856 "tags": [],
857 857 "parents": ["97054abb4ab824450e9164180baf491ae0078465"]
858 858 },
859 859 {
860 860 "rev": 2,
861 861 "node": "97054abb4ab824450e9164180baf491ae0078465",
862 862 "branch": "default",
863 863 "phase": "draft",
864 864 "user": "other@place",
865 865 "date": [1200000, 0],
866 866 "desc": "no person",
867 867 "bookmarks": [],
868 868 "tags": [],
869 869 "parents": ["b608e9d1a3f0273ccf70fb85fd6866b3482bf965"]
870 870 },
871 871 {
872 872 "rev": 1,
873 873 "node": "b608e9d1a3f0273ccf70fb85fd6866b3482bf965",
874 874 "branch": "default",
875 875 "phase": "draft",
876 876 "user": "A. N. Other <other@place>",
877 877 "date": [1100000, 0],
878 878 "desc": "other 1\nother 2\n\nother 3",
879 879 "bookmarks": [],
880 880 "tags": [],
881 881 "parents": ["1e4e1b8f71e05681d422154f5421e385fec3454f"]
882 882 },
883 883 {
884 884 "rev": 0,
885 885 "node": "1e4e1b8f71e05681d422154f5421e385fec3454f",
886 886 "branch": "default",
887 887 "phase": "draft",
888 888 "user": "User Name <user@hostname>",
889 889 "date": [1000000, 0],
890 890 "desc": "line 1\nline 2",
891 891 "bookmarks": [],
892 892 "tags": [],
893 893 "parents": ["0000000000000000000000000000000000000000"]
894 894 }
895 895 ]
896 896
897 897 $ hg heads -v -Tjson
898 898 [
899 899 {
900 900 "rev": 8,
901 901 "node": "95c24699272ef57d062b8bccc32c878bf841784a",
902 902 "branch": "default",
903 903 "phase": "draft",
904 904 "user": "test",
905 905 "date": [1577872860, 0],
906 906 "desc": "third",
907 907 "bookmarks": [],
908 908 "tags": ["tip"],
909 909 "parents": ["29114dbae42b9f078cf2714dbe3a86bba8ec7453"],
910 910 "files": ["fourth", "second", "third"]
911 911 },
912 912 {
913 913 "rev": 6,
914 914 "node": "d41e714fe50d9e4a5f11b4d595d543481b5f980b",
915 915 "branch": "default",
916 916 "phase": "draft",
917 917 "user": "person",
918 918 "date": [1500001, 0],
919 919 "desc": "merge",
920 920 "bookmarks": [],
921 921 "tags": [],
922 922 "parents": ["13207e5a10d9fd28ec424934298e176197f2c67f", "bbe44766e73d5f11ed2177f1838de10c53ef3e74"],
923 923 "files": []
924 924 },
925 925 {
926 926 "rev": 4,
927 927 "node": "bbe44766e73d5f11ed2177f1838de10c53ef3e74",
928 928 "branch": "foo",
929 929 "phase": "draft",
930 930 "user": "person",
931 931 "date": [1400000, 0],
932 932 "desc": "new branch",
933 933 "bookmarks": [],
934 934 "tags": [],
935 935 "parents": ["10e46f2dcbf4823578cf180f33ecf0b957964c47"],
936 936 "files": []
937 937 }
938 938 ]
939 939
940 940 $ hg log --debug -Tjson
941 941 [
942 942 {
943 943 "rev": 8,
944 944 "node": "95c24699272ef57d062b8bccc32c878bf841784a",
945 945 "branch": "default",
946 946 "phase": "draft",
947 947 "user": "test",
948 948 "date": [1577872860, 0],
949 949 "desc": "third",
950 950 "bookmarks": [],
951 951 "tags": ["tip"],
952 952 "parents": ["29114dbae42b9f078cf2714dbe3a86bba8ec7453"],
953 953 "manifest": "94961b75a2da554b4df6fb599e5bfc7d48de0c64",
954 954 "extra": {"branch": "default"},
955 955 "modified": [],
956 956 "added": ["fourth", "third"],
957 957 "removed": ["second"]
958 958 },
959 959 {
960 960 "rev": 7,
961 961 "node": "29114dbae42b9f078cf2714dbe3a86bba8ec7453",
962 962 "branch": "default",
963 963 "phase": "draft",
964 964 "user": "User Name <user@hostname>",
965 965 "date": [1000000, 0],
966 966 "desc": "second",
967 967 "bookmarks": [],
968 968 "tags": [],
969 969 "parents": ["0000000000000000000000000000000000000000"],
970 970 "manifest": "f2dbc354b94e5ec0b4f10680ee0cee816101d0bf",
971 971 "extra": {"branch": "default"},
972 972 "modified": [],
973 973 "added": ["second"],
974 974 "removed": []
975 975 },
976 976 {
977 977 "rev": 6,
978 978 "node": "d41e714fe50d9e4a5f11b4d595d543481b5f980b",
979 979 "branch": "default",
980 980 "phase": "draft",
981 981 "user": "person",
982 982 "date": [1500001, 0],
983 983 "desc": "merge",
984 984 "bookmarks": [],
985 985 "tags": [],
986 986 "parents": ["13207e5a10d9fd28ec424934298e176197f2c67f", "bbe44766e73d5f11ed2177f1838de10c53ef3e74"],
987 987 "manifest": "4dc3def4f9b4c6e8de820f6ee74737f91e96a216",
988 988 "extra": {"branch": "default"},
989 989 "modified": [],
990 990 "added": [],
991 991 "removed": []
992 992 },
993 993 {
994 994 "rev": 5,
995 995 "node": "13207e5a10d9fd28ec424934298e176197f2c67f",
996 996 "branch": "default",
997 997 "phase": "draft",
998 998 "user": "person",
999 999 "date": [1500000, 0],
1000 1000 "desc": "new head",
1001 1001 "bookmarks": [],
1002 1002 "tags": [],
1003 1003 "parents": ["10e46f2dcbf4823578cf180f33ecf0b957964c47"],
1004 1004 "manifest": "4dc3def4f9b4c6e8de820f6ee74737f91e96a216",
1005 1005 "extra": {"branch": "default"},
1006 1006 "modified": [],
1007 1007 "added": ["d"],
1008 1008 "removed": []
1009 1009 },
1010 1010 {
1011 1011 "rev": 4,
1012 1012 "node": "bbe44766e73d5f11ed2177f1838de10c53ef3e74",
1013 1013 "branch": "foo",
1014 1014 "phase": "draft",
1015 1015 "user": "person",
1016 1016 "date": [1400000, 0],
1017 1017 "desc": "new branch",
1018 1018 "bookmarks": [],
1019 1019 "tags": [],
1020 1020 "parents": ["10e46f2dcbf4823578cf180f33ecf0b957964c47"],
1021 1021 "manifest": "cb5a1327723bada42f117e4c55a303246eaf9ccc",
1022 1022 "extra": {"branch": "foo"},
1023 1023 "modified": [],
1024 1024 "added": [],
1025 1025 "removed": []
1026 1026 },
1027 1027 {
1028 1028 "rev": 3,
1029 1029 "node": "10e46f2dcbf4823578cf180f33ecf0b957964c47",
1030 1030 "branch": "default",
1031 1031 "phase": "draft",
1032 1032 "user": "person",
1033 1033 "date": [1300000, 0],
1034 1034 "desc": "no user, no domain",
1035 1035 "bookmarks": [],
1036 1036 "tags": [],
1037 1037 "parents": ["97054abb4ab824450e9164180baf491ae0078465"],
1038 1038 "manifest": "cb5a1327723bada42f117e4c55a303246eaf9ccc",
1039 1039 "extra": {"branch": "default"},
1040 1040 "modified": ["c"],
1041 1041 "added": [],
1042 1042 "removed": []
1043 1043 },
1044 1044 {
1045 1045 "rev": 2,
1046 1046 "node": "97054abb4ab824450e9164180baf491ae0078465",
1047 1047 "branch": "default",
1048 1048 "phase": "draft",
1049 1049 "user": "other@place",
1050 1050 "date": [1200000, 0],
1051 1051 "desc": "no person",
1052 1052 "bookmarks": [],
1053 1053 "tags": [],
1054 1054 "parents": ["b608e9d1a3f0273ccf70fb85fd6866b3482bf965"],
1055 1055 "manifest": "6e0e82995c35d0d57a52aca8da4e56139e06b4b1",
1056 1056 "extra": {"branch": "default"},
1057 1057 "modified": [],
1058 1058 "added": ["c"],
1059 1059 "removed": []
1060 1060 },
1061 1061 {
1062 1062 "rev": 1,
1063 1063 "node": "b608e9d1a3f0273ccf70fb85fd6866b3482bf965",
1064 1064 "branch": "default",
1065 1065 "phase": "draft",
1066 1066 "user": "A. N. Other <other@place>",
1067 1067 "date": [1100000, 0],
1068 1068 "desc": "other 1\nother 2\n\nother 3",
1069 1069 "bookmarks": [],
1070 1070 "tags": [],
1071 1071 "parents": ["1e4e1b8f71e05681d422154f5421e385fec3454f"],
1072 1072 "manifest": "4e8d705b1e53e3f9375e0e60dc7b525d8211fe55",
1073 1073 "extra": {"branch": "default"},
1074 1074 "modified": [],
1075 1075 "added": ["b"],
1076 1076 "removed": []
1077 1077 },
1078 1078 {
1079 1079 "rev": 0,
1080 1080 "node": "1e4e1b8f71e05681d422154f5421e385fec3454f",
1081 1081 "branch": "default",
1082 1082 "phase": "draft",
1083 1083 "user": "User Name <user@hostname>",
1084 1084 "date": [1000000, 0],
1085 1085 "desc": "line 1\nline 2",
1086 1086 "bookmarks": [],
1087 1087 "tags": [],
1088 1088 "parents": ["0000000000000000000000000000000000000000"],
1089 1089 "manifest": "a0c8bcbbb45c63b90b70ad007bf38961f64f2af0",
1090 1090 "extra": {"branch": "default"},
1091 1091 "modified": [],
1092 1092 "added": ["a"],
1093 1093 "removed": []
1094 1094 }
1095 1095 ]
1096 1096
1097 1097 Error if style not readable:
1098 1098
1099 1099 #if unix-permissions no-root
1100 1100 $ touch q
1101 1101 $ chmod 0 q
1102 1102 $ hg log --style ./q
1103 1103 abort: Permission denied: ./q
1104 1104 [255]
1105 1105 #endif
1106 1106
1107 1107 Error if no style:
1108 1108
1109 1109 $ hg log --style notexist
1110 1110 abort: style 'notexist' not found
1111 1111 (available styles: bisect, changelog, compact, default, phases, status, xml)
1112 1112 [255]
1113 1113
1114 1114 $ hg log -T list
1115 1115 available styles: bisect, changelog, compact, default, phases, status, xml
1116 1116 abort: specify a template
1117 1117 [255]
1118 1118
1119 1119 Error if style missing key:
1120 1120
1121 1121 $ echo 'q = q' > t
1122 1122 $ hg log --style ./t
1123 1123 abort: "changeset" not in template map
1124 1124 [255]
1125 1125
1126 1126 Error if style missing value:
1127 1127
1128 1128 $ echo 'changeset =' > t
1129 1129 $ hg log --style t
1130 1130 hg: parse error at t:1: missing value
1131 1131 [255]
1132 1132
1133 1133 Error if include fails:
1134 1134
1135 1135 $ echo 'changeset = q' >> t
1136 1136 #if unix-permissions no-root
1137 1137 $ hg log --style ./t
1138 1138 abort: template file ./q: Permission denied
1139 1139 [255]
1140 1140 $ rm -f q
1141 1141 #endif
1142 1142
1143 1143 Include works:
1144 1144
1145 1145 $ echo '{rev}' > q
1146 1146 $ hg log --style ./t
1147 1147 8
1148 1148 7
1149 1149 6
1150 1150 5
1151 1151 4
1152 1152 3
1153 1153 2
1154 1154 1
1155 1155 0
1156 1156
1157 1157 Check that recursive reference does not fall into RuntimeError (issue4758):
1158 1158
1159 1159 common mistake:
1160 1160
1161 1161 $ hg log -T '{changeset}\n'
1162 1162 abort: recursive reference 'changeset' in template
1163 1163 [255]
1164 1164
1165 1165 circular reference:
1166 1166
1167 1167 $ cat << EOF > issue4758
1168 1168 > changeset = '{foo}'
1169 1169 > foo = '{changeset}'
1170 1170 > EOF
1171 1171 $ hg log --style ./issue4758
1172 1172 abort: recursive reference 'foo' in template
1173 1173 [255]
1174 1174
1175 1175 buildmap() -> gettemplate(), where no thunk was made:
1176 1176
1177 1177 $ hg log -T '{files % changeset}\n'
1178 1178 abort: recursive reference 'changeset' in template
1179 1179 [255]
1180 1180
1181 1181 not a recursion if a keyword of the same name exists:
1182 1182
1183 1183 $ cat << EOF > issue4758
1184 1184 > changeset = '{tags % rev}'
1185 1185 > rev = '{rev} {tag}\n'
1186 1186 > EOF
1187 1187 $ hg log --style ./issue4758 -r tip
1188 1188 8 tip
1189 1189
1190 1190 Check that {phase} works correctly on parents:
1191 1191
1192 1192 $ cat << EOF > parentphase
1193 1193 > changeset_debug = '{rev} ({phase}):{parents}\n'
1194 1194 > parent = ' {rev} ({phase})'
1195 1195 > EOF
1196 1196 $ hg phase -r 5 --public
1197 1197 $ hg phase -r 7 --secret --force
1198 1198 $ hg log --debug -G --style ./parentphase
1199 1199 @ 8 (secret): 7 (secret) -1 (public)
1200 1200 |
1201 1201 o 7 (secret): -1 (public) -1 (public)
1202 1202
1203 1203 o 6 (draft): 5 (public) 4 (draft)
1204 1204 |\
1205 1205 | o 5 (public): 3 (public) -1 (public)
1206 1206 | |
1207 1207 o | 4 (draft): 3 (public) -1 (public)
1208 1208 |/
1209 1209 o 3 (public): 2 (public) -1 (public)
1210 1210 |
1211 1211 o 2 (public): 1 (public) -1 (public)
1212 1212 |
1213 1213 o 1 (public): 0 (public) -1 (public)
1214 1214 |
1215 1215 o 0 (public): -1 (public) -1 (public)
1216 1216
1217 1217
1218 1218 Missing non-standard names give no error (backward compatibility):
1219 1219
1220 1220 $ echo "changeset = '{c}'" > t
1221 1221 $ hg log --style ./t
1222 1222
1223 1223 Defining non-standard name works:
1224 1224
1225 1225 $ cat <<EOF > t
1226 1226 > changeset = '{c}'
1227 1227 > c = q
1228 1228 > EOF
1229 1229 $ hg log --style ./t
1230 1230 8
1231 1231 7
1232 1232 6
1233 1233 5
1234 1234 4
1235 1235 3
1236 1236 2
1237 1237 1
1238 1238 0
1239 1239
1240 1240 ui.style works:
1241 1241
1242 1242 $ echo '[ui]' > .hg/hgrc
1243 1243 $ echo 'style = t' >> .hg/hgrc
1244 1244 $ hg log
1245 1245 8
1246 1246 7
1247 1247 6
1248 1248 5
1249 1249 4
1250 1250 3
1251 1251 2
1252 1252 1
1253 1253 0
1254 1254
1255 1255
1256 1256 Issue338:
1257 1257
1258 1258 $ hg log --style=changelog > changelog
1259 1259
1260 1260 $ cat changelog
1261 1261 2020-01-01 test <test>
1262 1262
1263 1263 * fourth, second, third:
1264 1264 third
1265 1265 [95c24699272e] [tip]
1266 1266
1267 1267 1970-01-12 User Name <user@hostname>
1268 1268
1269 1269 * second:
1270 1270 second
1271 1271 [29114dbae42b]
1272 1272
1273 1273 1970-01-18 person <person>
1274 1274
1275 1275 * merge
1276 1276 [d41e714fe50d]
1277 1277
1278 1278 * d:
1279 1279 new head
1280 1280 [13207e5a10d9]
1281 1281
1282 1282 1970-01-17 person <person>
1283 1283
1284 1284 * new branch
1285 1285 [bbe44766e73d] <foo>
1286 1286
1287 1287 1970-01-16 person <person>
1288 1288
1289 1289 * c:
1290 1290 no user, no domain
1291 1291 [10e46f2dcbf4]
1292 1292
1293 1293 1970-01-14 other <other@place>
1294 1294
1295 1295 * c:
1296 1296 no person
1297 1297 [97054abb4ab8]
1298 1298
1299 1299 1970-01-13 A. N. Other <other@place>
1300 1300
1301 1301 * b:
1302 1302 other 1 other 2
1303 1303
1304 1304 other 3
1305 1305 [b608e9d1a3f0]
1306 1306
1307 1307 1970-01-12 User Name <user@hostname>
1308 1308
1309 1309 * a:
1310 1310 line 1 line 2
1311 1311 [1e4e1b8f71e0]
1312 1312
1313 1313
1314 1314 Issue2130: xml output for 'hg heads' is malformed
1315 1315
1316 1316 $ hg heads --style changelog
1317 1317 2020-01-01 test <test>
1318 1318
1319 1319 * fourth, second, third:
1320 1320 third
1321 1321 [95c24699272e] [tip]
1322 1322
1323 1323 1970-01-18 person <person>
1324 1324
1325 1325 * merge
1326 1326 [d41e714fe50d]
1327 1327
1328 1328 1970-01-17 person <person>
1329 1329
1330 1330 * new branch
1331 1331 [bbe44766e73d] <foo>
1332 1332
1333 1333
1334 1334 Keys work:
1335 1335
1336 1336 $ for key in author branch branches date desc file_adds file_dels file_mods \
1337 1337 > file_copies file_copies_switch files \
1338 1338 > manifest node parents rev tags diffstat extras \
1339 1339 > p1rev p2rev p1node p2node; do
1340 1340 > for mode in '' --verbose --debug; do
1341 1341 > hg log $mode --template "$key$mode: {$key}\n"
1342 1342 > done
1343 1343 > done
1344 1344 author: test
1345 1345 author: User Name <user@hostname>
1346 1346 author: person
1347 1347 author: person
1348 1348 author: person
1349 1349 author: person
1350 1350 author: other@place
1351 1351 author: A. N. Other <other@place>
1352 1352 author: User Name <user@hostname>
1353 1353 author--verbose: test
1354 1354 author--verbose: User Name <user@hostname>
1355 1355 author--verbose: person
1356 1356 author--verbose: person
1357 1357 author--verbose: person
1358 1358 author--verbose: person
1359 1359 author--verbose: other@place
1360 1360 author--verbose: A. N. Other <other@place>
1361 1361 author--verbose: User Name <user@hostname>
1362 1362 author--debug: test
1363 1363 author--debug: User Name <user@hostname>
1364 1364 author--debug: person
1365 1365 author--debug: person
1366 1366 author--debug: person
1367 1367 author--debug: person
1368 1368 author--debug: other@place
1369 1369 author--debug: A. N. Other <other@place>
1370 1370 author--debug: User Name <user@hostname>
1371 1371 branch: default
1372 1372 branch: default
1373 1373 branch: default
1374 1374 branch: default
1375 1375 branch: foo
1376 1376 branch: default
1377 1377 branch: default
1378 1378 branch: default
1379 1379 branch: default
1380 1380 branch--verbose: default
1381 1381 branch--verbose: default
1382 1382 branch--verbose: default
1383 1383 branch--verbose: default
1384 1384 branch--verbose: foo
1385 1385 branch--verbose: default
1386 1386 branch--verbose: default
1387 1387 branch--verbose: default
1388 1388 branch--verbose: default
1389 1389 branch--debug: default
1390 1390 branch--debug: default
1391 1391 branch--debug: default
1392 1392 branch--debug: default
1393 1393 branch--debug: foo
1394 1394 branch--debug: default
1395 1395 branch--debug: default
1396 1396 branch--debug: default
1397 1397 branch--debug: default
1398 1398 branches:
1399 1399 branches:
1400 1400 branches:
1401 1401 branches:
1402 1402 branches: foo
1403 1403 branches:
1404 1404 branches:
1405 1405 branches:
1406 1406 branches:
1407 1407 branches--verbose:
1408 1408 branches--verbose:
1409 1409 branches--verbose:
1410 1410 branches--verbose:
1411 1411 branches--verbose: foo
1412 1412 branches--verbose:
1413 1413 branches--verbose:
1414 1414 branches--verbose:
1415 1415 branches--verbose:
1416 1416 branches--debug:
1417 1417 branches--debug:
1418 1418 branches--debug:
1419 1419 branches--debug:
1420 1420 branches--debug: foo
1421 1421 branches--debug:
1422 1422 branches--debug:
1423 1423 branches--debug:
1424 1424 branches--debug:
1425 1425 date: 1577872860.00
1426 1426 date: 1000000.00
1427 1427 date: 1500001.00
1428 1428 date: 1500000.00
1429 1429 date: 1400000.00
1430 1430 date: 1300000.00
1431 1431 date: 1200000.00
1432 1432 date: 1100000.00
1433 1433 date: 1000000.00
1434 1434 date--verbose: 1577872860.00
1435 1435 date--verbose: 1000000.00
1436 1436 date--verbose: 1500001.00
1437 1437 date--verbose: 1500000.00
1438 1438 date--verbose: 1400000.00
1439 1439 date--verbose: 1300000.00
1440 1440 date--verbose: 1200000.00
1441 1441 date--verbose: 1100000.00
1442 1442 date--verbose: 1000000.00
1443 1443 date--debug: 1577872860.00
1444 1444 date--debug: 1000000.00
1445 1445 date--debug: 1500001.00
1446 1446 date--debug: 1500000.00
1447 1447 date--debug: 1400000.00
1448 1448 date--debug: 1300000.00
1449 1449 date--debug: 1200000.00
1450 1450 date--debug: 1100000.00
1451 1451 date--debug: 1000000.00
1452 1452 desc: third
1453 1453 desc: second
1454 1454 desc: merge
1455 1455 desc: new head
1456 1456 desc: new branch
1457 1457 desc: no user, no domain
1458 1458 desc: no person
1459 1459 desc: other 1
1460 1460 other 2
1461 1461
1462 1462 other 3
1463 1463 desc: line 1
1464 1464 line 2
1465 1465 desc--verbose: third
1466 1466 desc--verbose: second
1467 1467 desc--verbose: merge
1468 1468 desc--verbose: new head
1469 1469 desc--verbose: new branch
1470 1470 desc--verbose: no user, no domain
1471 1471 desc--verbose: no person
1472 1472 desc--verbose: other 1
1473 1473 other 2
1474 1474
1475 1475 other 3
1476 1476 desc--verbose: line 1
1477 1477 line 2
1478 1478 desc--debug: third
1479 1479 desc--debug: second
1480 1480 desc--debug: merge
1481 1481 desc--debug: new head
1482 1482 desc--debug: new branch
1483 1483 desc--debug: no user, no domain
1484 1484 desc--debug: no person
1485 1485 desc--debug: other 1
1486 1486 other 2
1487 1487
1488 1488 other 3
1489 1489 desc--debug: line 1
1490 1490 line 2
1491 1491 file_adds: fourth third
1492 1492 file_adds: second
1493 1493 file_adds:
1494 1494 file_adds: d
1495 1495 file_adds:
1496 1496 file_adds:
1497 1497 file_adds: c
1498 1498 file_adds: b
1499 1499 file_adds: a
1500 1500 file_adds--verbose: fourth third
1501 1501 file_adds--verbose: second
1502 1502 file_adds--verbose:
1503 1503 file_adds--verbose: d
1504 1504 file_adds--verbose:
1505 1505 file_adds--verbose:
1506 1506 file_adds--verbose: c
1507 1507 file_adds--verbose: b
1508 1508 file_adds--verbose: a
1509 1509 file_adds--debug: fourth third
1510 1510 file_adds--debug: second
1511 1511 file_adds--debug:
1512 1512 file_adds--debug: d
1513 1513 file_adds--debug:
1514 1514 file_adds--debug:
1515 1515 file_adds--debug: c
1516 1516 file_adds--debug: b
1517 1517 file_adds--debug: a
1518 1518 file_dels: second
1519 1519 file_dels:
1520 1520 file_dels:
1521 1521 file_dels:
1522 1522 file_dels:
1523 1523 file_dels:
1524 1524 file_dels:
1525 1525 file_dels:
1526 1526 file_dels:
1527 1527 file_dels--verbose: second
1528 1528 file_dels--verbose:
1529 1529 file_dels--verbose:
1530 1530 file_dels--verbose:
1531 1531 file_dels--verbose:
1532 1532 file_dels--verbose:
1533 1533 file_dels--verbose:
1534 1534 file_dels--verbose:
1535 1535 file_dels--verbose:
1536 1536 file_dels--debug: second
1537 1537 file_dels--debug:
1538 1538 file_dels--debug:
1539 1539 file_dels--debug:
1540 1540 file_dels--debug:
1541 1541 file_dels--debug:
1542 1542 file_dels--debug:
1543 1543 file_dels--debug:
1544 1544 file_dels--debug:
1545 1545 file_mods:
1546 1546 file_mods:
1547 1547 file_mods:
1548 1548 file_mods:
1549 1549 file_mods:
1550 1550 file_mods: c
1551 1551 file_mods:
1552 1552 file_mods:
1553 1553 file_mods:
1554 1554 file_mods--verbose:
1555 1555 file_mods--verbose:
1556 1556 file_mods--verbose:
1557 1557 file_mods--verbose:
1558 1558 file_mods--verbose:
1559 1559 file_mods--verbose: c
1560 1560 file_mods--verbose:
1561 1561 file_mods--verbose:
1562 1562 file_mods--verbose:
1563 1563 file_mods--debug:
1564 1564 file_mods--debug:
1565 1565 file_mods--debug:
1566 1566 file_mods--debug:
1567 1567 file_mods--debug:
1568 1568 file_mods--debug: c
1569 1569 file_mods--debug:
1570 1570 file_mods--debug:
1571 1571 file_mods--debug:
1572 1572 file_copies: fourth (second)
1573 1573 file_copies:
1574 1574 file_copies:
1575 1575 file_copies:
1576 1576 file_copies:
1577 1577 file_copies:
1578 1578 file_copies:
1579 1579 file_copies:
1580 1580 file_copies:
1581 1581 file_copies--verbose: fourth (second)
1582 1582 file_copies--verbose:
1583 1583 file_copies--verbose:
1584 1584 file_copies--verbose:
1585 1585 file_copies--verbose:
1586 1586 file_copies--verbose:
1587 1587 file_copies--verbose:
1588 1588 file_copies--verbose:
1589 1589 file_copies--verbose:
1590 1590 file_copies--debug: fourth (second)
1591 1591 file_copies--debug:
1592 1592 file_copies--debug:
1593 1593 file_copies--debug:
1594 1594 file_copies--debug:
1595 1595 file_copies--debug:
1596 1596 file_copies--debug:
1597 1597 file_copies--debug:
1598 1598 file_copies--debug:
1599 1599 file_copies_switch:
1600 1600 file_copies_switch:
1601 1601 file_copies_switch:
1602 1602 file_copies_switch:
1603 1603 file_copies_switch:
1604 1604 file_copies_switch:
1605 1605 file_copies_switch:
1606 1606 file_copies_switch:
1607 1607 file_copies_switch:
1608 1608 file_copies_switch--verbose:
1609 1609 file_copies_switch--verbose:
1610 1610 file_copies_switch--verbose:
1611 1611 file_copies_switch--verbose:
1612 1612 file_copies_switch--verbose:
1613 1613 file_copies_switch--verbose:
1614 1614 file_copies_switch--verbose:
1615 1615 file_copies_switch--verbose:
1616 1616 file_copies_switch--verbose:
1617 1617 file_copies_switch--debug:
1618 1618 file_copies_switch--debug:
1619 1619 file_copies_switch--debug:
1620 1620 file_copies_switch--debug:
1621 1621 file_copies_switch--debug:
1622 1622 file_copies_switch--debug:
1623 1623 file_copies_switch--debug:
1624 1624 file_copies_switch--debug:
1625 1625 file_copies_switch--debug:
1626 1626 files: fourth second third
1627 1627 files: second
1628 1628 files:
1629 1629 files: d
1630 1630 files:
1631 1631 files: c
1632 1632 files: c
1633 1633 files: b
1634 1634 files: a
1635 1635 files--verbose: fourth second third
1636 1636 files--verbose: second
1637 1637 files--verbose:
1638 1638 files--verbose: d
1639 1639 files--verbose:
1640 1640 files--verbose: c
1641 1641 files--verbose: c
1642 1642 files--verbose: b
1643 1643 files--verbose: a
1644 1644 files--debug: fourth second third
1645 1645 files--debug: second
1646 1646 files--debug:
1647 1647 files--debug: d
1648 1648 files--debug:
1649 1649 files--debug: c
1650 1650 files--debug: c
1651 1651 files--debug: b
1652 1652 files--debug: a
1653 1653 manifest: 6:94961b75a2da
1654 1654 manifest: 5:f2dbc354b94e
1655 1655 manifest: 4:4dc3def4f9b4
1656 1656 manifest: 4:4dc3def4f9b4
1657 1657 manifest: 3:cb5a1327723b
1658 1658 manifest: 3:cb5a1327723b
1659 1659 manifest: 2:6e0e82995c35
1660 1660 manifest: 1:4e8d705b1e53
1661 1661 manifest: 0:a0c8bcbbb45c
1662 1662 manifest--verbose: 6:94961b75a2da
1663 1663 manifest--verbose: 5:f2dbc354b94e
1664 1664 manifest--verbose: 4:4dc3def4f9b4
1665 1665 manifest--verbose: 4:4dc3def4f9b4
1666 1666 manifest--verbose: 3:cb5a1327723b
1667 1667 manifest--verbose: 3:cb5a1327723b
1668 1668 manifest--verbose: 2:6e0e82995c35
1669 1669 manifest--verbose: 1:4e8d705b1e53
1670 1670 manifest--verbose: 0:a0c8bcbbb45c
1671 1671 manifest--debug: 6:94961b75a2da554b4df6fb599e5bfc7d48de0c64
1672 1672 manifest--debug: 5:f2dbc354b94e5ec0b4f10680ee0cee816101d0bf
1673 1673 manifest--debug: 4:4dc3def4f9b4c6e8de820f6ee74737f91e96a216
1674 1674 manifest--debug: 4:4dc3def4f9b4c6e8de820f6ee74737f91e96a216
1675 1675 manifest--debug: 3:cb5a1327723bada42f117e4c55a303246eaf9ccc
1676 1676 manifest--debug: 3:cb5a1327723bada42f117e4c55a303246eaf9ccc
1677 1677 manifest--debug: 2:6e0e82995c35d0d57a52aca8da4e56139e06b4b1
1678 1678 manifest--debug: 1:4e8d705b1e53e3f9375e0e60dc7b525d8211fe55
1679 1679 manifest--debug: 0:a0c8bcbbb45c63b90b70ad007bf38961f64f2af0
1680 1680 node: 95c24699272ef57d062b8bccc32c878bf841784a
1681 1681 node: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
1682 1682 node: d41e714fe50d9e4a5f11b4d595d543481b5f980b
1683 1683 node: 13207e5a10d9fd28ec424934298e176197f2c67f
1684 1684 node: bbe44766e73d5f11ed2177f1838de10c53ef3e74
1685 1685 node: 10e46f2dcbf4823578cf180f33ecf0b957964c47
1686 1686 node: 97054abb4ab824450e9164180baf491ae0078465
1687 1687 node: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
1688 1688 node: 1e4e1b8f71e05681d422154f5421e385fec3454f
1689 1689 node--verbose: 95c24699272ef57d062b8bccc32c878bf841784a
1690 1690 node--verbose: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
1691 1691 node--verbose: d41e714fe50d9e4a5f11b4d595d543481b5f980b
1692 1692 node--verbose: 13207e5a10d9fd28ec424934298e176197f2c67f
1693 1693 node--verbose: bbe44766e73d5f11ed2177f1838de10c53ef3e74
1694 1694 node--verbose: 10e46f2dcbf4823578cf180f33ecf0b957964c47
1695 1695 node--verbose: 97054abb4ab824450e9164180baf491ae0078465
1696 1696 node--verbose: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
1697 1697 node--verbose: 1e4e1b8f71e05681d422154f5421e385fec3454f
1698 1698 node--debug: 95c24699272ef57d062b8bccc32c878bf841784a
1699 1699 node--debug: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
1700 1700 node--debug: d41e714fe50d9e4a5f11b4d595d543481b5f980b
1701 1701 node--debug: 13207e5a10d9fd28ec424934298e176197f2c67f
1702 1702 node--debug: bbe44766e73d5f11ed2177f1838de10c53ef3e74
1703 1703 node--debug: 10e46f2dcbf4823578cf180f33ecf0b957964c47
1704 1704 node--debug: 97054abb4ab824450e9164180baf491ae0078465
1705 1705 node--debug: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
1706 1706 node--debug: 1e4e1b8f71e05681d422154f5421e385fec3454f
1707 1707 parents:
1708 1708 parents: -1:000000000000
1709 1709 parents: 5:13207e5a10d9 4:bbe44766e73d
1710 1710 parents: 3:10e46f2dcbf4
1711 1711 parents:
1712 1712 parents:
1713 1713 parents:
1714 1714 parents:
1715 1715 parents:
1716 1716 parents--verbose:
1717 1717 parents--verbose: -1:000000000000
1718 1718 parents--verbose: 5:13207e5a10d9 4:bbe44766e73d
1719 1719 parents--verbose: 3:10e46f2dcbf4
1720 1720 parents--verbose:
1721 1721 parents--verbose:
1722 1722 parents--verbose:
1723 1723 parents--verbose:
1724 1724 parents--verbose:
1725 1725 parents--debug: 7:29114dbae42b9f078cf2714dbe3a86bba8ec7453 -1:0000000000000000000000000000000000000000
1726 1726 parents--debug: -1:0000000000000000000000000000000000000000 -1:0000000000000000000000000000000000000000
1727 1727 parents--debug: 5:13207e5a10d9fd28ec424934298e176197f2c67f 4:bbe44766e73d5f11ed2177f1838de10c53ef3e74
1728 1728 parents--debug: 3:10e46f2dcbf4823578cf180f33ecf0b957964c47 -1:0000000000000000000000000000000000000000
1729 1729 parents--debug: 3:10e46f2dcbf4823578cf180f33ecf0b957964c47 -1:0000000000000000000000000000000000000000
1730 1730 parents--debug: 2:97054abb4ab824450e9164180baf491ae0078465 -1:0000000000000000000000000000000000000000
1731 1731 parents--debug: 1:b608e9d1a3f0273ccf70fb85fd6866b3482bf965 -1:0000000000000000000000000000000000000000
1732 1732 parents--debug: 0:1e4e1b8f71e05681d422154f5421e385fec3454f -1:0000000000000000000000000000000000000000
1733 1733 parents--debug: -1:0000000000000000000000000000000000000000 -1:0000000000000000000000000000000000000000
1734 1734 rev: 8
1735 1735 rev: 7
1736 1736 rev: 6
1737 1737 rev: 5
1738 1738 rev: 4
1739 1739 rev: 3
1740 1740 rev: 2
1741 1741 rev: 1
1742 1742 rev: 0
1743 1743 rev--verbose: 8
1744 1744 rev--verbose: 7
1745 1745 rev--verbose: 6
1746 1746 rev--verbose: 5
1747 1747 rev--verbose: 4
1748 1748 rev--verbose: 3
1749 1749 rev--verbose: 2
1750 1750 rev--verbose: 1
1751 1751 rev--verbose: 0
1752 1752 rev--debug: 8
1753 1753 rev--debug: 7
1754 1754 rev--debug: 6
1755 1755 rev--debug: 5
1756 1756 rev--debug: 4
1757 1757 rev--debug: 3
1758 1758 rev--debug: 2
1759 1759 rev--debug: 1
1760 1760 rev--debug: 0
1761 1761 tags: tip
1762 1762 tags:
1763 1763 tags:
1764 1764 tags:
1765 1765 tags:
1766 1766 tags:
1767 1767 tags:
1768 1768 tags:
1769 1769 tags:
1770 1770 tags--verbose: tip
1771 1771 tags--verbose:
1772 1772 tags--verbose:
1773 1773 tags--verbose:
1774 1774 tags--verbose:
1775 1775 tags--verbose:
1776 1776 tags--verbose:
1777 1777 tags--verbose:
1778 1778 tags--verbose:
1779 1779 tags--debug: tip
1780 1780 tags--debug:
1781 1781 tags--debug:
1782 1782 tags--debug:
1783 1783 tags--debug:
1784 1784 tags--debug:
1785 1785 tags--debug:
1786 1786 tags--debug:
1787 1787 tags--debug:
1788 1788 diffstat: 3: +2/-1
1789 1789 diffstat: 1: +1/-0
1790 1790 diffstat: 0: +0/-0
1791 1791 diffstat: 1: +1/-0
1792 1792 diffstat: 0: +0/-0
1793 1793 diffstat: 1: +1/-0
1794 1794 diffstat: 1: +4/-0
1795 1795 diffstat: 1: +2/-0
1796 1796 diffstat: 1: +1/-0
1797 1797 diffstat--verbose: 3: +2/-1
1798 1798 diffstat--verbose: 1: +1/-0
1799 1799 diffstat--verbose: 0: +0/-0
1800 1800 diffstat--verbose: 1: +1/-0
1801 1801 diffstat--verbose: 0: +0/-0
1802 1802 diffstat--verbose: 1: +1/-0
1803 1803 diffstat--verbose: 1: +4/-0
1804 1804 diffstat--verbose: 1: +2/-0
1805 1805 diffstat--verbose: 1: +1/-0
1806 1806 diffstat--debug: 3: +2/-1
1807 1807 diffstat--debug: 1: +1/-0
1808 1808 diffstat--debug: 0: +0/-0
1809 1809 diffstat--debug: 1: +1/-0
1810 1810 diffstat--debug: 0: +0/-0
1811 1811 diffstat--debug: 1: +1/-0
1812 1812 diffstat--debug: 1: +4/-0
1813 1813 diffstat--debug: 1: +2/-0
1814 1814 diffstat--debug: 1: +1/-0
1815 1815 extras: branch=default
1816 1816 extras: branch=default
1817 1817 extras: branch=default
1818 1818 extras: branch=default
1819 1819 extras: branch=foo
1820 1820 extras: branch=default
1821 1821 extras: branch=default
1822 1822 extras: branch=default
1823 1823 extras: branch=default
1824 1824 extras--verbose: branch=default
1825 1825 extras--verbose: branch=default
1826 1826 extras--verbose: branch=default
1827 1827 extras--verbose: branch=default
1828 1828 extras--verbose: branch=foo
1829 1829 extras--verbose: branch=default
1830 1830 extras--verbose: branch=default
1831 1831 extras--verbose: branch=default
1832 1832 extras--verbose: branch=default
1833 1833 extras--debug: branch=default
1834 1834 extras--debug: branch=default
1835 1835 extras--debug: branch=default
1836 1836 extras--debug: branch=default
1837 1837 extras--debug: branch=foo
1838 1838 extras--debug: branch=default
1839 1839 extras--debug: branch=default
1840 1840 extras--debug: branch=default
1841 1841 extras--debug: branch=default
1842 1842 p1rev: 7
1843 1843 p1rev: -1
1844 1844 p1rev: 5
1845 1845 p1rev: 3
1846 1846 p1rev: 3
1847 1847 p1rev: 2
1848 1848 p1rev: 1
1849 1849 p1rev: 0
1850 1850 p1rev: -1
1851 1851 p1rev--verbose: 7
1852 1852 p1rev--verbose: -1
1853 1853 p1rev--verbose: 5
1854 1854 p1rev--verbose: 3
1855 1855 p1rev--verbose: 3
1856 1856 p1rev--verbose: 2
1857 1857 p1rev--verbose: 1
1858 1858 p1rev--verbose: 0
1859 1859 p1rev--verbose: -1
1860 1860 p1rev--debug: 7
1861 1861 p1rev--debug: -1
1862 1862 p1rev--debug: 5
1863 1863 p1rev--debug: 3
1864 1864 p1rev--debug: 3
1865 1865 p1rev--debug: 2
1866 1866 p1rev--debug: 1
1867 1867 p1rev--debug: 0
1868 1868 p1rev--debug: -1
1869 1869 p2rev: -1
1870 1870 p2rev: -1
1871 1871 p2rev: 4
1872 1872 p2rev: -1
1873 1873 p2rev: -1
1874 1874 p2rev: -1
1875 1875 p2rev: -1
1876 1876 p2rev: -1
1877 1877 p2rev: -1
1878 1878 p2rev--verbose: -1
1879 1879 p2rev--verbose: -1
1880 1880 p2rev--verbose: 4
1881 1881 p2rev--verbose: -1
1882 1882 p2rev--verbose: -1
1883 1883 p2rev--verbose: -1
1884 1884 p2rev--verbose: -1
1885 1885 p2rev--verbose: -1
1886 1886 p2rev--verbose: -1
1887 1887 p2rev--debug: -1
1888 1888 p2rev--debug: -1
1889 1889 p2rev--debug: 4
1890 1890 p2rev--debug: -1
1891 1891 p2rev--debug: -1
1892 1892 p2rev--debug: -1
1893 1893 p2rev--debug: -1
1894 1894 p2rev--debug: -1
1895 1895 p2rev--debug: -1
1896 1896 p1node: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
1897 1897 p1node: 0000000000000000000000000000000000000000
1898 1898 p1node: 13207e5a10d9fd28ec424934298e176197f2c67f
1899 1899 p1node: 10e46f2dcbf4823578cf180f33ecf0b957964c47
1900 1900 p1node: 10e46f2dcbf4823578cf180f33ecf0b957964c47
1901 1901 p1node: 97054abb4ab824450e9164180baf491ae0078465
1902 1902 p1node: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
1903 1903 p1node: 1e4e1b8f71e05681d422154f5421e385fec3454f
1904 1904 p1node: 0000000000000000000000000000000000000000
1905 1905 p1node--verbose: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
1906 1906 p1node--verbose: 0000000000000000000000000000000000000000
1907 1907 p1node--verbose: 13207e5a10d9fd28ec424934298e176197f2c67f
1908 1908 p1node--verbose: 10e46f2dcbf4823578cf180f33ecf0b957964c47
1909 1909 p1node--verbose: 10e46f2dcbf4823578cf180f33ecf0b957964c47
1910 1910 p1node--verbose: 97054abb4ab824450e9164180baf491ae0078465
1911 1911 p1node--verbose: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
1912 1912 p1node--verbose: 1e4e1b8f71e05681d422154f5421e385fec3454f
1913 1913 p1node--verbose: 0000000000000000000000000000000000000000
1914 1914 p1node--debug: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
1915 1915 p1node--debug: 0000000000000000000000000000000000000000
1916 1916 p1node--debug: 13207e5a10d9fd28ec424934298e176197f2c67f
1917 1917 p1node--debug: 10e46f2dcbf4823578cf180f33ecf0b957964c47
1918 1918 p1node--debug: 10e46f2dcbf4823578cf180f33ecf0b957964c47
1919 1919 p1node--debug: 97054abb4ab824450e9164180baf491ae0078465
1920 1920 p1node--debug: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
1921 1921 p1node--debug: 1e4e1b8f71e05681d422154f5421e385fec3454f
1922 1922 p1node--debug: 0000000000000000000000000000000000000000
1923 1923 p2node: 0000000000000000000000000000000000000000
1924 1924 p2node: 0000000000000000000000000000000000000000
1925 1925 p2node: bbe44766e73d5f11ed2177f1838de10c53ef3e74
1926 1926 p2node: 0000000000000000000000000000000000000000
1927 1927 p2node: 0000000000000000000000000000000000000000
1928 1928 p2node: 0000000000000000000000000000000000000000
1929 1929 p2node: 0000000000000000000000000000000000000000
1930 1930 p2node: 0000000000000000000000000000000000000000
1931 1931 p2node: 0000000000000000000000000000000000000000
1932 1932 p2node--verbose: 0000000000000000000000000000000000000000
1933 1933 p2node--verbose: 0000000000000000000000000000000000000000
1934 1934 p2node--verbose: bbe44766e73d5f11ed2177f1838de10c53ef3e74
1935 1935 p2node--verbose: 0000000000000000000000000000000000000000
1936 1936 p2node--verbose: 0000000000000000000000000000000000000000
1937 1937 p2node--verbose: 0000000000000000000000000000000000000000
1938 1938 p2node--verbose: 0000000000000000000000000000000000000000
1939 1939 p2node--verbose: 0000000000000000000000000000000000000000
1940 1940 p2node--verbose: 0000000000000000000000000000000000000000
1941 1941 p2node--debug: 0000000000000000000000000000000000000000
1942 1942 p2node--debug: 0000000000000000000000000000000000000000
1943 1943 p2node--debug: bbe44766e73d5f11ed2177f1838de10c53ef3e74
1944 1944 p2node--debug: 0000000000000000000000000000000000000000
1945 1945 p2node--debug: 0000000000000000000000000000000000000000
1946 1946 p2node--debug: 0000000000000000000000000000000000000000
1947 1947 p2node--debug: 0000000000000000000000000000000000000000
1948 1948 p2node--debug: 0000000000000000000000000000000000000000
1949 1949 p2node--debug: 0000000000000000000000000000000000000000
1950 1950
1951 1951 Filters work:
1952 1952
1953 1953 $ hg log --template '{author|domain}\n'
1954 1954
1955 1955 hostname
1956 1956
1957 1957
1958 1958
1959 1959
1960 1960 place
1961 1961 place
1962 1962 hostname
1963 1963
1964 1964 $ hg log --template '{author|person}\n'
1965 1965 test
1966 1966 User Name
1967 1967 person
1968 1968 person
1969 1969 person
1970 1970 person
1971 1971 other
1972 1972 A. N. Other
1973 1973 User Name
1974 1974
1975 1975 $ hg log --template '{author|user}\n'
1976 1976 test
1977 1977 user
1978 1978 person
1979 1979 person
1980 1980 person
1981 1981 person
1982 1982 other
1983 1983 other
1984 1984 user
1985 1985
1986 1986 $ hg log --template '{date|date}\n'
1987 1987 Wed Jan 01 10:01:00 2020 +0000
1988 1988 Mon Jan 12 13:46:40 1970 +0000
1989 1989 Sun Jan 18 08:40:01 1970 +0000
1990 1990 Sun Jan 18 08:40:00 1970 +0000
1991 1991 Sat Jan 17 04:53:20 1970 +0000
1992 1992 Fri Jan 16 01:06:40 1970 +0000
1993 1993 Wed Jan 14 21:20:00 1970 +0000
1994 1994 Tue Jan 13 17:33:20 1970 +0000
1995 1995 Mon Jan 12 13:46:40 1970 +0000
1996 1996
1997 1997 $ hg log --template '{date|isodate}\n'
1998 1998 2020-01-01 10:01 +0000
1999 1999 1970-01-12 13:46 +0000
2000 2000 1970-01-18 08:40 +0000
2001 2001 1970-01-18 08:40 +0000
2002 2002 1970-01-17 04:53 +0000
2003 2003 1970-01-16 01:06 +0000
2004 2004 1970-01-14 21:20 +0000
2005 2005 1970-01-13 17:33 +0000
2006 2006 1970-01-12 13:46 +0000
2007 2007
2008 2008 $ hg log --template '{date|isodatesec}\n'
2009 2009 2020-01-01 10:01:00 +0000
2010 2010 1970-01-12 13:46:40 +0000
2011 2011 1970-01-18 08:40:01 +0000
2012 2012 1970-01-18 08:40:00 +0000
2013 2013 1970-01-17 04:53:20 +0000
2014 2014 1970-01-16 01:06:40 +0000
2015 2015 1970-01-14 21:20:00 +0000
2016 2016 1970-01-13 17:33:20 +0000
2017 2017 1970-01-12 13:46:40 +0000
2018 2018
2019 2019 $ hg log --template '{date|rfc822date}\n'
2020 2020 Wed, 01 Jan 2020 10:01:00 +0000
2021 2021 Mon, 12 Jan 1970 13:46:40 +0000
2022 2022 Sun, 18 Jan 1970 08:40:01 +0000
2023 2023 Sun, 18 Jan 1970 08:40:00 +0000
2024 2024 Sat, 17 Jan 1970 04:53:20 +0000
2025 2025 Fri, 16 Jan 1970 01:06:40 +0000
2026 2026 Wed, 14 Jan 1970 21:20:00 +0000
2027 2027 Tue, 13 Jan 1970 17:33:20 +0000
2028 2028 Mon, 12 Jan 1970 13:46:40 +0000
2029 2029
2030 2030 $ hg log --template '{desc|firstline}\n'
2031 2031 third
2032 2032 second
2033 2033 merge
2034 2034 new head
2035 2035 new branch
2036 2036 no user, no domain
2037 2037 no person
2038 2038 other 1
2039 2039 line 1
2040 2040
2041 2041 $ hg log --template '{node|short}\n'
2042 2042 95c24699272e
2043 2043 29114dbae42b
2044 2044 d41e714fe50d
2045 2045 13207e5a10d9
2046 2046 bbe44766e73d
2047 2047 10e46f2dcbf4
2048 2048 97054abb4ab8
2049 2049 b608e9d1a3f0
2050 2050 1e4e1b8f71e0
2051 2051
2052 2052 $ hg log --template '<changeset author="{author|xmlescape}"/>\n'
2053 2053 <changeset author="test"/>
2054 2054 <changeset author="User Name &lt;user@hostname&gt;"/>
2055 2055 <changeset author="person"/>
2056 2056 <changeset author="person"/>
2057 2057 <changeset author="person"/>
2058 2058 <changeset author="person"/>
2059 2059 <changeset author="other@place"/>
2060 2060 <changeset author="A. N. Other &lt;other@place&gt;"/>
2061 2061 <changeset author="User Name &lt;user@hostname&gt;"/>
2062 2062
2063 2063 $ hg log --template '{rev}: {children}\n'
2064 2064 8:
2065 2065 7: 8:95c24699272e
2066 2066 6:
2067 2067 5: 6:d41e714fe50d
2068 2068 4: 6:d41e714fe50d
2069 2069 3: 4:bbe44766e73d 5:13207e5a10d9
2070 2070 2: 3:10e46f2dcbf4
2071 2071 1: 2:97054abb4ab8
2072 2072 0: 1:b608e9d1a3f0
2073 2073
2074 2074 Formatnode filter works:
2075 2075
2076 2076 $ hg -q log -r 0 --template '{node|formatnode}\n'
2077 2077 1e4e1b8f71e0
2078 2078
2079 2079 $ hg log -r 0 --template '{node|formatnode}\n'
2080 2080 1e4e1b8f71e0
2081 2081
2082 2082 $ hg -v log -r 0 --template '{node|formatnode}\n'
2083 2083 1e4e1b8f71e0
2084 2084
2085 2085 $ hg --debug log -r 0 --template '{node|formatnode}\n'
2086 2086 1e4e1b8f71e05681d422154f5421e385fec3454f
2087 2087
2088 2088 Age filter:
2089 2089
2090 2090 $ hg init unstable-hash
2091 2091 $ cd unstable-hash
2092 2092 $ hg log --template '{date|age}\n' > /dev/null || exit 1
2093 2093
2094 2094 >>> from datetime import datetime, timedelta
2095 2095 >>> fp = open('a', 'w')
2096 2096 >>> n = datetime.now() + timedelta(366 * 7)
2097 2097 >>> fp.write('%d-%d-%d 00:00' % (n.year, n.month, n.day))
2098 2098 >>> fp.close()
2099 2099 $ hg add a
2100 2100 $ hg commit -m future -d "`cat a`"
2101 2101
2102 2102 $ hg log -l1 --template '{date|age}\n'
2103 2103 7 years from now
2104 2104
2105 2105 $ cd ..
2106 2106 $ rm -rf unstable-hash
2107 2107
2108 2108 Add a dummy commit to make up for the instability of the above:
2109 2109
2110 2110 $ echo a > a
2111 2111 $ hg add a
2112 2112 $ hg ci -m future
2113 2113
2114 2114 Count filter:
2115 2115
2116 2116 $ hg log -l1 --template '{node|count} {node|short|count}\n'
2117 2117 40 12
2118 2118
2119 2119 $ hg log -l1 --template '{revset("null^")|count} {revset(".")|count} {revset("0::3")|count}\n'
2120 2120 0 1 4
2121 2121
2122 2122 $ hg log -G --template '{rev}: children: {children|count}, \
2123 2123 > tags: {tags|count}, file_adds: {file_adds|count}, \
2124 2124 > ancestors: {revset("ancestors(%s)", rev)|count}'
2125 2125 @ 9: children: 0, tags: 1, file_adds: 1, ancestors: 3
2126 2126 |
2127 2127 o 8: children: 1, tags: 0, file_adds: 2, ancestors: 2
2128 2128 |
2129 2129 o 7: children: 1, tags: 0, file_adds: 1, ancestors: 1
2130 2130
2131 2131 o 6: children: 0, tags: 0, file_adds: 0, ancestors: 7
2132 2132 |\
2133 2133 | o 5: children: 1, tags: 0, file_adds: 1, ancestors: 5
2134 2134 | |
2135 2135 o | 4: children: 1, tags: 0, file_adds: 0, ancestors: 5
2136 2136 |/
2137 2137 o 3: children: 2, tags: 0, file_adds: 0, ancestors: 4
2138 2138 |
2139 2139 o 2: children: 1, tags: 0, file_adds: 1, ancestors: 3
2140 2140 |
2141 2141 o 1: children: 1, tags: 0, file_adds: 1, ancestors: 2
2142 2142 |
2143 2143 o 0: children: 1, tags: 0, file_adds: 1, ancestors: 1
2144 2144
2145 2145
2146 2146 Upper/lower filters:
2147 2147
2148 2148 $ hg log -r0 --template '{branch|upper}\n'
2149 2149 DEFAULT
2150 2150 $ hg log -r0 --template '{author|lower}\n'
2151 2151 user name <user@hostname>
2152 2152 $ hg log -r0 --template '{date|upper}\n'
2153 2153 abort: template filter 'upper' is not compatible with keyword 'date'
2154 2154 [255]
2155 2155
2156 2156 Add a commit that does all possible modifications at once
2157 2157
2158 2158 $ echo modify >> third
2159 2159 $ touch b
2160 2160 $ hg add b
2161 2161 $ hg mv fourth fifth
2162 2162 $ hg rm a
2163 2163 $ hg ci -m "Modify, add, remove, rename"
2164 2164
2165 2165 Check the status template
2166 2166
2167 2167 $ cat <<EOF >> $HGRCPATH
2168 2168 > [extensions]
2169 2169 > color=
2170 2170 > EOF
2171 2171
2172 2172 $ hg log -T status -r 10
2173 2173 changeset: 10:0f9759ec227a
2174 2174 tag: tip
2175 2175 user: test
2176 2176 date: Thu Jan 01 00:00:00 1970 +0000
2177 2177 summary: Modify, add, remove, rename
2178 2178 files:
2179 2179 M third
2180 2180 A b
2181 2181 A fifth
2182 2182 R a
2183 2183 R fourth
2184 2184
2185 2185 $ hg log -T status -C -r 10
2186 2186 changeset: 10:0f9759ec227a
2187 2187 tag: tip
2188 2188 user: test
2189 2189 date: Thu Jan 01 00:00:00 1970 +0000
2190 2190 summary: Modify, add, remove, rename
2191 2191 files:
2192 2192 M third
2193 2193 A b
2194 2194 A fifth
2195 2195 fourth
2196 2196 R a
2197 2197 R fourth
2198 2198
2199 2199 $ hg log -T status -C -r 10 -v
2200 2200 changeset: 10:0f9759ec227a
2201 2201 tag: tip
2202 2202 user: test
2203 2203 date: Thu Jan 01 00:00:00 1970 +0000
2204 2204 description:
2205 2205 Modify, add, remove, rename
2206 2206
2207 2207 files:
2208 2208 M third
2209 2209 A b
2210 2210 A fifth
2211 2211 fourth
2212 2212 R a
2213 2213 R fourth
2214 2214
2215 2215 $ hg log -T status -C -r 10 --debug
2216 2216 changeset: 10:0f9759ec227a4859c2014a345cd8a859022b7c6c
2217 2217 tag: tip
2218 2218 phase: secret
2219 2219 parent: 9:bf9dfba36635106d6a73ccc01e28b762da60e066
2220 2220 parent: -1:0000000000000000000000000000000000000000
2221 2221 manifest: 8:89dd546f2de0a9d6d664f58d86097eb97baba567
2222 2222 user: test
2223 2223 date: Thu Jan 01 00:00:00 1970 +0000
2224 2224 extra: branch=default
2225 2225 description:
2226 2226 Modify, add, remove, rename
2227 2227
2228 2228 files:
2229 2229 M third
2230 2230 A b
2231 2231 A fifth
2232 2232 fourth
2233 2233 R a
2234 2234 R fourth
2235 2235
2236 2236 $ hg log -T status -C -r 10 --quiet
2237 2237 10:0f9759ec227a
2238 2238 $ hg --color=debug log -T status -r 10
2239 2239 [log.changeset changeset.secret|changeset: 10:0f9759ec227a]
2240 2240 [log.tag|tag: tip]
2241 2241 [log.user|user: test]
2242 2242 [log.date|date: Thu Jan 01 00:00:00 1970 +0000]
2243 2243 [log.summary|summary: Modify, add, remove, rename]
2244 2244 [ui.note log.files|files:]
2245 2245 [status.modified|M third]
2246 2246 [status.added|A b]
2247 2247 [status.added|A fifth]
2248 2248 [status.removed|R a]
2249 2249 [status.removed|R fourth]
2250 2250
2251 2251 $ hg --color=debug log -T status -C -r 10
2252 2252 [log.changeset changeset.secret|changeset: 10:0f9759ec227a]
2253 2253 [log.tag|tag: tip]
2254 2254 [log.user|user: test]
2255 2255 [log.date|date: Thu Jan 01 00:00:00 1970 +0000]
2256 2256 [log.summary|summary: Modify, add, remove, rename]
2257 2257 [ui.note log.files|files:]
2258 2258 [status.modified|M third]
2259 2259 [status.added|A b]
2260 2260 [status.added|A fifth]
2261 2261 [status.copied| fourth]
2262 2262 [status.removed|R a]
2263 2263 [status.removed|R fourth]
2264 2264
2265 2265 $ hg --color=debug log -T status -C -r 10 -v
2266 2266 [log.changeset changeset.secret|changeset: 10:0f9759ec227a]
2267 2267 [log.tag|tag: tip]
2268 2268 [log.user|user: test]
2269 2269 [log.date|date: Thu Jan 01 00:00:00 1970 +0000]
2270 2270 [ui.note log.description|description:]
2271 2271 [ui.note log.description|Modify, add, remove, rename]
2272 2272
2273 2273 [ui.note log.files|files:]
2274 2274 [status.modified|M third]
2275 2275 [status.added|A b]
2276 2276 [status.added|A fifth]
2277 2277 [status.copied| fourth]
2278 2278 [status.removed|R a]
2279 2279 [status.removed|R fourth]
2280 2280
2281 2281 $ hg --color=debug log -T status -C -r 10 --debug
2282 2282 [log.changeset changeset.secret|changeset: 10:0f9759ec227a4859c2014a345cd8a859022b7c6c]
2283 2283 [log.tag|tag: tip]
2284 2284 [log.phase|phase: secret]
2285 2285 [log.parent changeset.secret|parent: 9:bf9dfba36635106d6a73ccc01e28b762da60e066]
2286 2286 [log.parent changeset.public|parent: -1:0000000000000000000000000000000000000000]
2287 2287 [ui.debug log.manifest|manifest: 8:89dd546f2de0a9d6d664f58d86097eb97baba567]
2288 2288 [log.user|user: test]
2289 2289 [log.date|date: Thu Jan 01 00:00:00 1970 +0000]
2290 2290 [ui.debug log.extra|extra: branch=default]
2291 2291 [ui.note log.description|description:]
2292 2292 [ui.note log.description|Modify, add, remove, rename]
2293 2293
2294 2294 [ui.note log.files|files:]
2295 2295 [status.modified|M third]
2296 2296 [status.added|A b]
2297 2297 [status.added|A fifth]
2298 2298 [status.copied| fourth]
2299 2299 [status.removed|R a]
2300 2300 [status.removed|R fourth]
2301 2301
2302 2302 $ hg --color=debug log -T status -C -r 10 --quiet
2303 2303 [log.node|10:0f9759ec227a]
2304 2304
2305 2305 Check the bisect template
2306 2306
2307 2307 $ hg bisect -g 1
2308 2308 $ hg bisect -b 3 --noupdate
2309 2309 Testing changeset 2:97054abb4ab8 (2 changesets remaining, ~1 tests)
2310 2310 $ hg log -T bisect -r 0:4
2311 2311 changeset: 0:1e4e1b8f71e0
2312 2312 bisect: good (implicit)
2313 2313 user: User Name <user@hostname>
2314 2314 date: Mon Jan 12 13:46:40 1970 +0000
2315 2315 summary: line 1
2316 2316
2317 2317 changeset: 1:b608e9d1a3f0
2318 2318 bisect: good
2319 2319 user: A. N. Other <other@place>
2320 2320 date: Tue Jan 13 17:33:20 1970 +0000
2321 2321 summary: other 1
2322 2322
2323 2323 changeset: 2:97054abb4ab8
2324 2324 bisect: untested
2325 2325 user: other@place
2326 2326 date: Wed Jan 14 21:20:00 1970 +0000
2327 2327 summary: no person
2328 2328
2329 2329 changeset: 3:10e46f2dcbf4
2330 2330 bisect: bad
2331 2331 user: person
2332 2332 date: Fri Jan 16 01:06:40 1970 +0000
2333 2333 summary: no user, no domain
2334 2334
2335 2335 changeset: 4:bbe44766e73d
2336 2336 bisect: bad (implicit)
2337 2337 branch: foo
2338 2338 user: person
2339 2339 date: Sat Jan 17 04:53:20 1970 +0000
2340 2340 summary: new branch
2341 2341
2342 2342 $ hg log --debug -T bisect -r 0:4
2343 2343 changeset: 0:1e4e1b8f71e05681d422154f5421e385fec3454f
2344 2344 bisect: good (implicit)
2345 2345 phase: public
2346 2346 parent: -1:0000000000000000000000000000000000000000
2347 2347 parent: -1:0000000000000000000000000000000000000000
2348 2348 manifest: 0:a0c8bcbbb45c63b90b70ad007bf38961f64f2af0
2349 2349 user: User Name <user@hostname>
2350 2350 date: Mon Jan 12 13:46:40 1970 +0000
2351 2351 files+: a
2352 2352 extra: branch=default
2353 2353 description:
2354 2354 line 1
2355 2355 line 2
2356 2356
2357 2357
2358 2358 changeset: 1:b608e9d1a3f0273ccf70fb85fd6866b3482bf965
2359 2359 bisect: good
2360 2360 phase: public
2361 2361 parent: 0:1e4e1b8f71e05681d422154f5421e385fec3454f
2362 2362 parent: -1:0000000000000000000000000000000000000000
2363 2363 manifest: 1:4e8d705b1e53e3f9375e0e60dc7b525d8211fe55
2364 2364 user: A. N. Other <other@place>
2365 2365 date: Tue Jan 13 17:33:20 1970 +0000
2366 2366 files+: b
2367 2367 extra: branch=default
2368 2368 description:
2369 2369 other 1
2370 2370 other 2
2371 2371
2372 2372 other 3
2373 2373
2374 2374
2375 2375 changeset: 2:97054abb4ab824450e9164180baf491ae0078465
2376 2376 bisect: untested
2377 2377 phase: public
2378 2378 parent: 1:b608e9d1a3f0273ccf70fb85fd6866b3482bf965
2379 2379 parent: -1:0000000000000000000000000000000000000000
2380 2380 manifest: 2:6e0e82995c35d0d57a52aca8da4e56139e06b4b1
2381 2381 user: other@place
2382 2382 date: Wed Jan 14 21:20:00 1970 +0000
2383 2383 files+: c
2384 2384 extra: branch=default
2385 2385 description:
2386 2386 no person
2387 2387
2388 2388
2389 2389 changeset: 3:10e46f2dcbf4823578cf180f33ecf0b957964c47
2390 2390 bisect: bad
2391 2391 phase: public
2392 2392 parent: 2:97054abb4ab824450e9164180baf491ae0078465
2393 2393 parent: -1:0000000000000000000000000000000000000000
2394 2394 manifest: 3:cb5a1327723bada42f117e4c55a303246eaf9ccc
2395 2395 user: person
2396 2396 date: Fri Jan 16 01:06:40 1970 +0000
2397 2397 files: c
2398 2398 extra: branch=default
2399 2399 description:
2400 2400 no user, no domain
2401 2401
2402 2402
2403 2403 changeset: 4:bbe44766e73d5f11ed2177f1838de10c53ef3e74
2404 2404 bisect: bad (implicit)
2405 2405 branch: foo
2406 2406 phase: draft
2407 2407 parent: 3:10e46f2dcbf4823578cf180f33ecf0b957964c47
2408 2408 parent: -1:0000000000000000000000000000000000000000
2409 2409 manifest: 3:cb5a1327723bada42f117e4c55a303246eaf9ccc
2410 2410 user: person
2411 2411 date: Sat Jan 17 04:53:20 1970 +0000
2412 2412 extra: branch=foo
2413 2413 description:
2414 2414 new branch
2415 2415
2416 2416
2417 2417 $ hg log -v -T bisect -r 0:4
2418 2418 changeset: 0:1e4e1b8f71e0
2419 2419 bisect: good (implicit)
2420 2420 user: User Name <user@hostname>
2421 2421 date: Mon Jan 12 13:46:40 1970 +0000
2422 2422 files: a
2423 2423 description:
2424 2424 line 1
2425 2425 line 2
2426 2426
2427 2427
2428 2428 changeset: 1:b608e9d1a3f0
2429 2429 bisect: good
2430 2430 user: A. N. Other <other@place>
2431 2431 date: Tue Jan 13 17:33:20 1970 +0000
2432 2432 files: b
2433 2433 description:
2434 2434 other 1
2435 2435 other 2
2436 2436
2437 2437 other 3
2438 2438
2439 2439
2440 2440 changeset: 2:97054abb4ab8
2441 2441 bisect: untested
2442 2442 user: other@place
2443 2443 date: Wed Jan 14 21:20:00 1970 +0000
2444 2444 files: c
2445 2445 description:
2446 2446 no person
2447 2447
2448 2448
2449 2449 changeset: 3:10e46f2dcbf4
2450 2450 bisect: bad
2451 2451 user: person
2452 2452 date: Fri Jan 16 01:06:40 1970 +0000
2453 2453 files: c
2454 2454 description:
2455 2455 no user, no domain
2456 2456
2457 2457
2458 2458 changeset: 4:bbe44766e73d
2459 2459 bisect: bad (implicit)
2460 2460 branch: foo
2461 2461 user: person
2462 2462 date: Sat Jan 17 04:53:20 1970 +0000
2463 2463 description:
2464 2464 new branch
2465 2465
2466 2466
2467 2467 $ hg --color=debug log -T bisect -r 0:4
2468 2468 [log.changeset changeset.public|changeset: 0:1e4e1b8f71e0]
2469 2469 [log.bisect bisect.good|bisect: good (implicit)]
2470 2470 [log.user|user: User Name <user@hostname>]
2471 2471 [log.date|date: Mon Jan 12 13:46:40 1970 +0000]
2472 2472 [log.summary|summary: line 1]
2473 2473
2474 2474 [log.changeset changeset.public|changeset: 1:b608e9d1a3f0]
2475 2475 [log.bisect bisect.good|bisect: good]
2476 2476 [log.user|user: A. N. Other <other@place>]
2477 2477 [log.date|date: Tue Jan 13 17:33:20 1970 +0000]
2478 2478 [log.summary|summary: other 1]
2479 2479
2480 2480 [log.changeset changeset.public|changeset: 2:97054abb4ab8]
2481 2481 [log.bisect bisect.untested|bisect: untested]
2482 2482 [log.user|user: other@place]
2483 2483 [log.date|date: Wed Jan 14 21:20:00 1970 +0000]
2484 2484 [log.summary|summary: no person]
2485 2485
2486 2486 [log.changeset changeset.public|changeset: 3:10e46f2dcbf4]
2487 2487 [log.bisect bisect.bad|bisect: bad]
2488 2488 [log.user|user: person]
2489 2489 [log.date|date: Fri Jan 16 01:06:40 1970 +0000]
2490 2490 [log.summary|summary: no user, no domain]
2491 2491
2492 2492 [log.changeset changeset.draft|changeset: 4:bbe44766e73d]
2493 2493 [log.bisect bisect.bad|bisect: bad (implicit)]
2494 2494 [log.branch|branch: foo]
2495 2495 [log.user|user: person]
2496 2496 [log.date|date: Sat Jan 17 04:53:20 1970 +0000]
2497 2497 [log.summary|summary: new branch]
2498 2498
2499 2499 $ hg --color=debug log --debug -T bisect -r 0:4
2500 2500 [log.changeset changeset.public|changeset: 0:1e4e1b8f71e05681d422154f5421e385fec3454f]
2501 2501 [log.bisect bisect.good|bisect: good (implicit)]
2502 2502 [log.phase|phase: public]
2503 2503 [log.parent changeset.public|parent: -1:0000000000000000000000000000000000000000]
2504 2504 [log.parent changeset.public|parent: -1:0000000000000000000000000000000000000000]
2505 2505 [ui.debug log.manifest|manifest: 0:a0c8bcbbb45c63b90b70ad007bf38961f64f2af0]
2506 2506 [log.user|user: User Name <user@hostname>]
2507 2507 [log.date|date: Mon Jan 12 13:46:40 1970 +0000]
2508 2508 [ui.debug log.files|files+: a]
2509 2509 [ui.debug log.extra|extra: branch=default]
2510 2510 [ui.note log.description|description:]
2511 2511 [ui.note log.description|line 1
2512 2512 line 2]
2513 2513
2514 2514
2515 2515 [log.changeset changeset.public|changeset: 1:b608e9d1a3f0273ccf70fb85fd6866b3482bf965]
2516 2516 [log.bisect bisect.good|bisect: good]
2517 2517 [log.phase|phase: public]
2518 2518 [log.parent changeset.public|parent: 0:1e4e1b8f71e05681d422154f5421e385fec3454f]
2519 2519 [log.parent changeset.public|parent: -1:0000000000000000000000000000000000000000]
2520 2520 [ui.debug log.manifest|manifest: 1:4e8d705b1e53e3f9375e0e60dc7b525d8211fe55]
2521 2521 [log.user|user: A. N. Other <other@place>]
2522 2522 [log.date|date: Tue Jan 13 17:33:20 1970 +0000]
2523 2523 [ui.debug log.files|files+: b]
2524 2524 [ui.debug log.extra|extra: branch=default]
2525 2525 [ui.note log.description|description:]
2526 2526 [ui.note log.description|other 1
2527 2527 other 2
2528 2528
2529 2529 other 3]
2530 2530
2531 2531
2532 2532 [log.changeset changeset.public|changeset: 2:97054abb4ab824450e9164180baf491ae0078465]
2533 2533 [log.bisect bisect.untested|bisect: untested]
2534 2534 [log.phase|phase: public]
2535 2535 [log.parent changeset.public|parent: 1:b608e9d1a3f0273ccf70fb85fd6866b3482bf965]
2536 2536 [log.parent changeset.public|parent: -1:0000000000000000000000000000000000000000]
2537 2537 [ui.debug log.manifest|manifest: 2:6e0e82995c35d0d57a52aca8da4e56139e06b4b1]
2538 2538 [log.user|user: other@place]
2539 2539 [log.date|date: Wed Jan 14 21:20:00 1970 +0000]
2540 2540 [ui.debug log.files|files+: c]
2541 2541 [ui.debug log.extra|extra: branch=default]
2542 2542 [ui.note log.description|description:]
2543 2543 [ui.note log.description|no person]
2544 2544
2545 2545
2546 2546 [log.changeset changeset.public|changeset: 3:10e46f2dcbf4823578cf180f33ecf0b957964c47]
2547 2547 [log.bisect bisect.bad|bisect: bad]
2548 2548 [log.phase|phase: public]
2549 2549 [log.parent changeset.public|parent: 2:97054abb4ab824450e9164180baf491ae0078465]
2550 2550 [log.parent changeset.public|parent: -1:0000000000000000000000000000000000000000]
2551 2551 [ui.debug log.manifest|manifest: 3:cb5a1327723bada42f117e4c55a303246eaf9ccc]
2552 2552 [log.user|user: person]
2553 2553 [log.date|date: Fri Jan 16 01:06:40 1970 +0000]
2554 2554 [ui.debug log.files|files: c]
2555 2555 [ui.debug log.extra|extra: branch=default]
2556 2556 [ui.note log.description|description:]
2557 2557 [ui.note log.description|no user, no domain]
2558 2558
2559 2559
2560 2560 [log.changeset changeset.draft|changeset: 4:bbe44766e73d5f11ed2177f1838de10c53ef3e74]
2561 2561 [log.bisect bisect.bad|bisect: bad (implicit)]
2562 2562 [log.branch|branch: foo]
2563 2563 [log.phase|phase: draft]
2564 2564 [log.parent changeset.public|parent: 3:10e46f2dcbf4823578cf180f33ecf0b957964c47]
2565 2565 [log.parent changeset.public|parent: -1:0000000000000000000000000000000000000000]
2566 2566 [ui.debug log.manifest|manifest: 3:cb5a1327723bada42f117e4c55a303246eaf9ccc]
2567 2567 [log.user|user: person]
2568 2568 [log.date|date: Sat Jan 17 04:53:20 1970 +0000]
2569 2569 [ui.debug log.extra|extra: branch=foo]
2570 2570 [ui.note log.description|description:]
2571 2571 [ui.note log.description|new branch]
2572 2572
2573 2573
2574 2574 $ hg --color=debug log -v -T bisect -r 0:4
2575 2575 [log.changeset changeset.public|changeset: 0:1e4e1b8f71e0]
2576 2576 [log.bisect bisect.good|bisect: good (implicit)]
2577 2577 [log.user|user: User Name <user@hostname>]
2578 2578 [log.date|date: Mon Jan 12 13:46:40 1970 +0000]
2579 2579 [ui.note log.files|files: a]
2580 2580 [ui.note log.description|description:]
2581 2581 [ui.note log.description|line 1
2582 2582 line 2]
2583 2583
2584 2584
2585 2585 [log.changeset changeset.public|changeset: 1:b608e9d1a3f0]
2586 2586 [log.bisect bisect.good|bisect: good]
2587 2587 [log.user|user: A. N. Other <other@place>]
2588 2588 [log.date|date: Tue Jan 13 17:33:20 1970 +0000]
2589 2589 [ui.note log.files|files: b]
2590 2590 [ui.note log.description|description:]
2591 2591 [ui.note log.description|other 1
2592 2592 other 2
2593 2593
2594 2594 other 3]
2595 2595
2596 2596
2597 2597 [log.changeset changeset.public|changeset: 2:97054abb4ab8]
2598 2598 [log.bisect bisect.untested|bisect: untested]
2599 2599 [log.user|user: other@place]
2600 2600 [log.date|date: Wed Jan 14 21:20:00 1970 +0000]
2601 2601 [ui.note log.files|files: c]
2602 2602 [ui.note log.description|description:]
2603 2603 [ui.note log.description|no person]
2604 2604
2605 2605
2606 2606 [log.changeset changeset.public|changeset: 3:10e46f2dcbf4]
2607 2607 [log.bisect bisect.bad|bisect: bad]
2608 2608 [log.user|user: person]
2609 2609 [log.date|date: Fri Jan 16 01:06:40 1970 +0000]
2610 2610 [ui.note log.files|files: c]
2611 2611 [ui.note log.description|description:]
2612 2612 [ui.note log.description|no user, no domain]
2613 2613
2614 2614
2615 2615 [log.changeset changeset.draft|changeset: 4:bbe44766e73d]
2616 2616 [log.bisect bisect.bad|bisect: bad (implicit)]
2617 2617 [log.branch|branch: foo]
2618 2618 [log.user|user: person]
2619 2619 [log.date|date: Sat Jan 17 04:53:20 1970 +0000]
2620 2620 [ui.note log.description|description:]
2621 2621 [ui.note log.description|new branch]
2622 2622
2623 2623
2624 2624 $ hg bisect --reset
2625 2625
2626 2626 Error on syntax:
2627 2627
2628 2628 $ echo 'x = "f' >> t
2629 2629 $ hg log
2630 2630 hg: parse error at t:3: unmatched quotes
2631 2631 [255]
2632 2632
2633 2633 $ hg log -T '{date'
2634 2634 hg: parse error at 1: unterminated template expansion
2635 2635 [255]
2636 2636
2637 2637 Behind the scenes, this will throw TypeError
2638 2638
2639 2639 $ hg log -l 3 --template '{date|obfuscate}\n'
2640 2640 abort: template filter 'obfuscate' is not compatible with keyword 'date'
2641 2641 [255]
2642 2642
2643 2643 Behind the scenes, this will throw a ValueError
2644 2644
2645 2645 $ hg log -l 3 --template 'line: {desc|shortdate}\n'
2646 2646 abort: template filter 'shortdate' is not compatible with keyword 'desc'
2647 2647 [255]
2648 2648
2649 2649 Behind the scenes, this will throw AttributeError
2650 2650
2651 2651 $ hg log -l 3 --template 'line: {date|escape}\n'
2652 2652 abort: template filter 'escape' is not compatible with keyword 'date'
2653 2653 [255]
2654 2654
2655 2655 $ hg log -l 3 --template 'line: {extras|localdate}\n'
2656 2656 hg: parse error: localdate expects a date information
2657 2657 [255]
2658 2658
2659 2659 Behind the scenes, this will throw ValueError
2660 2660
2661 2661 $ hg tip --template '{author|email|date}\n'
2662 2662 hg: parse error: date expects a date information
2663 2663 [255]
2664 2664
2665 2665 Error in nested template:
2666 2666
2667 2667 $ hg log -T '{"date'
2668 2668 hg: parse error at 2: unterminated string
2669 2669 [255]
2670 2670
2671 2671 $ hg log -T '{"foo{date|=}"}'
2672 2672 hg: parse error at 11: syntax error
2673 2673 [255]
2674 2674
2675 2675 Thrown an error if a template function doesn't exist
2676 2676
2677 2677 $ hg tip --template '{foo()}\n'
2678 2678 hg: parse error: unknown function 'foo'
2679 2679 [255]
2680 2680
2681 2681 Pass generator object created by template function to filter
2682 2682
2683 2683 $ hg log -l 1 --template '{if(author, author)|user}\n'
2684 2684 test
2685 2685
2686 2686 Test diff function:
2687 2687
2688 2688 $ hg diff -c 8
2689 2689 diff -r 29114dbae42b -r 95c24699272e fourth
2690 2690 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2691 2691 +++ b/fourth Wed Jan 01 10:01:00 2020 +0000
2692 2692 @@ -0,0 +1,1 @@
2693 2693 +second
2694 2694 diff -r 29114dbae42b -r 95c24699272e second
2695 2695 --- a/second Mon Jan 12 13:46:40 1970 +0000
2696 2696 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2697 2697 @@ -1,1 +0,0 @@
2698 2698 -second
2699 2699 diff -r 29114dbae42b -r 95c24699272e third
2700 2700 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2701 2701 +++ b/third Wed Jan 01 10:01:00 2020 +0000
2702 2702 @@ -0,0 +1,1 @@
2703 2703 +third
2704 2704
2705 2705 $ hg log -r 8 -T "{diff()}"
2706 2706 diff -r 29114dbae42b -r 95c24699272e fourth
2707 2707 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2708 2708 +++ b/fourth Wed Jan 01 10:01:00 2020 +0000
2709 2709 @@ -0,0 +1,1 @@
2710 2710 +second
2711 2711 diff -r 29114dbae42b -r 95c24699272e second
2712 2712 --- a/second Mon Jan 12 13:46:40 1970 +0000
2713 2713 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2714 2714 @@ -1,1 +0,0 @@
2715 2715 -second
2716 2716 diff -r 29114dbae42b -r 95c24699272e third
2717 2717 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2718 2718 +++ b/third Wed Jan 01 10:01:00 2020 +0000
2719 2719 @@ -0,0 +1,1 @@
2720 2720 +third
2721 2721
2722 2722 $ hg log -r 8 -T "{diff('glob:f*')}"
2723 2723 diff -r 29114dbae42b -r 95c24699272e fourth
2724 2724 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2725 2725 +++ b/fourth Wed Jan 01 10:01:00 2020 +0000
2726 2726 @@ -0,0 +1,1 @@
2727 2727 +second
2728 2728
2729 2729 $ hg log -r 8 -T "{diff('', 'glob:f*')}"
2730 2730 diff -r 29114dbae42b -r 95c24699272e second
2731 2731 --- a/second Mon Jan 12 13:46:40 1970 +0000
2732 2732 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2733 2733 @@ -1,1 +0,0 @@
2734 2734 -second
2735 2735 diff -r 29114dbae42b -r 95c24699272e third
2736 2736 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2737 2737 +++ b/third Wed Jan 01 10:01:00 2020 +0000
2738 2738 @@ -0,0 +1,1 @@
2739 2739 +third
2740 2740
2741 2741 $ hg log -r 8 -T "{diff('FOURTH'|lower)}"
2742 2742 diff -r 29114dbae42b -r 95c24699272e fourth
2743 2743 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2744 2744 +++ b/fourth Wed Jan 01 10:01:00 2020 +0000
2745 2745 @@ -0,0 +1,1 @@
2746 2746 +second
2747 2747
2748 2748 $ cd ..
2749 2749
2750 2750
2751 2751 latesttag:
2752 2752
2753 2753 $ hg init latesttag
2754 2754 $ cd latesttag
2755 2755
2756 2756 $ echo a > file
2757 2757 $ hg ci -Am a -d '0 0'
2758 2758 adding file
2759 2759
2760 2760 $ echo b >> file
2761 2761 $ hg ci -m b -d '1 0'
2762 2762
2763 2763 $ echo c >> head1
2764 2764 $ hg ci -Am h1c -d '2 0'
2765 2765 adding head1
2766 2766
2767 2767 $ hg update -q 1
2768 2768 $ echo d >> head2
2769 2769 $ hg ci -Am h2d -d '3 0'
2770 2770 adding head2
2771 2771 created new head
2772 2772
2773 2773 $ echo e >> head2
2774 2774 $ hg ci -m h2e -d '4 0'
2775 2775
2776 2776 $ hg merge -q
2777 2777 $ hg ci -m merge -d '5 -3600'
2778 2778
2779 2779 No tag set:
2780 2780
2781 2781 $ hg log --template '{rev}: {latesttag}+{latesttagdistance}\n'
2782 2782 5: null+5
2783 2783 4: null+4
2784 2784 3: null+3
2785 2785 2: null+3
2786 2786 1: null+2
2787 2787 0: null+1
2788 2788
2789 2789 One common tag: longest path wins:
2790 2790
2791 2791 $ hg tag -r 1 -m t1 -d '6 0' t1
2792 2792 $ hg log --template '{rev}: {latesttag}+{latesttagdistance}\n'
2793 2793 6: t1+4
2794 2794 5: t1+3
2795 2795 4: t1+2
2796 2796 3: t1+1
2797 2797 2: t1+1
2798 2798 1: t1+0
2799 2799 0: null+1
2800 2800
2801 2801 One ancestor tag: more recent wins:
2802 2802
2803 2803 $ hg tag -r 2 -m t2 -d '7 0' t2
2804 2804 $ hg log --template '{rev}: {latesttag}+{latesttagdistance}\n'
2805 2805 7: t2+3
2806 2806 6: t2+2
2807 2807 5: t2+1
2808 2808 4: t1+2
2809 2809 3: t1+1
2810 2810 2: t2+0
2811 2811 1: t1+0
2812 2812 0: null+1
2813 2813
2814 2814 Two branch tags: more recent wins:
2815 2815
2816 2816 $ hg tag -r 3 -m t3 -d '8 0' t3
2817 2817 $ hg log --template '{rev}: {latesttag}+{latesttagdistance}\n'
2818 2818 8: t3+5
2819 2819 7: t3+4
2820 2820 6: t3+3
2821 2821 5: t3+2
2822 2822 4: t3+1
2823 2823 3: t3+0
2824 2824 2: t2+0
2825 2825 1: t1+0
2826 2826 0: null+1
2827 2827
2828 2828 Merged tag overrides:
2829 2829
2830 2830 $ hg tag -r 5 -m t5 -d '9 0' t5
2831 2831 $ hg tag -r 3 -m at3 -d '10 0' at3
2832 2832 $ hg log --template '{rev}: {latesttag}+{latesttagdistance}\n'
2833 2833 10: t5+5
2834 2834 9: t5+4
2835 2835 8: t5+3
2836 2836 7: t5+2
2837 2837 6: t5+1
2838 2838 5: t5+0
2839 2839 4: at3:t3+1
2840 2840 3: at3:t3+0
2841 2841 2: t2+0
2842 2842 1: t1+0
2843 2843 0: null+1
2844 2844
2845 2845 $ hg log --template "{rev}: {latesttag % '{tag}+{distance},{changes} '}\n"
2846 2846 10: t5+5,5
2847 2847 9: t5+4,4
2848 2848 8: t5+3,3
2849 2849 7: t5+2,2
2850 2850 6: t5+1,1
2851 2851 5: t5+0,0
2852 2852 4: at3+1,1 t3+1,1
2853 2853 3: at3+0,0 t3+0,0
2854 2854 2: t2+0,0
2855 2855 1: t1+0,0
2856 2856 0: null+1,1
2857 2857
2858 2858 $ hg log --template "{rev}: {latesttag('re:^t[13]$') % '{tag}, C: {changes}, D: {distance}'}\n"
2859 2859 10: t3, C: 8, D: 7
2860 2860 9: t3, C: 7, D: 6
2861 2861 8: t3, C: 6, D: 5
2862 2862 7: t3, C: 5, D: 4
2863 2863 6: t3, C: 4, D: 3
2864 2864 5: t3, C: 3, D: 2
2865 2865 4: t3, C: 1, D: 1
2866 2866 3: t3, C: 0, D: 0
2867 2867 2: t1, C: 1, D: 1
2868 2868 1: t1, C: 0, D: 0
2869 2869 0: null, C: 1, D: 1
2870 2870
2871 2871 $ cd ..
2872 2872
2873 2873
2874 2874 Style path expansion: issue1948 - ui.style option doesn't work on OSX
2875 2875 if it is a relative path
2876 2876
2877 2877 $ mkdir -p home/styles
2878 2878
2879 2879 $ cat > home/styles/teststyle <<EOF
2880 2880 > changeset = 'test {rev}:{node|short}\n'
2881 2881 > EOF
2882 2882
2883 2883 $ HOME=`pwd`/home; export HOME
2884 2884
2885 2885 $ cat > latesttag/.hg/hgrc <<EOF
2886 2886 > [ui]
2887 2887 > style = ~/styles/teststyle
2888 2888 > EOF
2889 2889
2890 2890 $ hg -R latesttag tip
2891 2891 test 10:9b4a630e5f5f
2892 2892
2893 2893 Test recursive showlist template (issue1989):
2894 2894
2895 2895 $ cat > style1989 <<EOF
2896 2896 > changeset = '{file_mods}{manifest}{extras}'
2897 2897 > file_mod = 'M|{author|person}\n'
2898 2898 > manifest = '{rev},{author}\n'
2899 2899 > extra = '{key}: {author}\n'
2900 2900 > EOF
2901 2901
2902 2902 $ hg -R latesttag log -r tip --style=style1989
2903 2903 M|test
2904 2904 10,test
2905 2905 branch: test
2906 2906
2907 2907 Test new-style inline templating:
2908 2908
2909 2909 $ hg log -R latesttag -r tip --template 'modified files: {file_mods % " {file}\n"}\n'
2910 2910 modified files: .hgtags
2911 2911
2912 2912
2913 2913 $ hg log -R latesttag -r tip -T '{rev % "a"}\n'
2914 2914 hg: parse error: keyword 'rev' is not iterable
2915 2915 [255]
2916 2916 $ hg log -R latesttag -r tip -T '{get(extras, "unknown") % "a"}\n'
2917 2917 hg: parse error: None is not iterable
2918 2918 [255]
2919 2919
2920 2920 Test the sub function of templating for expansion:
2921 2921
2922 2922 $ hg log -R latesttag -r 10 --template '{sub("[0-9]", "x", "{rev}")}\n'
2923 2923 xx
2924 2924
2925 2925 $ hg log -R latesttag -r 10 -T '{sub("[", "x", rev)}\n'
2926 2926 hg: parse error: sub got an invalid pattern: [
2927 2927 [255]
2928 2928 $ hg log -R latesttag -r 10 -T '{sub("[0-9]", r"\1", rev)}\n'
2929 2929 hg: parse error: sub got an invalid replacement: \1
2930 2930 [255]
2931 2931
2932 2932 Test the strip function with chars specified:
2933 2933
2934 2934 $ hg log -R latesttag --template '{desc}\n'
2935 2935 at3
2936 2936 t5
2937 2937 t3
2938 2938 t2
2939 2939 t1
2940 2940 merge
2941 2941 h2e
2942 2942 h2d
2943 2943 h1c
2944 2944 b
2945 2945 a
2946 2946
2947 2947 $ hg log -R latesttag --template '{strip(desc, "te")}\n'
2948 2948 at3
2949 2949 5
2950 2950 3
2951 2951 2
2952 2952 1
2953 2953 merg
2954 2954 h2
2955 2955 h2d
2956 2956 h1c
2957 2957 b
2958 2958 a
2959 2959
2960 2960 Test date format:
2961 2961
2962 2962 $ hg log -R latesttag --template 'date: {date(date, "%y %m %d %S %z")}\n'
2963 2963 date: 70 01 01 10 +0000
2964 2964 date: 70 01 01 09 +0000
2965 2965 date: 70 01 01 08 +0000
2966 2966 date: 70 01 01 07 +0000
2967 2967 date: 70 01 01 06 +0000
2968 2968 date: 70 01 01 05 +0100
2969 2969 date: 70 01 01 04 +0000
2970 2970 date: 70 01 01 03 +0000
2971 2971 date: 70 01 01 02 +0000
2972 2972 date: 70 01 01 01 +0000
2973 2973 date: 70 01 01 00 +0000
2974 2974
2975 2975 Test invalid date:
2976 2976
2977 2977 $ hg log -R latesttag -T '{date(rev)}\n'
2978 2978 hg: parse error: date expects a date information
2979 2979 [255]
2980 2980
2981 2981 Test integer literal:
2982 2982
2983 2983 $ hg debugtemplate -v '{(0)}\n'
2984 2984 (template
2985 2985 (group
2986 2986 ('integer', '0'))
2987 2987 ('string', '\n'))
2988 2988 0
2989 2989 $ hg debugtemplate -v '{(123)}\n'
2990 2990 (template
2991 2991 (group
2992 2992 ('integer', '123'))
2993 2993 ('string', '\n'))
2994 2994 123
2995 2995 $ hg debugtemplate -v '{(-4)}\n'
2996 2996 (template
2997 2997 (group
2998 2998 (negate
2999 2999 ('integer', '4')))
3000 3000 ('string', '\n'))
3001 3001 -4
3002 3002 $ hg debugtemplate '{(-)}\n'
3003 3003 hg: parse error at 3: not a prefix: )
3004 3004 [255]
3005 3005 $ hg debugtemplate '{(-a)}\n'
3006 3006 hg: parse error: negation needs an integer argument
3007 3007 [255]
3008 3008
3009 3009 top-level integer literal is interpreted as symbol (i.e. variable name):
3010 3010
3011 3011 $ hg debugtemplate -D 1=one -v '{1}\n'
3012 3012 (template
3013 3013 ('integer', '1')
3014 3014 ('string', '\n'))
3015 3015 one
3016 3016 $ hg debugtemplate -D 1=one -v '{if("t", "{1}")}\n'
3017 3017 (template
3018 3018 (func
3019 3019 ('symbol', 'if')
3020 3020 (list
3021 3021 ('string', 't')
3022 3022 (template
3023 3023 ('integer', '1'))))
3024 3024 ('string', '\n'))
3025 3025 one
3026 3026 $ hg debugtemplate -D 1=one -v '{1|stringify}\n'
3027 3027 (template
3028 3028 (|
3029 3029 ('integer', '1')
3030 3030 ('symbol', 'stringify'))
3031 3031 ('string', '\n'))
3032 3032 one
3033 3033
3034 3034 unless explicit symbol is expected:
3035 3035
3036 3036 $ hg log -Ra -r0 -T '{desc|1}\n'
3037 3037 hg: parse error: expected a symbol, got 'integer'
3038 3038 [255]
3039 3039 $ hg log -Ra -r0 -T '{1()}\n'
3040 3040 hg: parse error: expected a symbol, got 'integer'
3041 3041 [255]
3042 3042
3043 3043 Test string literal:
3044 3044
3045 3045 $ hg debugtemplate -Ra -r0 -v '{"string with no template fragment"}\n'
3046 3046 (template
3047 3047 ('string', 'string with no template fragment')
3048 3048 ('string', '\n'))
3049 3049 string with no template fragment
3050 3050 $ hg debugtemplate -Ra -r0 -v '{"template: {rev}"}\n'
3051 3051 (template
3052 3052 (template
3053 3053 ('string', 'template: ')
3054 3054 ('symbol', 'rev'))
3055 3055 ('string', '\n'))
3056 3056 template: 0
3057 3057 $ hg debugtemplate -Ra -r0 -v '{r"rawstring: {rev}"}\n'
3058 3058 (template
3059 3059 ('string', 'rawstring: {rev}')
3060 3060 ('string', '\n'))
3061 3061 rawstring: {rev}
3062 3062 $ hg debugtemplate -Ra -r0 -v '{files % r"rawstring: {file}"}\n'
3063 3063 (template
3064 3064 (%
3065 3065 ('symbol', 'files')
3066 3066 ('string', 'rawstring: {file}'))
3067 3067 ('string', '\n'))
3068 3068 rawstring: {file}
3069 3069
3070 3070 Test string escaping:
3071 3071
3072 3072 $ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n'
3073 3073 >
3074 3074 <>\n<[>
3075 3075 <>\n<]>
3076 3076 <>\n<
3077 3077
3078 3078 $ hg log -R latesttag -r 0 \
3079 3079 > --config ui.logtemplate='>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n'
3080 3080 >
3081 3081 <>\n<[>
3082 3082 <>\n<]>
3083 3083 <>\n<
3084 3084
3085 3085 $ hg log -R latesttag -r 0 -T esc \
3086 3086 > --config templates.esc='>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n'
3087 3087 >
3088 3088 <>\n<[>
3089 3089 <>\n<]>
3090 3090 <>\n<
3091 3091
3092 3092 $ cat <<'EOF' > esctmpl
3093 3093 > changeset = '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n'
3094 3094 > EOF
3095 3095 $ hg log -R latesttag -r 0 --style ./esctmpl
3096 3096 >
3097 3097 <>\n<[>
3098 3098 <>\n<]>
3099 3099 <>\n<
3100 3100
3101 3101 Test string escaping of quotes:
3102 3102
3103 3103 $ hg log -Ra -r0 -T '{"\""}\n'
3104 3104 "
3105 3105 $ hg log -Ra -r0 -T '{"\\\""}\n'
3106 3106 \"
3107 3107 $ hg log -Ra -r0 -T '{r"\""}\n'
3108 3108 \"
3109 3109 $ hg log -Ra -r0 -T '{r"\\\""}\n'
3110 3110 \\\"
3111 3111
3112 3112
3113 3113 $ hg log -Ra -r0 -T '{"\""}\n'
3114 3114 "
3115 3115 $ hg log -Ra -r0 -T '{"\\\""}\n'
3116 3116 \"
3117 3117 $ hg log -Ra -r0 -T '{r"\""}\n'
3118 3118 \"
3119 3119 $ hg log -Ra -r0 -T '{r"\\\""}\n'
3120 3120 \\\"
3121 3121
3122 3122 Test exception in quoted template. single backslash before quotation mark is
3123 3123 stripped before parsing:
3124 3124
3125 3125 $ cat <<'EOF' > escquotetmpl
3126 3126 > changeset = "\" \\" \\\" \\\\" {files % \"{file}\"}\n"
3127 3127 > EOF
3128 3128 $ cd latesttag
3129 3129 $ hg log -r 2 --style ../escquotetmpl
3130 3130 " \" \" \\" head1
3131 3131
3132 3132 $ hg log -r 2 -T esc --config templates.esc='"{\"valid\"}\n"'
3133 3133 valid
3134 3134 $ hg log -r 2 -T esc --config templates.esc="'"'{\'"'"'valid\'"'"'}\n'"'"
3135 3135 valid
3136 3136
3137 3137 Test compatibility with 2.9.2-3.4 of escaped quoted strings in nested
3138 3138 _evalifliteral() templates (issue4733):
3139 3139
3140 3140 $ hg log -r 2 -T '{if(rev, "\"{rev}")}\n'
3141 3141 "2
3142 3142 $ hg log -r 2 -T '{if(rev, "{if(rev, \"\\\"{rev}\")}")}\n'
3143 3143 "2
3144 3144 $ hg log -r 2 -T '{if(rev, "{if(rev, \"{if(rev, \\\"\\\\\\\"{rev}\\\")}\")}")}\n'
3145 3145 "2
3146 3146
3147 3147 $ hg log -r 2 -T '{if(rev, "\\\"")}\n'
3148 3148 \"
3149 3149 $ hg log -r 2 -T '{if(rev, "{if(rev, \"\\\\\\\"\")}")}\n'
3150 3150 \"
3151 3151 $ hg log -r 2 -T '{if(rev, "{if(rev, \"{if(rev, \\\"\\\\\\\\\\\\\\\"\\\")}\")}")}\n'
3152 3152 \"
3153 3153
3154 3154 $ hg log -r 2 -T '{if(rev, r"\\\"")}\n'
3155 3155 \\\"
3156 3156 $ hg log -r 2 -T '{if(rev, "{if(rev, r\"\\\\\\\"\")}")}\n'
3157 3157 \\\"
3158 3158 $ hg log -r 2 -T '{if(rev, "{if(rev, \"{if(rev, r\\\"\\\\\\\\\\\\\\\"\\\")}\")}")}\n'
3159 3159 \\\"
3160 3160
3161 3161 escaped single quotes and errors:
3162 3162
3163 3163 $ hg log -r 2 -T "{if(rev, '{if(rev, \'foo\')}')}"'\n'
3164 3164 foo
3165 3165 $ hg log -r 2 -T "{if(rev, '{if(rev, r\'foo\')}')}"'\n'
3166 3166 foo
3167 3167 $ hg log -r 2 -T '{if(rev, "{if(rev, \")}")}\n'
3168 3168 hg: parse error at 21: unterminated string
3169 3169 [255]
3170 3170 $ hg log -r 2 -T '{if(rev, \"\\"")}\n'
3171 3171 hg: parse error: trailing \ in string
3172 3172 [255]
3173 3173 $ hg log -r 2 -T '{if(rev, r\"\\"")}\n'
3174 3174 hg: parse error: trailing \ in string
3175 3175 [255]
3176 3176
3177 3177 $ cd ..
3178 3178
3179 3179 Test leading backslashes:
3180 3180
3181 3181 $ cd latesttag
3182 3182 $ hg log -r 2 -T '\{rev} {files % "\{file}"}\n'
3183 3183 {rev} {file}
3184 3184 $ hg log -r 2 -T '\\{rev} {files % "\\{file}"}\n'
3185 3185 \2 \head1
3186 3186 $ hg log -r 2 -T '\\\{rev} {files % "\\\{file}"}\n'
3187 3187 \{rev} \{file}
3188 3188 $ cd ..
3189 3189
3190 3190 Test leading backslashes in "if" expression (issue4714):
3191 3191
3192 3192 $ cd latesttag
3193 3193 $ hg log -r 2 -T '{if("1", "\{rev}")} {if("1", r"\{rev}")}\n'
3194 3194 {rev} \{rev}
3195 3195 $ hg log -r 2 -T '{if("1", "\\{rev}")} {if("1", r"\\{rev}")}\n'
3196 3196 \2 \\{rev}
3197 3197 $ hg log -r 2 -T '{if("1", "\\\{rev}")} {if("1", r"\\\{rev}")}\n'
3198 3198 \{rev} \\\{rev}
3199 3199 $ cd ..
3200 3200
3201 3201 "string-escape"-ed "\x5c\x786e" becomes r"\x6e" (once) or r"n" (twice)
3202 3202
3203 3203 $ hg log -R a -r 0 --template '{if("1", "\x5c\x786e", "NG")}\n'
3204 3204 \x6e
3205 3205 $ hg log -R a -r 0 --template '{if("1", r"\x5c\x786e", "NG")}\n'
3206 3206 \x5c\x786e
3207 3207 $ hg log -R a -r 0 --template '{if("", "NG", "\x5c\x786e")}\n'
3208 3208 \x6e
3209 3209 $ hg log -R a -r 0 --template '{if("", "NG", r"\x5c\x786e")}\n'
3210 3210 \x5c\x786e
3211 3211
3212 3212 $ hg log -R a -r 2 --template '{ifeq("no perso\x6e", desc, "\x5c\x786e", "NG")}\n'
3213 3213 \x6e
3214 3214 $ hg log -R a -r 2 --template '{ifeq(r"no perso\x6e", desc, "NG", r"\x5c\x786e")}\n'
3215 3215 \x5c\x786e
3216 3216 $ hg log -R a -r 2 --template '{ifeq(desc, "no perso\x6e", "\x5c\x786e", "NG")}\n'
3217 3217 \x6e
3218 3218 $ hg log -R a -r 2 --template '{ifeq(desc, r"no perso\x6e", "NG", r"\x5c\x786e")}\n'
3219 3219 \x5c\x786e
3220 3220
3221 3221 $ hg log -R a -r 8 --template '{join(files, "\n")}\n'
3222 3222 fourth
3223 3223 second
3224 3224 third
3225 3225 $ hg log -R a -r 8 --template '{join(files, r"\n")}\n'
3226 3226 fourth\nsecond\nthird
3227 3227
3228 3228 $ hg log -R a -r 2 --template '{rstdoc("1st\n\n2nd", "htm\x6c")}'
3229 3229 <p>
3230 3230 1st
3231 3231 </p>
3232 3232 <p>
3233 3233 2nd
3234 3234 </p>
3235 3235 $ hg log -R a -r 2 --template '{rstdoc(r"1st\n\n2nd", "html")}'
3236 3236 <p>
3237 3237 1st\n\n2nd
3238 3238 </p>
3239 3239 $ hg log -R a -r 2 --template '{rstdoc("1st\n\n2nd", r"htm\x6c")}'
3240 3240 1st
3241 3241
3242 3242 2nd
3243 3243
3244 3244 $ hg log -R a -r 2 --template '{strip(desc, "\x6e")}\n'
3245 3245 o perso
3246 3246 $ hg log -R a -r 2 --template '{strip(desc, r"\x6e")}\n'
3247 3247 no person
3248 3248 $ hg log -R a -r 2 --template '{strip("no perso\x6e", "\x6e")}\n'
3249 3249 o perso
3250 3250 $ hg log -R a -r 2 --template '{strip(r"no perso\x6e", r"\x6e")}\n'
3251 3251 no perso
3252 3252
3253 3253 $ hg log -R a -r 2 --template '{sub("\\x6e", "\x2d", desc)}\n'
3254 3254 -o perso-
3255 3255 $ hg log -R a -r 2 --template '{sub(r"\\x6e", "-", desc)}\n'
3256 3256 no person
3257 3257 $ hg log -R a -r 2 --template '{sub("n", r"\x2d", desc)}\n'
3258 3258 \x2do perso\x2d
3259 3259 $ hg log -R a -r 2 --template '{sub("n", "\x2d", "no perso\x6e")}\n'
3260 3260 -o perso-
3261 3261 $ hg log -R a -r 2 --template '{sub("n", r"\x2d", r"no perso\x6e")}\n'
3262 3262 \x2do perso\x6e
3263 3263
3264 3264 $ hg log -R a -r 8 --template '{files % "{file}\n"}'
3265 3265 fourth
3266 3266 second
3267 3267 third
3268 3268
3269 3269 Test string escaping in nested expression:
3270 3270
3271 3271 $ hg log -R a -r 8 --template '{ifeq(r"\x6e", if("1", "\x5c\x786e"), join(files, "\x5c\x786e"))}\n'
3272 3272 fourth\x6esecond\x6ethird
3273 3273 $ hg log -R a -r 8 --template '{ifeq(if("1", r"\x6e"), "\x5c\x786e", join(files, "\x5c\x786e"))}\n'
3274 3274 fourth\x6esecond\x6ethird
3275 3275
3276 3276 $ hg log -R a -r 8 --template '{join(files, ifeq(branch, "default", "\x5c\x786e"))}\n'
3277 3277 fourth\x6esecond\x6ethird
3278 3278 $ hg log -R a -r 8 --template '{join(files, ifeq(branch, "default", r"\x5c\x786e"))}\n'
3279 3279 fourth\x5c\x786esecond\x5c\x786ethird
3280 3280
3281 3281 $ hg log -R a -r 3:4 --template '{rev}:{sub(if("1", "\x6e"), ifeq(branch, "foo", r"\x5c\x786e", "\x5c\x786e"), desc)}\n'
3282 3282 3:\x6eo user, \x6eo domai\x6e
3283 3283 4:\x5c\x786eew bra\x5c\x786ech
3284 3284
3285 3285 Test quotes in nested expression are evaluated just like a $(command)
3286 3286 substitution in POSIX shells:
3287 3287
3288 3288 $ hg log -R a -r 8 -T '{"{"{rev}:{node|short}"}"}\n'
3289 3289 8:95c24699272e
3290 3290 $ hg log -R a -r 8 -T '{"{"\{{rev}} \"{node|short}\""}"}\n'
3291 3291 {8} "95c24699272e"
3292 3292
3293 3293 Test recursive evaluation:
3294 3294
3295 3295 $ hg init r
3296 3296 $ cd r
3297 3297 $ echo a > a
3298 3298 $ hg ci -Am '{rev}'
3299 3299 adding a
3300 3300 $ hg log -r 0 --template '{if(rev, desc)}\n'
3301 3301 {rev}
3302 3302 $ hg log -r 0 --template '{if(rev, "{author} {rev}")}\n'
3303 3303 test 0
3304 3304
3305 3305 $ hg branch -q 'text.{rev}'
3306 3306 $ echo aa >> aa
3307 3307 $ hg ci -u '{node|short}' -m 'desc to be wrapped desc to be wrapped'
3308 3308
3309 3309 $ hg log -l1 --template '{fill(desc, "20", author, branch)}'
3310 3310 {node|short}desc to
3311 3311 text.{rev}be wrapped
3312 3312 text.{rev}desc to be
3313 3313 text.{rev}wrapped (no-eol)
3314 3314 $ hg log -l1 --template '{fill(desc, "20", "{node|short}:", "text.{rev}:")}'
3315 3315 bcc7ff960b8e:desc to
3316 3316 text.1:be wrapped
3317 3317 text.1:desc to be
3318 3318 text.1:wrapped (no-eol)
3319 3319 $ hg log -l1 -T '{fill(desc, date, "", "")}\n'
3320 3320 hg: parse error: fill expects an integer width
3321 3321 [255]
3322 3322
3323 3323 $ COLUMNS=25 hg log -l1 --template '{fill(desc, termwidth, "{node|short}:", "termwidth.{rev}:")}'
3324 3324 bcc7ff960b8e:desc to be
3325 3325 termwidth.1:wrapped desc
3326 3326 termwidth.1:to be wrapped (no-eol)
3327 3327
3328 3328 $ hg log -l 1 --template '{sub(r"[0-9]", "-", author)}'
3329 3329 {node|short} (no-eol)
3330 3330 $ hg log -l 1 --template '{sub(r"[0-9]", "-", "{node|short}")}'
3331 3331 bcc-ff---b-e (no-eol)
3332 3332
3333 3333 $ cat >> .hg/hgrc <<EOF
3334 3334 > [extensions]
3335 3335 > color=
3336 3336 > [color]
3337 3337 > mode=ansi
3338 3338 > text.{rev} = red
3339 3339 > text.1 = green
3340 3340 > EOF
3341 3341 $ hg log --color=always -l 1 --template '{label(branch, "text\n")}'
3342 3342 \x1b[0;31mtext\x1b[0m (esc)
3343 3343 $ hg log --color=always -l 1 --template '{label("text.{rev}", "text\n")}'
3344 3344 \x1b[0;32mtext\x1b[0m (esc)
3345 3345
3346 3346 color effect can be specified without quoting:
3347 3347
3348 3348 $ hg log --color=always -l 1 --template '{label(red, "text\n")}'
3349 3349 \x1b[0;31mtext\x1b[0m (esc)
3350 3350
3351 3351 label should be no-op if color is disabled:
3352 3352
3353 3353 $ hg log --color=never -l 1 --template '{label(red, "text\n")}'
3354 3354 text
3355 3355 $ hg log --config extensions.color=! -l 1 --template '{label(red, "text\n")}'
3356 3356 text
3357 3357
3358 3358 Test branches inside if statement:
3359 3359
3360 3360 $ hg log -r 0 --template '{if(branches, "yes", "no")}\n'
3361 3361 no
3362 3362
3363 3363 Test get function:
3364 3364
3365 3365 $ hg log -r 0 --template '{get(extras, "branch")}\n'
3366 3366 default
3367 3367 $ hg log -r 0 --template '{get(extras, "br{"anch"}")}\n'
3368 3368 default
3369 3369 $ hg log -r 0 --template '{get(files, "should_fail")}\n'
3370 3370 hg: parse error: get() expects a dict as first argument
3371 3371 [255]
3372 3372
3373 3373 Test localdate(date, tz) function:
3374 3374
3375 3375 $ TZ=JST-09 hg log -r0 -T '{date|localdate|isodate}\n'
3376 3376 1970-01-01 09:00 +0900
3377 3377 $ TZ=JST-09 hg log -r0 -T '{localdate(date, "UTC")|isodate}\n'
3378 3378 1970-01-01 00:00 +0000
3379 3379 $ TZ=JST-09 hg log -r0 -T '{localdate(date, "blahUTC")|isodate}\n'
3380 3380 hg: parse error: localdate expects a timezone
3381 3381 [255]
3382 3382 $ TZ=JST-09 hg log -r0 -T '{localdate(date, "+0200")|isodate}\n'
3383 3383 1970-01-01 02:00 +0200
3384 3384 $ TZ=JST-09 hg log -r0 -T '{localdate(date, "0")|isodate}\n'
3385 3385 1970-01-01 00:00 +0000
3386 3386 $ TZ=JST-09 hg log -r0 -T '{localdate(date, 0)|isodate}\n'
3387 3387 1970-01-01 00:00 +0000
3388 3388 $ hg log -r0 -T '{localdate(date, "invalid")|isodate}\n'
3389 3389 hg: parse error: localdate expects a timezone
3390 3390 [255]
3391 3391 $ hg log -r0 -T '{localdate(date, date)|isodate}\n'
3392 3392 hg: parse error: localdate expects a timezone
3393 3393 [255]
3394 3394
3395 3395 Test shortest(node) function:
3396 3396
3397 3397 $ echo b > b
3398 3398 $ hg ci -qAm b
3399 3399 $ hg log --template '{shortest(node)}\n'
3400 3400 e777
3401 3401 bcc7
3402 3402 f776
3403 3403 $ hg log --template '{shortest(node, 10)}\n'
3404 3404 e777603221
3405 3405 bcc7ff960b
3406 3406 f7769ec2ab
3407 3407 $ hg log --template '{node|shortest}\n' -l1
3408 3408 e777
3409 3409
3410 3410 $ hg log -r 0 -T '{shortest(node, "1{"0"}")}\n'
3411 3411 f7769ec2ab
3412 3412 $ hg log -r 0 -T '{shortest(node, "not an int")}\n'
3413 3413 hg: parse error: shortest() expects an integer minlength
3414 3414 [255]
3415 3415
3416 3416 $ cd ..
3417 3417
3418 3418 Test shortest(node) with the repo having short hash collision:
3419 3419
3420 3420 $ hg init hashcollision
3421 3421 $ cd hashcollision
3422 3422 $ cat <<EOF >> .hg/hgrc
3423 3423 > [experimental]
3424 3424 > evolution = createmarkers
3425 3425 > EOF
3426 3426 $ echo 0 > a
3427 3427 $ hg ci -qAm 0
3428 3428 $ for i in 17 129 248 242 480 580 617 1057 2857 4025; do
3429 3429 > hg up -q 0
3430 3430 > echo $i > a
3431 3431 > hg ci -qm $i
3432 3432 > done
3433 3433 $ hg up -q null
3434 3434 $ hg log -r0: -T '{rev}:{node}\n'
3435 3435 0:b4e73ffab476aa0ee32ed81ca51e07169844bc6a
3436 3436 1:11424df6dc1dd4ea255eae2b58eaca7831973bbc
3437 3437 2:11407b3f1b9c3e76a79c1ec5373924df096f0499
3438 3438 3:11dd92fe0f39dfdaacdaa5f3997edc533875cfc4
3439 3439 4:10776689e627b465361ad5c296a20a487e153ca4
3440 3440 5:a00be79088084cb3aff086ab799f8790e01a976b
3441 3441 6:a0b0acd79b4498d0052993d35a6a748dd51d13e6
3442 3442 7:a0457b3450b8e1b778f1163b31a435802987fe5d
3443 3443 8:c56256a09cd28e5764f32e8e2810d0f01e2e357a
3444 3444 9:c5623987d205cd6d9d8389bfc40fff9dbb670b48
3445 3445 10:c562ddd9c94164376c20b86b0b4991636a3bf84f
3446 3446 $ hg debugobsolete a00be79088084cb3aff086ab799f8790e01a976b
3447 3447 $ hg debugobsolete c5623987d205cd6d9d8389bfc40fff9dbb670b48
3448 3448 $ hg debugobsolete c562ddd9c94164376c20b86b0b4991636a3bf84f
3449 3449
3450 3450 nodes starting with '11' (we don't have the revision number '11' though)
3451 3451
3452 3452 $ hg log -r 1:3 -T '{rev}:{shortest(node, 0)}\n'
3453 3453 1:1142
3454 3454 2:1140
3455 3455 3:11d
3456 3456
3457 3457 '5:a00' is hidden, but still we have two nodes starting with 'a0'
3458 3458
3459 3459 $ hg log -r 6:7 -T '{rev}:{shortest(node, 0)}\n'
3460 3460 6:a0b
3461 3461 7:a04
3462 3462
3463 3463 node '10' conflicts with the revision number '10' even if it is hidden
3464 3464 (we could exclude hidden revision numbers, but currently we don't)
3465 3465
3466 3466 $ hg log -r 4 -T '{rev}:{shortest(node, 0)}\n'
3467 3467 4:107
3468 3468 $ hg log -r 4 -T '{rev}:{shortest(node, 0)}\n' --hidden
3469 3469 4:107
3470 3470
3471 3471 node 'c562' should be unique if the other 'c562' nodes are hidden
3472 (but we don't try the slow path to filter out hidden nodes for now)
3472 3473
3473 3474 $ hg log -r 8 -T '{rev}:{node|shortest}\n'
3474 8:c562
3475 8:c5625
3475 3476 $ hg log -r 8:10 -T '{rev}:{node|shortest}\n' --hidden
3476 3477 8:c5625
3477 3478 9:c5623
3478 3479 10:c562d
3479 3480
3480 3481 $ cd ..
3481 3482
3482 3483 Test pad function
3483 3484
3484 3485 $ cd r
3485 3486
3486 3487 $ hg log --template '{pad(rev, 20)} {author|user}\n'
3487 3488 2 test
3488 3489 1 {node|short}
3489 3490 0 test
3490 3491
3491 3492 $ hg log --template '{pad(rev, 20, " ", True)} {author|user}\n'
3492 3493 2 test
3493 3494 1 {node|short}
3494 3495 0 test
3495 3496
3496 3497 $ hg log --template '{pad(rev, 20, "-", False)} {author|user}\n'
3497 3498 2------------------- test
3498 3499 1------------------- {node|short}
3499 3500 0------------------- test
3500 3501
3501 3502 Test template string in pad function
3502 3503
3503 3504 $ hg log -r 0 -T '{pad("\{{rev}}", 10)} {author|user}\n'
3504 3505 {0} test
3505 3506
3506 3507 $ hg log -r 0 -T '{pad(r"\{rev}", 10)} {author|user}\n'
3507 3508 \{rev} test
3508 3509
3509 3510 Test width argument passed to pad function
3510 3511
3511 3512 $ hg log -r 0 -T '{pad(rev, "1{"0"}")} {author|user}\n'
3512 3513 0 test
3513 3514 $ hg log -r 0 -T '{pad(rev, "not an int")}\n'
3514 3515 hg: parse error: pad() expects an integer width
3515 3516 [255]
3516 3517
3517 3518 Test boolean argument passed to pad function
3518 3519
3519 3520 no crash
3520 3521
3521 3522 $ hg log -r 0 -T '{pad(rev, 10, "-", "f{"oo"}")}\n'
3522 3523 ---------0
3523 3524
3524 3525 string/literal
3525 3526
3526 3527 $ hg log -r 0 -T '{pad(rev, 10, "-", "false")}\n'
3527 3528 ---------0
3528 3529 $ hg log -r 0 -T '{pad(rev, 10, "-", false)}\n'
3529 3530 0---------
3530 3531 $ hg log -r 0 -T '{pad(rev, 10, "-", "")}\n'
3531 3532 0---------
3532 3533
3533 3534 unknown keyword is evaluated to ''
3534 3535
3535 3536 $ hg log -r 0 -T '{pad(rev, 10, "-", unknownkeyword)}\n'
3536 3537 0---------
3537 3538
3538 3539 Test separate function
3539 3540
3540 3541 $ hg log -r 0 -T '{separate("-", "", "a", "b", "", "", "c", "")}\n'
3541 3542 a-b-c
3542 3543 $ hg log -r 0 -T '{separate(" ", "{rev}:{node|short}", author|user, branch)}\n'
3543 3544 0:f7769ec2ab97 test default
3544 3545 $ hg log -r 0 --color=always -T '{separate(" ", "a", label(red, "b"), "c", label(red, ""), "d")}\n'
3545 3546 a \x1b[0;31mb\x1b[0m c d (esc)
3546 3547
3547 3548 Test boolean expression/literal passed to if function
3548 3549
3549 3550 $ hg log -r 0 -T '{if(rev, "rev 0 is True")}\n'
3550 3551 rev 0 is True
3551 3552 $ hg log -r 0 -T '{if(0, "literal 0 is True as well")}\n'
3552 3553 literal 0 is True as well
3553 3554 $ hg log -r 0 -T '{if("", "", "empty string is False")}\n'
3554 3555 empty string is False
3555 3556 $ hg log -r 0 -T '{if(revset(r"0 - 0"), "", "empty list is False")}\n'
3556 3557 empty list is False
3557 3558 $ hg log -r 0 -T '{if(true, "true is True")}\n'
3558 3559 true is True
3559 3560 $ hg log -r 0 -T '{if(false, "", "false is False")}\n'
3560 3561 false is False
3561 3562 $ hg log -r 0 -T '{if("false", "non-empty string is True")}\n'
3562 3563 non-empty string is True
3563 3564
3564 3565 Test ifcontains function
3565 3566
3566 3567 $ hg log --template '{rev} {ifcontains(rev, "2 two 0", "is in the string", "is not")}\n'
3567 3568 2 is in the string
3568 3569 1 is not
3569 3570 0 is in the string
3570 3571
3571 3572 $ hg log -T '{rev} {ifcontains(rev, "2 two{" 0"}", "is in the string", "is not")}\n'
3572 3573 2 is in the string
3573 3574 1 is not
3574 3575 0 is in the string
3575 3576
3576 3577 $ hg log --template '{rev} {ifcontains("a", file_adds, "added a", "did not add a")}\n'
3577 3578 2 did not add a
3578 3579 1 did not add a
3579 3580 0 added a
3580 3581
3581 3582 $ hg log --debug -T '{rev}{ifcontains(1, parents, " is parent of 1")}\n'
3582 3583 2 is parent of 1
3583 3584 1
3584 3585 0
3585 3586
3586 3587 Test revset function
3587 3588
3588 3589 $ hg log --template '{rev} {ifcontains(rev, revset("."), "current rev", "not current rev")}\n'
3589 3590 2 current rev
3590 3591 1 not current rev
3591 3592 0 not current rev
3592 3593
3593 3594 $ hg log --template '{rev} {ifcontains(rev, revset(". + .^"), "match rev", "not match rev")}\n'
3594 3595 2 match rev
3595 3596 1 match rev
3596 3597 0 not match rev
3597 3598
3598 3599 $ hg log --template '{rev} Parents: {revset("parents(%s)", rev)}\n'
3599 3600 2 Parents: 1
3600 3601 1 Parents: 0
3601 3602 0 Parents:
3602 3603
3603 3604 $ cat >> .hg/hgrc <<EOF
3604 3605 > [revsetalias]
3605 3606 > myparents(\$1) = parents(\$1)
3606 3607 > EOF
3607 3608 $ hg log --template '{rev} Parents: {revset("myparents(%s)", rev)}\n'
3608 3609 2 Parents: 1
3609 3610 1 Parents: 0
3610 3611 0 Parents:
3611 3612
3612 3613 $ hg log --template 'Rev: {rev}\n{revset("::%s", rev) % "Ancestor: {revision}\n"}\n'
3613 3614 Rev: 2
3614 3615 Ancestor: 0
3615 3616 Ancestor: 1
3616 3617 Ancestor: 2
3617 3618
3618 3619 Rev: 1
3619 3620 Ancestor: 0
3620 3621 Ancestor: 1
3621 3622
3622 3623 Rev: 0
3623 3624 Ancestor: 0
3624 3625
3625 3626 $ hg log --template '{revset("TIP"|lower)}\n' -l1
3626 3627 2
3627 3628
3628 3629 $ hg log -T '{revset("%s", "t{"ip"}")}\n' -l1
3629 3630 2
3630 3631
3631 3632 a list template is evaluated for each item of revset/parents
3632 3633
3633 3634 $ hg log -T '{rev} p: {revset("p1(%s)", rev) % "{rev}:{node|short}"}\n'
3634 3635 2 p: 1:bcc7ff960b8e
3635 3636 1 p: 0:f7769ec2ab97
3636 3637 0 p:
3637 3638
3638 3639 $ hg log --debug -T '{rev} p:{parents % " {rev}:{node|short}"}\n'
3639 3640 2 p: 1:bcc7ff960b8e -1:000000000000
3640 3641 1 p: 0:f7769ec2ab97 -1:000000000000
3641 3642 0 p: -1:000000000000 -1:000000000000
3642 3643
3643 3644 therefore, 'revcache' should be recreated for each rev
3644 3645
3645 3646 $ hg log -T '{rev} {file_adds}\np {revset("p1(%s)", rev) % "{file_adds}"}\n'
3646 3647 2 aa b
3647 3648 p
3648 3649 1
3649 3650 p a
3650 3651 0 a
3651 3652 p
3652 3653
3653 3654 $ hg log --debug -T '{rev} {file_adds}\np {parents % "{file_adds}"}\n'
3654 3655 2 aa b
3655 3656 p
3656 3657 1
3657 3658 p a
3658 3659 0 a
3659 3660 p
3660 3661
3661 3662 a revset item must be evaluated as an integer revision, not an offset from tip
3662 3663
3663 3664 $ hg log -l 1 -T '{revset("null") % "{rev}:{node|short}"}\n'
3664 3665 -1:000000000000
3665 3666 $ hg log -l 1 -T '{revset("%s", "null") % "{rev}:{node|short}"}\n'
3666 3667 -1:000000000000
3667 3668
3668 3669 join() should pick '{rev}' from revset items:
3669 3670
3670 3671 $ hg log -R ../a -T '{join(revset("parents(%d)", rev), ", ")}\n' -r6
3671 3672 4, 5
3672 3673
3673 3674 on the other hand, parents are formatted as '{rev}:{node|formatnode}' by
3674 3675 default. join() should agree with the default formatting:
3675 3676
3676 3677 $ hg log -R ../a -T '{join(parents, ", ")}\n' -r6
3677 3678 5:13207e5a10d9, 4:bbe44766e73d
3678 3679
3679 3680 $ hg log -R ../a -T '{join(parents, ",\n")}\n' -r6 --debug
3680 3681 5:13207e5a10d9fd28ec424934298e176197f2c67f,
3681 3682 4:bbe44766e73d5f11ed2177f1838de10c53ef3e74
3682 3683
3683 3684 Test files function
3684 3685
3685 3686 $ hg log -T "{rev}\n{join(files('*'), '\n')}\n"
3686 3687 2
3687 3688 a
3688 3689 aa
3689 3690 b
3690 3691 1
3691 3692 a
3692 3693 0
3693 3694 a
3694 3695
3695 3696 $ hg log -T "{rev}\n{join(files('aa'), '\n')}\n"
3696 3697 2
3697 3698 aa
3698 3699 1
3699 3700
3700 3701 0
3701 3702
3702 3703
3703 3704 Test relpath function
3704 3705
3705 3706 $ hg log -r0 -T '{files % "{file|relpath}\n"}'
3706 3707 a
3707 3708 $ cd ..
3708 3709 $ hg log -R r -r0 -T '{files % "{file|relpath}\n"}'
3709 3710 r/a (glob)
3710 3711 $ cd r
3711 3712
3712 3713 Test active bookmark templating
3713 3714
3714 3715 $ hg book foo
3715 3716 $ hg book bar
3716 3717 $ hg log --template "{rev} {bookmarks % '{bookmark}{ifeq(bookmark, active, \"*\")} '}\n"
3717 3718 2 bar* foo
3718 3719 1
3719 3720 0
3720 3721 $ hg log --template "{rev} {activebookmark}\n"
3721 3722 2 bar
3722 3723 1
3723 3724 0
3724 3725 $ hg bookmarks --inactive bar
3725 3726 $ hg log --template "{rev} {activebookmark}\n"
3726 3727 2
3727 3728 1
3728 3729 0
3729 3730 $ hg book -r1 baz
3730 3731 $ hg log --template "{rev} {join(bookmarks, ' ')}\n"
3731 3732 2 bar foo
3732 3733 1 baz
3733 3734 0
3734 3735 $ hg log --template "{rev} {ifcontains('foo', bookmarks, 't', 'f')}\n"
3735 3736 2 t
3736 3737 1 f
3737 3738 0 f
3738 3739
3739 3740 Test namespaces dict
3740 3741
3741 3742 $ hg log -T '{rev}{namespaces % " {namespace}={join(names, ",")}"}\n'
3742 3743 2 bookmarks=bar,foo tags=tip branches=text.{rev}
3743 3744 1 bookmarks=baz tags= branches=text.{rev}
3744 3745 0 bookmarks= tags= branches=default
3745 3746 $ hg log -r2 -T '{namespaces % "{namespace}: {names}\n"}'
3746 3747 bookmarks: bar foo
3747 3748 tags: tip
3748 3749 branches: text.{rev}
3749 3750 $ hg log -r2 -T '{namespaces % "{namespace}:\n{names % " {name}\n"}"}'
3750 3751 bookmarks:
3751 3752 bar
3752 3753 foo
3753 3754 tags:
3754 3755 tip
3755 3756 branches:
3756 3757 text.{rev}
3757 3758 $ hg log -r2 -T '{get(namespaces, "bookmarks") % "{name}\n"}'
3758 3759 bar
3759 3760 foo
3760 3761
3761 3762 Test stringify on sub expressions
3762 3763
3763 3764 $ cd ..
3764 3765 $ hg log -R a -r 8 --template '{join(files, if("1", if("1", ", ")))}\n'
3765 3766 fourth, second, third
3766 3767 $ hg log -R a -r 8 --template '{strip(if("1", if("1", "-abc-")), if("1", if("1", "-")))}\n'
3767 3768 abc
3768 3769
3769 3770 Test splitlines
3770 3771
3771 3772 $ hg log -Gv -R a --template "{splitlines(desc) % 'foo {line}\n'}"
3772 3773 @ foo Modify, add, remove, rename
3773 3774 |
3774 3775 o foo future
3775 3776 |
3776 3777 o foo third
3777 3778 |
3778 3779 o foo second
3779 3780
3780 3781 o foo merge
3781 3782 |\
3782 3783 | o foo new head
3783 3784 | |
3784 3785 o | foo new branch
3785 3786 |/
3786 3787 o foo no user, no domain
3787 3788 |
3788 3789 o foo no person
3789 3790 |
3790 3791 o foo other 1
3791 3792 | foo other 2
3792 3793 | foo
3793 3794 | foo other 3
3794 3795 o foo line 1
3795 3796 foo line 2
3796 3797
3797 3798 Test startswith
3798 3799 $ hg log -Gv -R a --template "{startswith(desc)}"
3799 3800 hg: parse error: startswith expects two arguments
3800 3801 [255]
3801 3802
3802 3803 $ hg log -Gv -R a --template "{startswith('line', desc)}"
3803 3804 @
3804 3805 |
3805 3806 o
3806 3807 |
3807 3808 o
3808 3809 |
3809 3810 o
3810 3811
3811 3812 o
3812 3813 |\
3813 3814 | o
3814 3815 | |
3815 3816 o |
3816 3817 |/
3817 3818 o
3818 3819 |
3819 3820 o
3820 3821 |
3821 3822 o
3822 3823 |
3823 3824 o line 1
3824 3825 line 2
3825 3826
3826 3827 Test bad template with better error message
3827 3828
3828 3829 $ hg log -Gv -R a --template '{desc|user()}'
3829 3830 hg: parse error: expected a symbol, got 'func'
3830 3831 [255]
3831 3832
3832 3833 Test word function (including index out of bounds graceful failure)
3833 3834
3834 3835 $ hg log -Gv -R a --template "{word('1', desc)}"
3835 3836 @ add,
3836 3837 |
3837 3838 o
3838 3839 |
3839 3840 o
3840 3841 |
3841 3842 o
3842 3843
3843 3844 o
3844 3845 |\
3845 3846 | o head
3846 3847 | |
3847 3848 o | branch
3848 3849 |/
3849 3850 o user,
3850 3851 |
3851 3852 o person
3852 3853 |
3853 3854 o 1
3854 3855 |
3855 3856 o 1
3856 3857
3857 3858
3858 3859 Test word third parameter used as splitter
3859 3860
3860 3861 $ hg log -Gv -R a --template "{word('0', desc, 'o')}"
3861 3862 @ M
3862 3863 |
3863 3864 o future
3864 3865 |
3865 3866 o third
3866 3867 |
3867 3868 o sec
3868 3869
3869 3870 o merge
3870 3871 |\
3871 3872 | o new head
3872 3873 | |
3873 3874 o | new branch
3874 3875 |/
3875 3876 o n
3876 3877 |
3877 3878 o n
3878 3879 |
3879 3880 o
3880 3881 |
3881 3882 o line 1
3882 3883 line 2
3883 3884
3884 3885 Test word error messages for not enough and too many arguments
3885 3886
3886 3887 $ hg log -Gv -R a --template "{word('0')}"
3887 3888 hg: parse error: word expects two or three arguments, got 1
3888 3889 [255]
3889 3890
3890 3891 $ hg log -Gv -R a --template "{word('0', desc, 'o', 'h', 'b', 'o', 'y')}"
3891 3892 hg: parse error: word expects two or three arguments, got 7
3892 3893 [255]
3893 3894
3894 3895 Test word for integer literal
3895 3896
3896 3897 $ hg log -R a --template "{word(2, desc)}\n" -r0
3897 3898 line
3898 3899
3899 3900 Test word for invalid numbers
3900 3901
3901 3902 $ hg log -Gv -R a --template "{word('a', desc)}"
3902 3903 hg: parse error: word expects an integer index
3903 3904 [255]
3904 3905
3905 3906 Test word for out of range
3906 3907
3907 3908 $ hg log -R a --template "{word(10000, desc)}"
3908 3909 $ hg log -R a --template "{word(-10000, desc)}"
3909 3910
3910 3911 Test indent and not adding to empty lines
3911 3912
3912 3913 $ hg log -T "-----\n{indent(desc, '>> ', ' > ')}\n" -r 0:1 -R a
3913 3914 -----
3914 3915 > line 1
3915 3916 >> line 2
3916 3917 -----
3917 3918 > other 1
3918 3919 >> other 2
3919 3920
3920 3921 >> other 3
3921 3922
3922 3923 Test with non-strings like dates
3923 3924
3924 3925 $ hg log -T "{indent(date, ' ')}\n" -r 2:3 -R a
3925 3926 1200000.00
3926 3927 1300000.00
3927 3928
3928 3929 Test broken string escapes:
3929 3930
3930 3931 $ hg log -T "bogus\\" -R a
3931 3932 hg: parse error: trailing \ in string
3932 3933 [255]
3933 3934 $ hg log -T "\\xy" -R a
3934 3935 hg: parse error: invalid \x escape
3935 3936 [255]
3936 3937
3937 3938 json filter should escape HTML tags so that the output can be embedded in hgweb:
3938 3939
3939 3940 $ hg log -T "{'<foo@example.org>'|json}\n" -R a -l1
3940 3941 "\u003cfoo@example.org\u003e"
3941 3942
3942 3943 Templater supports aliases of symbol and func() styles:
3943 3944
3944 3945 $ hg clone -q a aliases
3945 3946 $ cd aliases
3946 3947 $ cat <<EOF >> .hg/hgrc
3947 3948 > [templatealias]
3948 3949 > r = rev
3949 3950 > rn = "{r}:{node|short}"
3950 3951 > status(c, files) = files % "{c} {file}\n"
3951 3952 > utcdate(d) = localdate(d, "UTC")
3952 3953 > EOF
3953 3954
3954 3955 $ hg debugtemplate -vr0 '{rn} {utcdate(date)|isodate}\n'
3955 3956 (template
3956 3957 ('symbol', 'rn')
3957 3958 ('string', ' ')
3958 3959 (|
3959 3960 (func
3960 3961 ('symbol', 'utcdate')
3961 3962 ('symbol', 'date'))
3962 3963 ('symbol', 'isodate'))
3963 3964 ('string', '\n'))
3964 3965 * expanded:
3965 3966 (template
3966 3967 (template
3967 3968 ('symbol', 'rev')
3968 3969 ('string', ':')
3969 3970 (|
3970 3971 ('symbol', 'node')
3971 3972 ('symbol', 'short')))
3972 3973 ('string', ' ')
3973 3974 (|
3974 3975 (func
3975 3976 ('symbol', 'localdate')
3976 3977 (list
3977 3978 ('symbol', 'date')
3978 3979 ('string', 'UTC')))
3979 3980 ('symbol', 'isodate'))
3980 3981 ('string', '\n'))
3981 3982 0:1e4e1b8f71e0 1970-01-12 13:46 +0000
3982 3983
3983 3984 $ hg debugtemplate -vr0 '{status("A", file_adds)}'
3984 3985 (template
3985 3986 (func
3986 3987 ('symbol', 'status')
3987 3988 (list
3988 3989 ('string', 'A')
3989 3990 ('symbol', 'file_adds'))))
3990 3991 * expanded:
3991 3992 (template
3992 3993 (%
3993 3994 ('symbol', 'file_adds')
3994 3995 (template
3995 3996 ('string', 'A')
3996 3997 ('string', ' ')
3997 3998 ('symbol', 'file')
3998 3999 ('string', '\n'))))
3999 4000 A a
4000 4001
4001 4002 A unary function alias can be called as a filter:
4002 4003
4003 4004 $ hg debugtemplate -vr0 '{date|utcdate|isodate}\n'
4004 4005 (template
4005 4006 (|
4006 4007 (|
4007 4008 ('symbol', 'date')
4008 4009 ('symbol', 'utcdate'))
4009 4010 ('symbol', 'isodate'))
4010 4011 ('string', '\n'))
4011 4012 * expanded:
4012 4013 (template
4013 4014 (|
4014 4015 (func
4015 4016 ('symbol', 'localdate')
4016 4017 (list
4017 4018 ('symbol', 'date')
4018 4019 ('string', 'UTC')))
4019 4020 ('symbol', 'isodate'))
4020 4021 ('string', '\n'))
4021 4022 1970-01-12 13:46 +0000
4022 4023
4023 4024 Aliases should be applied only to command arguments and templates in hgrc.
4024 4025 Otherwise, our stock styles and web templates could be corrupted:
4025 4026
4026 4027 $ hg log -r0 -T '{rn} {utcdate(date)|isodate}\n'
4027 4028 0:1e4e1b8f71e0 1970-01-12 13:46 +0000
4028 4029
4029 4030 $ hg log -r0 --config ui.logtemplate='"{rn} {utcdate(date)|isodate}\n"'
4030 4031 0:1e4e1b8f71e0 1970-01-12 13:46 +0000
4031 4032
4032 4033 $ cat <<EOF > tmpl
4033 4034 > changeset = 'nothing expanded:{rn}\n'
4034 4035 > EOF
4035 4036 $ hg log -r0 --style ./tmpl
4036 4037 nothing expanded:
4037 4038
4038 4039 Aliases in formatter:
4039 4040
4040 4041 $ hg branches -T '{pad(branch, 7)} {rn}\n'
4041 4042 default 6:d41e714fe50d
4042 4043 foo 4:bbe44766e73d
4043 4044
4044 4045 Aliases should honor HGPLAIN:
4045 4046
4046 4047 $ HGPLAIN= hg log -r0 -T 'nothing expanded:{rn}\n'
4047 4048 nothing expanded:
4048 4049 $ HGPLAINEXCEPT=templatealias hg log -r0 -T '{rn}\n'
4049 4050 0:1e4e1b8f71e0
4050 4051
4051 4052 Unparsable alias:
4052 4053
4053 4054 $ hg debugtemplate --config templatealias.bad='x(' -v '{bad}'
4054 4055 (template
4055 4056 ('symbol', 'bad'))
4056 4057 abort: bad definition of template alias "bad": at 2: not a prefix: end
4057 4058 [255]
4058 4059 $ hg log --config templatealias.bad='x(' -T '{bad}'
4059 4060 abort: bad definition of template alias "bad": at 2: not a prefix: end
4060 4061 [255]
4061 4062
4062 4063 $ cd ..
4063 4064
4064 4065 Set up repository for non-ascii encoding tests:
4065 4066
4066 4067 $ hg init nonascii
4067 4068 $ cd nonascii
4068 4069 $ python <<EOF
4069 4070 > open('latin1', 'w').write('\xe9')
4070 4071 > open('utf-8', 'w').write('\xc3\xa9')
4071 4072 > EOF
4072 4073 $ HGENCODING=utf-8 hg branch -q `cat utf-8`
4073 4074 $ HGENCODING=utf-8 hg ci -qAm "non-ascii branch: `cat utf-8`" utf-8
4074 4075
4075 4076 json filter should try round-trip conversion to utf-8:
4076 4077
4077 4078 $ HGENCODING=ascii hg log -T "{branch|json}\n" -r0
4078 4079 "\u00e9"
4079 4080 $ HGENCODING=ascii hg log -T "{desc|json}\n" -r0
4080 4081 "non-ascii branch: \u00e9"
4081 4082
4082 4083 json filter takes input as utf-8b:
4083 4084
4084 4085 $ HGENCODING=ascii hg log -T "{'`cat utf-8`'|json}\n" -l1
4085 4086 "\u00e9"
4086 4087 $ HGENCODING=ascii hg log -T "{'`cat latin1`'|json}\n" -l1
4087 4088 "\udce9"
4088 4089
4089 4090 utf8 filter:
4090 4091
4091 4092 $ HGENCODING=ascii hg log -T "round-trip: {branch|utf8|hex}\n" -r0
4092 4093 round-trip: c3a9
4093 4094 $ HGENCODING=latin1 hg log -T "decoded: {'`cat latin1`'|utf8|hex}\n" -l1
4094 4095 decoded: c3a9
4095 4096 $ HGENCODING=ascii hg log -T "replaced: {'`cat latin1`'|utf8|hex}\n" -l1
4096 4097 abort: decoding near * (glob)
4097 4098 [255]
4098 4099 $ hg log -T "invalid type: {rev|utf8}\n" -r0
4099 4100 abort: template filter 'utf8' is not compatible with keyword 'rev'
4100 4101 [255]
4101 4102
4102 4103 $ cd ..
4103 4104
4104 4105 Test that template function in extension is registered as expected
4105 4106
4106 4107 $ cd a
4107 4108
4108 4109 $ cat <<EOF > $TESTTMP/customfunc.py
4109 4110 > from mercurial import registrar
4110 4111 >
4111 4112 > templatefunc = registrar.templatefunc()
4112 4113 >
4113 4114 > @templatefunc('custom()')
4114 4115 > def custom(context, mapping, args):
4115 4116 > return 'custom'
4116 4117 > EOF
4117 4118 $ cat <<EOF > .hg/hgrc
4118 4119 > [extensions]
4119 4120 > customfunc = $TESTTMP/customfunc.py
4120 4121 > EOF
4121 4122
4122 4123 $ hg log -r . -T "{custom()}\n" --config customfunc.enabled=true
4123 4124 custom
4124 4125
4125 4126 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now