Mercurial > hg
changeset 39704:aa647457df14
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 03 Sep 2018 20:56:53 +0900 |
parents | 2fb88fa2b337 |
children | fa681452b249 |
files | hgext/journal.py tests/test-journal.t |
diffstat | 2 files changed, 61 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/journal.py Mon Sep 03 07:53:50 2018 +0900 +++ b/hgext/journal.py Mon Sep 03 20:56:53 2018 +0900 @@ -508,7 +508,11 @@ 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]
--- a/tests/test-journal.t Mon Sep 03 07:53:50 2018 +0900 +++ b/tests/test-journal.t Mon Sep 03 20:56:53 2018 +0900 @@ -231,6 +231,62 @@ 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