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