# HG changeset patch # User Siddharth Agarwal # Date 2015-10-02 20:00:47 # Node ID 0748083f28985fe4a7a539086250a0e4ad2eee22 # Parent 5bd7c4c07f6dfce82f8d29f9f9e104900a0f24e2 commands: add a new debug command to print merge state We're going to be extending the merge state very soon, and this will give us a way to test all that. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2476,6 +2476,71 @@ def debuglabelcomplete(ui, repo, *args): '''backwards compatibility with old bash completion scripts (DEPRECATED)''' debugnamecomplete(ui, repo, *args) +@command('debugmergestate', [], '') +def debugmergestate(ui, repo, *args): + """print merge state + + Use --verbose to print out information about whether v1 or v2 merge state + was chosen.""" + def printrecords(version): + ui.write(('* version %s records\n') % version) + if version == 1: + records = v1records + else: + records = v2records + + for rtype, record in records: + # pretty print some record types + if rtype == 'L': + ui.write(('local: %s\n') % record) + elif rtype == 'O': + ui.write(('other: %s\n') % record) + elif rtype == 'F': + r = record.split('\0') + f, state, hash, lfile, afile, anode, ofile = r[0:7] + if version == 1: + onode = 'not stored in v1 format' + flags = r[7] + else: + onode, flags = r[7:9] + ui.write(('file: %s (state "%s", hash %s)\n') + % (f, state, hash)) + ui.write((' local path: %s (flags "%s")\n') % (lfile, flags)) + ui.write((' ancestor path: %s (node %s)\n') % (afile, anode)) + ui.write((' other path: %s (node %s)\n') % (ofile, onode)) + else: + ui.write(('unrecognized entry: %s\t%s\n') + % (rtype, record.replace('\0', '\t'))) + + ms = mergemod.mergestate(repo) + + # sort so that reasonable information is on top + v1records = ms._readrecordsv1() + v2records = ms._readrecordsv2() + order = 'LO' + def key(r): + idx = order.find(r[0]) + if idx == -1: + return (1, r[1]) + else: + return (0, idx) + v1records.sort(key=key) + v2records.sort(key=key) + + if not v1records and not v2records: + ui.write(('no merge state found\n')) + elif not v2records: + ui.note(('no version 2 merge state\n')) + printrecords(1) + elif ms._v1v2match(v1records, v2records): + ui.note(('v1 and v2 states match: using v2\n')) + printrecords(2) + else: + ui.note(('v1 and v2 states mismatch: using v1\n')) + printrecords(1) + if ui.verbose: + printrecords(2) + @command('debugnamecomplete', [], _('NAME...')) def debugnamecomplete(ui, repo, *args): '''complete "names" - tags, open branch names, bookmark names''' diff --git a/tests/test-backout.t b/tests/test-backout.t --- a/tests/test-backout.t +++ b/tests/test-backout.t @@ -593,6 +593,23 @@ Test usage of `hg resolve` in case of co use 'hg resolve' to retry unresolved file merges [1] $ hg status + $ hg debugmergestate + * version 2 records + local: b71750c4b0fdf719734971e3ef90dbeab5919a2d + other: a30dd8addae3ce71b8667868478542bc417439e6 + file: foo (state "u", hash 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33) + local path: foo (flags "") + ancestor path: foo (node f89532f44c247a0e993d63e3a734dd781ab04708) + other path: foo (node f50039b486d6fa1a90ae51778388cad161f425ee) + $ mv .hg/merge/state2 .hg/merge/state2-moved + $ hg debugmergestate + * version 1 records + local: b71750c4b0fdf719734971e3ef90dbeab5919a2d + file: foo (state "u", hash 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33) + local path: foo (flags "") + ancestor path: foo (node f89532f44c247a0e993d63e3a734dd781ab04708) + other path: foo (node not stored in v1 format) + $ mv .hg/merge/state2-moved .hg/merge/state2 $ hg resolve -l # still unresolved U foo $ hg summary diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -91,6 +91,7 @@ Show debug commands if there are no othe debugknown debuglabelcomplete debuglocks + debugmergestate debugnamecomplete debugobsolete debugpathcomplete @@ -251,6 +252,7 @@ Show all commands + options debugknown: debuglabelcomplete: debuglocks: force-lock, force-wlock + debugmergestate: debugnamecomplete: debugobsolete: flags, record-parents, rev, date, user debugpathcomplete: full, normal, added, removed diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -810,6 +810,8 @@ Test list of internal help commands debuginstall test Mercurial installation debugknown test whether node ids are known to a repo debuglocks show or modify state of locks + debugmergestate + print merge state debugnamecomplete complete "names" - tags, open branch names, bookmark names debugobsolete