[PATCH 4 of 5] journal: use changesetformatter to properly nest list of commits in JSON
Yuya Nishihara
yuya at tcha.org
Fri Sep 14 21:54:08 EDT 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1535975813 -32400
# Mon Sep 03 20:56:53 2018 +0900
# Node ID 4a7c11cb2443577c7571daf93430d7e08599009c
# Parent 927a315f7c8e3a0db390488018a3b3b2c47f3d83
journal: use changesetformatter to properly nest list of commits in JSON
Before, two separate JSON documents were interleaved.
I chose the field name "changesets" over the option name "commits", since
each entry is called a "changeset" in log templates.
diff --git a/hgext/journal.py b/hgext/journal.py
--- a/hgext/journal.py
+++ b/hgext/journal.py
@@ -508,7 +508,11 @@ def journal(ui, repo, *args, **opts):
fm.write('command', ' %s\n', entry.command)
if opts.get("commits"):
- displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
+ if fm.isplain():
+ displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
+ else:
+ displayer = logcmdutil.changesetformatter(
+ ui, repo, fm.nested('changesets'), diffopts=opts)
for hash in entry.newhashes:
try:
ctx = repo[hash]
diff --git a/tests/test-journal.t b/tests/test-journal.t
--- a/tests/test-journal.t
+++ b/tests/test-journal.t
@@ -231,6 +231,62 @@ Test that verbose, JSON, template and co
summary: a
+ $ hg journal --commit -Tjson
+ [
+ {
+ "changesets": [{"bookmarks": ["bar", "baz"], "branch": "default", "date": [0, 0], "desc": "b", "node": "1e6c11564562b4ed919baca798bc4338bd299d6a", "parents": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"], "phase": "draft", "rev": 1, "tags": ["tip"], "user": "test"}],
+ "command": "up",
+ "date": [5, 0],
+ "name": ".",
+ "newnodes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
+ "oldnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
+ "user": "foobar"
+ },
+ {
+ "changesets": [{"bookmarks": [], "branch": "default", "date": [0, 0], "desc": "a", "node": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b", "parents": ["0000000000000000000000000000000000000000"], "phase": "draft", "rev": 0, "tags": [], "user": "test"}],
+ "command": "up 0",
+ "date": [2, 0],
+ "name": ".",
+ "newnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
+ "oldnodes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
+ "user": "foobar"
+ },
+ {
+ "changesets": [{"bookmarks": ["bar", "baz"], "branch": "default", "date": [0, 0], "desc": "b", "node": "1e6c11564562b4ed919baca798bc4338bd299d6a", "parents": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"], "phase": "draft", "rev": 1, "tags": ["tip"], "user": "test"}],
+ "command": "commit -Aqm b",
+ "date": [1, 0],
+ "name": ".",
+ "newnodes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
+ "oldnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
+ "user": "foobar"
+ },
+ {
+ "changesets": [{"bookmarks": [], "branch": "default", "date": [0, 0], "desc": "a", "node": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b", "parents": ["0000000000000000000000000000000000000000"], "phase": "draft", "rev": 0, "tags": [], "user": "test"}],
+ "command": "commit -Aqm a",
+ "date": [0, 0],
+ "name": ".",
+ "newnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
+ "oldnodes": ["0000000000000000000000000000000000000000"],
+ "user": "foobar"
+ }
+ ]
+
+ $ hg journal --commit \
+ > -T'command: {command}\n{changesets % " rev: {rev}\n children: {children}\n"}'
+ previous locations of '.':
+ command: up
+ rev: 1
+ children:
+ command: up 0
+ rev: 0
+ children:
+ command: commit -Aqm b
+ rev: 1
+ children:
+ command: commit -Aqm a
+ rev: 0
+ children:
+
Test for behaviour on unexpected storage version information
$ printf '42\0' > .hg/namejournal
More information about the Mercurial-devel
mailing list