# HG changeset patch
# User Yuya Nishihara
# Date 1570388321 14400
# Sun Oct 06 14:58:41 2019 -0400
# Node ID debe9628570ddfd9728f2097eb67ea0febaffd22
# Parent 7260fcfed7308f15554bbb0ed86e5e36f1a420fd
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
To make things simple, early return for ui.quiet is disabled if the formatter
is templated and provides some datahint().
diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -440,7 +440,8 @@ class changesetformatter(changesetprinte
fm.context(ctx=ctx)
fm.data(rev=scmutil.intrev(ctx), node=fm.hexfunc(scmutil.binnode(ctx)))
-if self.ui.quiet:
+datahint = fm.datahint()
+if self.ui.quiet and not datahint:
return
fm.data(
@@ -456,12 +457,17 @@ class changesetformatter(changesetprinte
),
)
-if self.ui.debugflag:
-fm.data(
-manifest=fm.hexfunc(ctx.manifestnode() or wdirid),
-extra=fm.formatdict(ctx.extra()),
-)
+if self.ui.debugflag or b'manifest' in datahint:
+fm.data(manifest=fm.hexfunc(ctx.manifestnode() or wdirid))
+if self.ui.debugflag or b'extra' in datahint:
+fm.data(extra=fm.formatdict(ctx.extra()))
+if (
+self.ui.debugflag
+or b'modified' in datahint
+or b'added' in datahint
+or b'removed' in datahint
+):
files = ctx.p1().status(ctx)
fm.data(
modified=fm.formatlist(files[0], name=b'file'),
@@ -469,18 +475,19 @@ class changesetformatter(changesetprinte
removed=fm.formatlist(files[2], name=b'file'),
)
-elif self.ui.verbose:
+verbose = not self.ui.debugflag and self.ui.verbose
+if verbose or b'files' in datahint:
fm.data(files=fm.formatlist(ctx.files(), name=b'file'))
-if copies:
-fm.data(
-copies=fm.formatdict(copies, key=b'name', value=b'source')
-)
+if verbose and copies or b'copies' in datahint:
+fm.data(
+copies=fm.formatdict(copies or {}, key=b'name',
value=b'source')
+)
-if self._includestat:
+if self._includestat or b'diffstat' in datahint:
self.ui.pushbuffer()
self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
fm.data(diffstat=self.ui.popbuffer())
-if self._includediff:
+if self._includediff or b'diff' in datahint:
self.ui.pushbuffer()
self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
fm.data(diff=self.ui.popbuffer())
diff --git a/tests/test-template-map.t b/tests/test-template-map.t
--- a/tests/test-template-map.t
+++ b/tests/test-template-map.t
@@ -1119,6 +1119,60 @@ honor --git but not format-breaking diff
{"parents": [""], "rev": 7}
]
+ $ hg log -qr. -T'json(rev, parents)'
+ [
+ {"parents": ["29114dbae42b9f078cf2714dbe3a86bba8ec7453"], "rev": 8}
+ ]
+
+ $ hg log -r. -T'json(diff)'
+ [
+ {"diff": "diff -r 29114dbae42b -r 95c24699272e fourth\n--- /dev/null\tThu
Jan 01 00:00:00 1970 +\n+++ b/fourth\tWed Jan 01 10:01:00 2020 +\n@@
-0,0 +1,1 @@\n+second\ndiff -r 29114dbae42b -r 95c24699272e second\n---
a/second\tMon Jan 12 13:46:40 1970 +\n+++ /dev/null\tThu Jan 01 00:00:00
1970 +\n@@ -1,1 +0,0 @@\n-second\ndiff -r 29114dbae42b -r 95c24699272e
third\n--- /dev/null\tThu Jan 01 00:00:00 1970 +\n+++ b/third\tWed Jan 01
10:01:00 2020 +\n@@ -0,0 +1,1 @@\n+third\n"}
+ ]
+
+ $ hg log -r. -T'json(diffstat)'
+ [
+ {"diffstat": " fourth | 1 +\n second | 1 -\n third | 1 +\n 3 files
changed, 2 insertions(+), 1 deletions(-)\n"}
+ ]
+
+ $ hg log -r. -T'json(manifest)'
+ [
+ {"manifest": "94961b75a2da554b4df6fb599e5bfc7d48de0c64"}
+ ]
+
+ $ hg log -r. -T'json(extra)'
+ [
+ {"extra": {"branch": "default"}}
+ ]
+
+ $ hg log -r3 -T'json(modified)'
+ [
+ {"modified": ["c"]}
+ ]
+
+ $ hg log -r. -T'json(added)'
+ [
+ {"added": ["fourth", "third"]}
+ ]
+
+ $ hg log -r. -T'json(removed)'
+ [
+ {"removed": ["second"]}
+ ]
+
+ $ hg log -r. -T'json(files)'
+ [
+ {"files": ["fourth", "second", "third"]}
+ ]
+
+ --copies is the exception. copies dict is built only when --copies switch
+ is on:
+
+ $ hg log -r'.^:' -T'json(copies)' --copies
+ [
+ {"copies": {}},
+ {"copies": {"fourth": "second"}}
+ ]
+
$ hg log -r. -T'json()'
[
{}
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel