Commit a82d59d1 authored by Martin von Zweigbergk's avatar Martin von Zweigbergk
Browse files

config: add a new [command-templates] section for templates defined by hg

The existing `[templates]` section lets the user define their own keys
and then refer to them on the command line with `-T`. There are many
cases where hg wants to use a user-defined template with a given name,
such as `ui.logtemplate` and `ui.mergemarkertemplate`. This patch
starts moving such configs in a common section by moving
`ui.logtemplate` to `command-templates.log` (with an alias from the
old name, of course).

Differential Revision: https://phab.mercurial-scm.org/D9245
parent 79d681753c4d
...@@ -4566,7 +4566,7 @@ def log(ui, repo, *pats, **opts): ...@@ -4566,7 +4566,7 @@ def log(ui, repo, *pats, **opts):
See :hg:`help templates` for more about pre-packaged styles and See :hg:`help templates` for more about pre-packaged styles and
specifying custom templates. The default template used by the log specifying custom templates. The default template used by the log
command can be customized via the ``ui.logtemplate`` configuration command can be customized via the ``command-templates.log`` configuration
setting. setting.
Returns 0 on success. Returns 0 on success.
......
...@@ -223,6 +223,9 @@ coreconfigitem( ...@@ -223,6 +223,9 @@ coreconfigitem(
coreconfigitem( coreconfigitem(
b'color', b'pagermode', default=dynamicdefault, b'color', b'pagermode', default=dynamicdefault,
) )
coreconfigitem(
b'command-templates', b'log', default=None, alias=[(b'ui', b'logtemplate')],
)
_registerdiffopts(section=b'commands', configprefix=b'commit.interactive.') _registerdiffopts(section=b'commands', configprefix=b'commit.interactive.')
coreconfigitem( coreconfigitem(
b'commands', b'commit.post-status', default=False, b'commands', b'commit.post-status', default=False,
...@@ -1305,9 +1308,6 @@ coreconfigitem( ...@@ -1305,9 +1308,6 @@ coreconfigitem(
coreconfigitem( coreconfigitem(
b'ui', b'logblockedtimes', default=False, b'ui', b'logblockedtimes', default=False,
) )
coreconfigitem(
b'ui', b'logtemplate', default=None,
)
coreconfigitem( coreconfigitem(
b'ui', b'merge', default=None, b'ui', b'merge', default=None,
) )
......
...@@ -2363,7 +2363,7 @@ User interface controls. ...@@ -2363,7 +2363,7 @@ User interface controls.
(default: 10000000) (default: 10000000)
``logtemplate`` ``logtemplate``
Template string for commands that print changesets. (DEPRECATED) Use ``command-templates.log`` instead.
``merge`` ``merge``
The conflict resolution program to use during a manual merge. The conflict resolution program to use during a manual merge.
...@@ -2561,6 +2561,15 @@ User interface controls. ...@@ -2561,6 +2561,15 @@ User interface controls.
Increase the amount of output printed. (default: False) Increase the amount of output printed. (default: False)
``command-templates``
---------------------
Templates used for customizing the output of commands.
``log``
Template string for commands that print changesets.
``web`` ``web``
------- -------
......
...@@ -623,7 +623,7 @@ def _lookuptemplate(ui, tmpl, style): ...@@ -623,7 +623,7 @@ def _lookuptemplate(ui, tmpl, style):
# ui settings # ui settings
if not tmpl and not style: # template are stronger than style if not tmpl and not style: # template are stronger than style
tmpl = ui.config(b'ui', b'logtemplate') tmpl = ui.config(b'command-templates', b'log')
if tmpl: if tmpl:
return formatter.literal_templatespec(templater.unquotestring(tmpl)) return formatter.literal_templatespec(templater.unquotestring(tmpl))
else: else:
...@@ -656,7 +656,7 @@ def changesetdisplayer(ui, repo, opts, differ=None, buffered=False): ...@@ -656,7 +656,7 @@ def changesetdisplayer(ui, repo, opts, differ=None, buffered=False):
Display format will be the first non-empty hit of: Display format will be the first non-empty hit of:
1. option 'template' 1. option 'template'
2. option 'style' 2. option 'style'
3. [ui] setting 'logtemplate' 3. [command-templates] setting 'log'
4. [ui] setting 'style' 4. [ui] setting 'style'
If all of these values are either the unset or the empty string, If all of these values are either the unset or the empty string,
regular display via changesetprinter() is done. regular display via changesetprinter() is done.
......
...@@ -507,6 +507,8 @@ class ui(object): ...@@ -507,6 +507,8 @@ class ui(object):
del cfg[b'defaults'][k] del cfg[b'defaults'][k]
for k, v in cfg.items(b'commands'): for k, v in cfg.items(b'commands'):
del cfg[b'commands'][k] del cfg[b'commands'][k]
for k, v in cfg.items(b'command-templates'):
del cfg[b'command-templates'][k]
# Don't remove aliases from the configuration if in the exceptionlist # Don't remove aliases from the configuration if in the exceptionlist
if self.plain(b'alias'): if self.plain(b'alias'):
for k, v in cfg.items(b'alias'): for k, v in cfg.items(b'alias'):
......
...@@ -403,10 +403,10 @@ Test update-timestamp config option| ...@@ -403,10 +403,10 @@ Test update-timestamp config option|
$ hg init $TESTTMP/repo5 $ hg init $TESTTMP/repo5
$ cd $TESTTMP/repo5 $ cd $TESTTMP/repo5
$ cat <<'EOF' >> .hg/hgrc $ cat <<'EOF' >> .hg/hgrc
> [ui] > [command-templates]
> logtemplate = 'user: {user} > log = 'user: {user}
> date: {date|date} > date: {date|date}
> summary: {desc|firstline}\n' > summary: {desc|firstline}\n'
> EOF > EOF
$ echo a>a $ echo a>a
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#require serve #require serve
$ cat << EOF >> $HGRCPATH $ cat << EOF >> $HGRCPATH
> [ui] > [command-templates]
> logtemplate={rev}:{node|short} {desc|firstline} > log={rev}:{node|short} {desc|firstline}
> [phases] > [phases]
> publish=False > publish=False
> [experimental] > [experimental]
......
...@@ -30,7 +30,8 @@ enable obsolescence ...@@ -30,7 +30,8 @@ enable obsolescence
> bundle2-output-capture=True > bundle2-output-capture=True
> [ui] > [ui]
> ssh="$PYTHON" "$TESTDIR/dummyssh" > ssh="$PYTHON" "$TESTDIR/dummyssh"
> logtemplate={rev}:{node|short} {phase} {author} {bookmarks} {desc|firstline} > [command-templates]
> log={rev}:{node|short} {phase} {author} {bookmarks} {desc|firstline}
> [web] > [web]
> push_ssl = false > push_ssl = false
> allow_push = * > allow_push = *
......
...@@ -235,7 +235,8 @@ Create an extension to test bundle2 API ...@@ -235,7 +235,8 @@ Create an extension to test bundle2 API
> evolution.createmarkers=True > evolution.createmarkers=True
> [ui] > [ui]
> ssh="$PYTHON" "$TESTDIR/dummyssh" > ssh="$PYTHON" "$TESTDIR/dummyssh"
> logtemplate={rev}:{node|short} {phase} {author} {bookmarks} {desc|firstline} > [command-templates]
> log={rev}:{node|short} {phase} {author} {bookmarks} {desc|firstline}
> [web] > [web]
> push_ssl = false > push_ssl = false
> allow_push = * > allow_push = *
......
...@@ -34,8 +34,8 @@ Create an extension to test bundle2 with multiple changegroups ...@@ -34,8 +34,8 @@ Create an extension to test bundle2 with multiple changegroups
> EOF > EOF
$ cat >> $HGRCPATH << EOF $ cat >> $HGRCPATH << EOF
> [ui] > [command-templates]
> logtemplate={rev}:{node|short} {phase} {author} {bookmarks} {desc|firstline} > log={rev}:{node|short} {phase} {author} {bookmarks} {desc|firstline}
> EOF > EOF
Start with a simple repository with a single commit Start with a simple repository with a single commit
......
...@@ -96,7 +96,8 @@ Start a simple HTTP server to serve bundles ...@@ -96,7 +96,8 @@ Start a simple HTTP server to serve bundles
$ cat >> $HGRCPATH << EOF $ cat >> $HGRCPATH << EOF
> [ui] > [ui]
> ssh="$PYTHON" "$TESTDIR/dummyssh" > ssh="$PYTHON" "$TESTDIR/dummyssh"
> logtemplate={rev}:{node|short} {phase} {author} {bookmarks} {desc|firstline} > [command-templates]
> log={rev}:{node|short} {phase} {author} {bookmarks} {desc|firstline}
> EOF > EOF
$ hg init repo $ hg init repo
......
...@@ -982,8 +982,8 @@ cases. ...@@ -982,8 +982,8 @@ cases.
$ cd repo3 $ cd repo3
$ cat <<EOF >> $HGRCPATH $ cat <<EOF >> $HGRCPATH
> [ui] > [command-templates]
> logtemplate = {rev} {desc|firstline} ({files})\n > log = {rev} {desc|firstline} ({files})\n
> >
> [extensions] > [extensions]
> failafterfinalize = $TESTTMP/failafterfinalize.py > failafterfinalize = $TESTTMP/failafterfinalize.py
......
...@@ -17,8 +17,8 @@ use git diff to see rename ...@@ -17,8 +17,8 @@ use git diff to see rename
$ cat << EOF >> $HGRCPATH $ cat << EOF >> $HGRCPATH
> [diff] > [diff]
> git=yes > git=yes
> [ui] > [command-templates]
> logtemplate={rev} {desc}\n > log={rev} {desc}\n
> EOF > EOF
#if compatibility #if compatibility
......
$ cat >> $HGRCPATH << EOF $ cat >> $HGRCPATH << EOF
> [ui] > [command-templates]
> logtemplate="{rev}:{node|short} ({phase}) [{tags} {bookmarks}] {desc|firstline}\n" > log="{rev}:{node|short} ({phase}) [{tags} {bookmarks}] {desc|firstline}\n"
> [extensions] > [extensions]
> dirstateparanoidcheck = $TESTDIR/../contrib/dirstatenonnormalcheck.py > dirstateparanoidcheck = $TESTDIR/../contrib/dirstatenonnormalcheck.py
> [experimental] > [experimental]
......
...@@ -3084,8 +3084,8 @@ Multiple roots (issue5440): ...@@ -3084,8 +3084,8 @@ Multiple roots (issue5440):
$ hg init multiroots $ hg init multiroots
$ cd multiroots $ cd multiroots
$ cat <<EOF > .hg/hgrc $ cat <<EOF > .hg/hgrc
> [ui] > [command-templates]
> logtemplate = '{rev} {desc}\n\n' > log = '{rev} {desc}\n\n'
> EOF > EOF
$ touch foo $ touch foo
......
This test file aims at test topological iteration and the various configuration it can has. This test file aims at test topological iteration and the various configuration it can has.
$ cat >> $HGRCPATH << EOF $ cat >> $HGRCPATH << EOF
> [ui] > [command-templates]
> logtemplate={rev}\n > log={rev}\n
> EOF > EOF
On this simple example, all topological branch are displayed in turn until we On this simple example, all topological branch are displayed in turn until we
......
...@@ -3420,8 +3420,8 @@ Multiple roots (issue5440): ...@@ -3420,8 +3420,8 @@ Multiple roots (issue5440):
$ hg init multiroots $ hg init multiroots
$ cd multiroots $ cd multiroots
$ cat <<EOF > .hg/hgrc $ cat <<EOF > .hg/hgrc
> [ui] > [command-templates]
> logtemplate = '{rev} {desc}\n\n' > log = '{rev} {desc}\n\n'
> EOF > EOF
$ touch foo $ touch foo
......
...@@ -851,8 +851,8 @@ unmodified changes. ...@@ -851,8 +851,8 @@ unmodified changes.
$ cd follow $ cd follow
$ cat <<'EOF' >> .hg/hgrc $ cat <<'EOF' >> .hg/hgrc
> [ui] > [command-templates]
> logtemplate = '{rev}: {join(files % "{status} {path}", ", ")}\n' > log = '{rev}: {join(files % "{status} {path}", ", ")}\n'
> EOF > EOF
$ for f in add0 add0-mod1 add0-rm1 add0-mod2 add0-rm2 add0-mod3 add0-mod4 add0-rm4; do $ for f in add0 add0-mod1 add0-rm1 add0-mod2 add0-rm2 add0-mod3 add0-mod4 add0-rm4; do
......
...@@ -293,8 +293,8 @@ Check that histedit respect immutability ...@@ -293,8 +293,8 @@ Check that histedit respect immutability
------------------------------------------- -------------------------------------------
$ cat >> $HGRCPATH << EOF $ cat >> $HGRCPATH << EOF
> [ui] > [command-templates]
> logtemplate= {rev}:{node|short} ({phase}) {desc|firstline}\n > log = {rev}:{node|short} ({phase}) {desc|firstline}\n
> EOF > EOF
$ hg ph -pv '.^' $ hg ph -pv '.^'
......
...@@ -450,6 +450,16 @@ log -vf dir/b ...@@ -450,6 +450,16 @@ log -vf dir/b
a a
Respects ui.logtemplate and command-templates.log configs (the latter takes
precedence)
$ hg log -r 0 --config ui.logtemplate="foo {rev}\n"
foo 0
$ hg log -r 0 --config command-templates.log="bar {rev}\n"
bar 0
$ hg log -r 0 --config ui.logtemplate="foo {rev}\n" \
> --config command-templates.log="bar {rev}\n"
bar 0
-f and multiple filelog heads -f and multiple filelog heads
...@@ -1122,8 +1132,8 @@ log --follow --patch FILE in repository where linkrev isn't trustworthy ...@@ -1122,8 +1132,8 @@ log --follow --patch FILE in repository where linkrev isn't trustworthy
$ hg init follow-dup $ hg init follow-dup
$ cd follow-dup $ cd follow-dup
$ cat <<EOF >> .hg/hgrc $ cat <<EOF >> .hg/hgrc
> [ui] > [command-templates]
> logtemplate = '=== {rev}: {desc}\n' > log = '=== {rev}: {desc}\n'
> [diff] > [diff]
> nodates = True > nodates = True
> EOF > EOF
......
...@@ -122,7 +122,7 @@ Predecessors template should show current revision as it is the working copy ...@@ -122,7 +122,7 @@ Predecessors template should show current revision as it is the working copy
o ea207398892e o ea207398892e
$ hg log -G --config ui.logtemplate= $ hg log -G --config command-templates.log=
o changeset: 3:d004c8f274b9 o changeset: 3:d004c8f274b9
| tag: tip | tag: tip
| parent: 0:ea207398892e | parent: 0:ea207398892e
......
...@@ -9,9 +9,9 @@ Config setup ...@@ -9,9 +9,9 @@ Config setup
------------ ------------
$ cat >> $HGRCPATH <<EOF $ cat >> $HGRCPATH <<EOF
> [ui] > [command-templates]
> # simpler log output > # simpler log output
> logtemplate = "{node|short}: {desc}\n" > log = "{node|short}: {desc}\n"
> >
> [experimental] > [experimental]
> # enable evolution > # enable evolution
......
...@@ -3,8 +3,8 @@ Check that obsolete properly strip heads ...@@ -3,8 +3,8 @@ Check that obsolete properly strip heads
> [phases] > [phases]
> # public changeset are not obsolete > # public changeset are not obsolete
> publish=false > publish=false
> [ui] > [command-templates]
> logtemplate='{node|short} ({phase}) {desc|firstline}\n' > log='{node|short} ({phase}) {desc|firstline}\n'
> [experimental] > [experimental]
> evolution.createmarkers=True > evolution.createmarkers=True
> EOF > EOF
......
...@@ -16,8 +16,8 @@ to happen in the local case but can easily happen in the distributed case. ...@@ -16,8 +16,8 @@ to happen in the local case but can easily happen in the distributed case.
> evolution = all > evolution = all
> [phases] > [phases]
> publish = False > publish = False
> [ui] > [command-templates]
> logtemplate= {rev}:{node|short} {desc}{if(obsfate, " [{join(obsfate, "; ")}]")}\n > log = {rev}:{node|short} {desc}{if(obsfate, " [{join(obsfate, "; ")}]")}\n
> EOF > EOF
Check distributed chain building Check distributed chain building
......
...@@ -5,8 +5,8 @@ Test rebase with obsolete ...@@ -5,8 +5,8 @@ Test rebase with obsolete
Enable obsolete Enable obsolete
$ cat >> $HGRCPATH << EOF $ cat >> $HGRCPATH << EOF
> [ui] > [command-templates]
> logtemplate= {rev}:{node|short} {desc|firstline}{if(obsolete,' ({obsfate})')} > log= {rev}:{node|short} {desc|firstline}{if(obsolete,' ({obsfate})')}
> [experimental] > [experimental]
> evolution.createmarkers=True > evolution.createmarkers=True
> evolution.allowunstable=True > evolution.allowunstable=True
......
$ cat >> $HGRCPATH << EOF $ cat >> $HGRCPATH << EOF
> [ui] > [command-templates]
> logtemplate="{rev}:{node|short} {desc} [{tags}]\n" > log="{rev}:{node|short} {desc} [{tags}]\n"
> EOF > EOF
$ hg init legacy-lookup $ hg init legacy-lookup
......
...@@ -48,8 +48,9 @@ Second branch starting at nullrev: ...@@ -48,8 +48,9 @@ Second branch starting at nullrev:
Make sure user/global hgrc does not affect tests Make sure user/global hgrc does not affect tests
$ echo '[command-templates]' > .hg/hgrc
$ echo 'log =' >> .hg/hgrc
$ echo '[ui]' > .hg/hgrc $ echo '[ui]' > .hg/hgrc
$ echo 'logtemplate =' >> .hg/hgrc
$ echo 'style =' >> .hg/hgrc $ echo 'style =' >> .hg/hgrc
Add some simple styles to settings Add some simple styles to settings
......
...@@ -3,8 +3,8 @@ Tests discovery against servers without getbundle support: ...@@ -3,8 +3,8 @@ Tests discovery against servers without getbundle support:
$ CAP="getbundle bundle2" $ CAP="getbundle bundle2"
$ . "$TESTDIR/notcapable" $ . "$TESTDIR/notcapable"
$ cat >> $HGRCPATH <<EOF $ cat >> $HGRCPATH <<EOF
> [ui] > [command-templates]
> logtemplate="{rev} {node|short}: {desc} {branches}\n" > log="{rev} {node|short}: {desc} {branches}\n"
> EOF > EOF
Setup HTTP server control: Setup HTTP server control:
......
...@@ -14,9 +14,9 @@ cat >> $HGRCPATH <<EOF ...@@ -14,9 +14,9 @@ cat >> $HGRCPATH <<EOF
push_ssl = false push_ssl = false
allow_push = * allow_push = *
[ui] [command-templates]
# simpler log output # simpler log output
logtemplate ="{node|short} ({phase}): {desc}\n" log ="{node|short} ({phase}): {desc}\n"
[phases] [phases]
# non publishing server # non publishing server
......
# setup config and various utility to test new heads checks on push # setup config and various utility to test new heads checks on push
cat >> $HGRCPATH <<EOF cat >> $HGRCPATH <<EOF
[ui] [command-templates]
# simpler log output # simpler log output
logtemplate ="{node|short} ({phase}): {desc}\n" log ="{node|short} ({phase}): {desc}\n"
[phases] [phases]
# non publishing server # non publishing server
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment