# HG changeset patch # User Yuya Nishihara # Date 1535975813 -32400 # Node ID aa647457df14c3e219dbe7af70bdc407b5691dba # Parent 2fb88fa2b33718439d7fb345bd80285a5b7b4598 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 -r 2fb88fa2b337 -r aa647457df14 hgext/journal.py --- 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] diff -r 2fb88fa2b337 -r aa647457df14 tests/test-journal.t --- 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