diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -2060,6 +2060,62 @@ printrecords(2) +@command(b'debugmergestatetemplated', [] + cmdutil.templateopts, b'') +def debugmergestatetemplated(ui, repo, *args, **opts): + """templated output about the merge state + + This command requires a template (such as '-T json'). + """ + + opts = pycompat.byteskwargs(opts) + if not opts[b'template']: + raise error.Abort(_(b'template required')) + + ms = mergemod.mergestate.read(repo) + if not ms.active(): + return + + fm = ui.formatter(b'debugmergestatetemplated', opts) + fm.startitem() + + fm_commits = fm.nested(b'commits') + for name, node, label_index in ( + (b'local', ms.local, 0), + (b'other', ms.other, 1), + ): + fm_commits.startitem() + fm_commits.data(name=name) + fm_commits.data(node=hex(node)) + if ms._labels and len(ms._labels) > label_index: + fm_commits.data(label=ms._labels[label_index]) + fm_commits.end() + + fm_files = fm.nested(b'files') + for f in ms: + fm_files.startitem() + fm_files.data(name=f) + state = ms._state[f] + fm_files.data(state=state[0]) + if state[0] == mergemod.MERGE_RECORD_UNRESOLVED: + fm_files.data(local_key=state[1]) + fm_files.data(local_path=state[2]) + fm_files.data(ancestor_path=state[3]) + fm_files.data(ancestor_node=state[4]) + fm_files.data(other_path=state[5]) + fm_files.data(other_node=state[6]) + fm_files.data(local_flags=state[7]) + fm_extras = fm_files.nested(b'extras') + for k, v in ms.extras(f).items(): + fm_extras.startitem() + fm_extras.data(key=k) + fm_extras.data(value=v) + fm_extras.end() + + fm_files.end() + + fm.end() + + @command(b'debugnamecomplete', [], _(b'NAME...')) def debugnamecomplete(ui, repo, *args): '''complete "names" - tags, open branch names, bookmark names''' diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -106,6 +106,7 @@ debuglocks debugmanifestfulltextcache debugmergestate + debugmergestatetemplated debugnamecomplete debugnodemap debugobsolete @@ -290,6 +291,7 @@ debuglocks: force-lock, force-wlock, set-lock, set-wlock debugmanifestfulltextcache: clear, add debugmergestate: + debugmergestatetemplated: style, template debugnamecomplete: debugnodemap: dump-new, dump-disk, check, metadata debugobsolete: flags, record-parents, rev, exclusive, index, delete, date, user, template diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -1022,6 +1022,8 @@ cache debugmergestate print merge state + debugmergestatetemplated + templated output about the merge state debugnamecomplete complete "names" - tags, open branch names, bookmark names debugnodemap write and inspect on disk nodemap diff --git a/tests/test-resolve.t b/tests/test-resolve.t --- a/tests/test-resolve.t +++ b/tests/test-resolve.t @@ -327,6 +327,20 @@ R file1 U file2 +test debugmergestatetemplate + + $ hg debugmergestatetemplated + abort: template required + [255] + $ hg debugmergestatetemplated -T json + [ + { + "commits": [{"label": "working copy", "name": "local", "node": "57653b9f834a4493f7240b0681efcb9ae7cab745"}, {"label": "merge rev", "name": "other", "node": "dc77451844e37f03f5c559e3b8529b2b48d381d1"}], + "files": [{"extras": [{"key": "ancestorlinknode", "value": "99726c03216e233810a2564cbc0adfe395007eac"}], "name": "file1", "state": "r"}, {"ancestor_node": "2ed2a3912a0b24502043eae84ee4b279c18b90dd", "ancestor_path": "file2", "extras": [{"key": "ancestorlinknode", "value": "99726c03216e233810a2564cbc0adfe395007eac"}], "local_flags": "", "local_key": "cb99b709a1978bd205ab9dfd4c5aaa1fc91c7523", "local_path": "file2", "name": "file2", "other_node": "6f4310b00b9a147241b071a60c28a650827fb03d", "other_path": "file2", "state": "u"}] + } + ] + + insert unsupported mandatory merge record $ hg --config extensions.fakemergerecord=$TESTDIR/fakemergerecord.py fakemergerecord -X