comparison mercurial/commands.py @ 1913:74cf2b2f43d4

fix some things people wanted to be cleaner. rename --map-file to --style. no more -t alias for --template. update docs. rename template entry in map files to changelog. if --verbose, use changelog_verbose if there, else changelog.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Sat, 04 Mar 2006 12:40:10 -0800
parents e2fe1953f417
children a5bf0030df5f
comparison
equal deleted inserted replaced
1912:b288b4bb8448 1913:74cf2b2f43d4
339 339
340 class changeset_templater(object): 340 class changeset_templater(object):
341 '''use templater module to format changeset information.''' 341 '''use templater module to format changeset information.'''
342 342
343 def __init__(self, ui, repo, mapfile): 343 def __init__(self, ui, repo, mapfile):
344 self.t = templater.templater(mapfile, templater.common_filters) 344 self.t = templater.templater(mapfile, templater.common_filters,
345 cache={'parent': '{rev}:{node|short} ',
346 'manifest': '{rev}:{node|short}'})
345 self.ui = ui 347 self.ui = ui
346 self.repo = repo 348 self.repo = repo
347 349
348 def use_template(self, t): 350 def use_template(self, t):
349 '''set template string to use''' 351 '''set template string to use'''
350 self.t.cache['template'] = t 352 self.t.cache['changelog'] = t
351 353
352 def write(self, thing): 354 def write(self, thing):
353 '''write expanded template. 355 '''write expanded template.
354 uses in-order recursive traverse of iterators.''' 356 uses in-order recursive traverse of iterators.'''
355 for t in thing: 357 for t in thing:
394 noname = 'no_' + names 396 noname = 'no_' + names
395 if noname in self.t: 397 if noname in self.t:
396 yield self.t(noname, **args) 398 yield self.t(noname, **args)
397 return 399 return
398 if name not in self.t: 400 if name not in self.t:
399 yield ' '.join(values) 401 if isinstance(values[0], str):
402 yield ' '.join(values)
403 else:
404 for v in values:
405 yield dict(v, **args)
400 return 406 return
401 startname = 'start_' + names 407 startname = 'start_' + names
402 if startname in self.t: 408 if startname in self.t:
403 yield self.t(startname, **args) 409 yield self.t(startname, **args)
404 vargs = args.copy() 410 vargs = args.copy()
481 'rev': rev, 487 'rev': rev,
482 'tags': showtags, 488 'tags': showtags,
483 } 489 }
484 490
485 try: 491 try:
486 self.write(self.t('template', **props)) 492 if self.ui.verbose and 'changelog_verbose' in self.t:
493 key = 'changelog_verbose'
494 else:
495 key = 'changelog'
496 self.write(self.t(key, **props))
487 except KeyError, inst: 497 except KeyError, inst:
488 raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, 498 raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile,
489 inst.args[0])) 499 inst.args[0]))
490 except SyntaxError, inst: 500 except SyntaxError, inst:
491 raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) 501 raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0]))
558 description.splitlines()[0]) 568 description.splitlines()[0])
559 self.ui.status("\n") 569 self.ui.status("\n")
560 570
561 def show_changeset(ui, repo, opts): 571 def show_changeset(ui, repo, opts):
562 '''show one changeset. uses template or regular display. caller 572 '''show one changeset. uses template or regular display. caller
563 can pass in 'map_file' and 'template' options in opts.''' 573 can pass in 'style' and 'template' options in opts.'''
564 574
565 tmpl = opts.get('template') 575 tmpl = opts.get('template')
566 if tmpl: 576 if tmpl:
567 tmpl = templater.parsestring(tmpl, quoted=False) 577 tmpl = templater.parsestring(tmpl, quoted=False)
568 else: 578 else:
569 tmpl = ui.config('ui', 'logtemplate') 579 tmpl = ui.config('ui', 'logtemplate')
570 if tmpl: tmpl = templater.parsestring(tmpl) 580 if tmpl: tmpl = templater.parsestring(tmpl)
571 mapfile = opts.get('map_file') or ui.config('ui', 'logmap') 581 mapfile = opts.get('style') or ui.config('ui', 'logmap')
572 if tmpl or mapfile: 582 if tmpl or mapfile:
573 if mapfile: 583 if mapfile:
574 if not os.path.isfile(mapfile): 584 if not os.path.isfile(mapfile):
575 mapname = templater.templatepath(mapfile) 585 mapname = templater.templatepath(mapfile)
576 if mapname: mapfile = mapname 586 if mapname: mapfile = mapname
2653 ('u', 'user', None, _('print user who committed change'))], 2663 ('u', 'user', None, _('print user who committed change'))],
2654 _('hg grep [OPTION]... PATTERN [FILE]...')), 2664 _('hg grep [OPTION]... PATTERN [FILE]...')),
2655 "heads": 2665 "heads":
2656 (heads, 2666 (heads,
2657 [('b', 'branches', None, _('show branches')), 2667 [('b', 'branches', None, _('show branches')),
2658 ('', 'map-file', '', _('display using template map file')), 2668 ('', 'style', '', _('display using template map file')),
2659 ('r', 'rev', '', _('show only heads which are descendants of rev')), 2669 ('r', 'rev', '', _('show only heads which are descendants of rev')),
2660 ('t', 'template', '', _('display with template'))], 2670 ('', 'template', '', _('display with template'))],
2661 _('hg heads [-b] [-r <rev>]')), 2671 _('hg heads [-b] [-r <rev>]')),
2662 "help": (help_, [], _('hg help [COMMAND]')), 2672 "help": (help_, [], _('hg help [COMMAND]')),
2663 "identify|id": (identify, [], _('hg identify')), 2673 "identify|id": (identify, [], _('hg identify')),
2664 "import|patch": 2674 "import|patch":
2665 (import_, 2675 (import_,
2670 _('skip check for outstanding uncommitted changes')), 2680 _('skip check for outstanding uncommitted changes')),
2671 ('b', 'base', '', _('base path'))], 2681 ('b', 'base', '', _('base path'))],
2672 _('hg import [-f] [-p NUM] [-b BASE] PATCH...')), 2682 _('hg import [-f] [-p NUM] [-b BASE] PATCH...')),
2673 "incoming|in": (incoming, 2683 "incoming|in": (incoming,
2674 [('M', 'no-merges', None, _('do not show merges')), 2684 [('M', 'no-merges', None, _('do not show merges')),
2675 ('', 'map-file', '', _('display using template map file')), 2685 ('', 'style', '', _('display using template map file')),
2676 ('n', 'newest-first', None, _('show newest record first')), 2686 ('n', 'newest-first', None, _('show newest record first')),
2677 ('p', 'patch', None, _('show patch')), 2687 ('p', 'patch', None, _('show patch')),
2678 ('t', 'template', '', _('display with template'))], 2688 ('', 'template', '', _('display with template'))],
2679 _('hg incoming [-p] [-n] [-M] [SOURCE]')), 2689 _('hg incoming [-p] [-n] [-M] [SOURCE]')),
2680 "^init": (init, [], _('hg init [DEST]')), 2690 "^init": (init, [], _('hg init [DEST]')),
2681 "locate": 2691 "locate":
2682 (locate, 2692 (locate,
2683 [('r', 'rev', '', _('search the repository as it stood at rev')), 2693 [('r', 'rev', '', _('search the repository as it stood at rev')),
2695 ('b', 'branches', None, _('show branches')), 2705 ('b', 'branches', None, _('show branches')),
2696 ('k', 'keyword', [], _('search for a keyword')), 2706 ('k', 'keyword', [], _('search for a keyword')),
2697 ('l', 'limit', '', _('limit number of changes displayed')), 2707 ('l', 'limit', '', _('limit number of changes displayed')),
2698 ('r', 'rev', [], _('show the specified revision or range')), 2708 ('r', 'rev', [], _('show the specified revision or range')),
2699 ('M', 'no-merges', None, _('do not show merges')), 2709 ('M', 'no-merges', None, _('do not show merges')),
2700 ('', 'map-file', '', _('display using template map file')), 2710 ('', 'style', '', _('display using template map file')),
2701 ('m', 'only-merges', None, _('show only merges')), 2711 ('m', 'only-merges', None, _('show only merges')),
2702 ('p', 'patch', None, _('show patch')), 2712 ('p', 'patch', None, _('show patch')),
2703 ('t', 'template', '', _('display with template'))], 2713 ('', 'template', '', _('display with template'))],
2704 _('hg log [-I] [-X] [-r REV]... [-p] [FILE]')), 2714 _('hg log [-I] [-X] [-r REV]... [-p] [FILE]')),
2705 "manifest": (manifest, [], _('hg manifest [REV]')), 2715 "manifest": (manifest, [], _('hg manifest [REV]')),
2706 "outgoing|out": (outgoing, 2716 "outgoing|out": (outgoing,
2707 [('M', 'no-merges', None, _('do not show merges')), 2717 [('M', 'no-merges', None, _('do not show merges')),
2708 ('p', 'patch', None, _('show patch')), 2718 ('p', 'patch', None, _('show patch')),
2709 ('', 'map-file', '', _('display using template map file')), 2719 ('', 'style', '', _('display using template map file')),
2710 ('n', 'newest-first', None, _('show newest record first')), 2720 ('n', 'newest-first', None, _('show newest record first')),
2711 ('t', 'template', '', _('display with template'))], 2721 ('', 'template', '', _('display with template'))],
2712 _('hg outgoing [-p] [-n] [-M] [DEST]')), 2722 _('hg outgoing [-p] [-n] [-M] [DEST]')),
2713 "^parents": 2723 "^parents":
2714 (parents, 2724 (parents,
2715 [('b', 'branches', None, _('show branches')), 2725 [('b', 'branches', None, _('show branches')),
2716 ('', 'map-file', '', _('display using template map file')), 2726 ('', 'style', '', _('display using template map file')),
2717 ('t', 'template', '', _('display with template'))], 2727 ('', 'template', '', _('display with template'))],
2718 _('hg parents [-b] [REV]')), 2728 _('hg parents [-b] [REV]')),
2719 "paths": (paths, [], _('hg paths [NAME]')), 2729 "paths": (paths, [], _('hg paths [NAME]')),
2720 "^pull": 2730 "^pull":
2721 (pull, 2731 (pull,
2722 [('u', 'update', None, 2732 [('u', 'update', None,
2774 ('a', 'address', '', _('address to use')), 2784 ('a', 'address', '', _('address to use')),
2775 ('n', 'name', '', 2785 ('n', 'name', '',
2776 _('name to show in web pages (default: working dir)')), 2786 _('name to show in web pages (default: working dir)')),
2777 ('', 'pid-file', '', _('name of file to write process ID to')), 2787 ('', 'pid-file', '', _('name of file to write process ID to')),
2778 ('', 'stdio', None, _('for remote clients')), 2788 ('', 'stdio', None, _('for remote clients')),
2779 ('t', 'templates', '', _('web templates to use')), 2789 ('', 'templates', '', _('web templates to use')),
2780 ('', 'style', '', _('template style to use')), 2790 ('', 'style', '', _('template style to use')),
2781 ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], 2791 ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))],
2782 _('hg serve [OPTION]...')), 2792 _('hg serve [OPTION]...')),
2783 "^status|st": 2793 "^status|st":
2784 (status, 2794 (status,
2803 _('hg tag [-r REV] [OPTION]... NAME')), 2813 _('hg tag [-r REV] [OPTION]... NAME')),
2804 "tags": (tags, [], _('hg tags')), 2814 "tags": (tags, [], _('hg tags')),
2805 "tip": 2815 "tip":
2806 (tip, 2816 (tip,
2807 [('b', 'branches', None, _('show branches')), 2817 [('b', 'branches', None, _('show branches')),
2808 ('', 'map-file', '', _('display using template map file')), 2818 ('', 'style', '', _('display using template map file')),
2809 ('p', 'patch', None, _('show patch')), 2819 ('p', 'patch', None, _('show patch')),
2810 ('t', 'template', '', _('display with template'))], 2820 ('', 'template', '', _('display with template'))],
2811 _('hg [-b] [-p] tip')), 2821 _('hg [-b] [-p] tip')),
2812 "unbundle": 2822 "unbundle":
2813 (unbundle, 2823 (unbundle,
2814 [('u', 'update', None, 2824 [('u', 'update', None,
2815 _('update the working directory to tip after unbundle'))], 2825 _('update the working directory to tip after unbundle'))],
2816 _('hg unbundle [-u] FILE')), 2826 _('hg unbundle [-u] FILE')),
2817 "undo": (undo, [], _('hg undo')), 2827 "undo": (undo, [], _('hg undo')),
2818 "^update|up|checkout|co": 2828 "^update|up|checkout|co":
2819 (update, 2829 (update,
2820 [('b', 'branch', '', _('checkout the head of a specific branch')), 2830 [('b', 'branch', '', _('checkout the head of a specific branch')),
2821 ('', 'map-file', '', _('display using template map file')), 2831 ('', 'style', '', _('display using template map file')),
2822 ('m', 'merge', None, _('allow merging of branches')), 2832 ('m', 'merge', None, _('allow merging of branches')),
2823 ('C', 'clean', None, _('overwrite locally modified files')), 2833 ('C', 'clean', None, _('overwrite locally modified files')),
2824 ('f', 'force', None, _('force a merge with outstanding changes')), 2834 ('f', 'force', None, _('force a merge with outstanding changes')),
2825 ('t', 'template', '', _('display with template'))], 2835 ('', 'template', '', _('display with template'))],
2826 _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), 2836 _('hg update [-b TAG] [-m] [-C] [-f] [REV]')),
2827 "verify": (verify, [], _('hg verify')), 2837 "verify": (verify, [], _('hg verify')),
2828 "version": (show_version, [], _('hg version')), 2838 "version": (show_version, [], _('hg version')),
2829 } 2839 }
2830 2840