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.
--- a/mercurial/commands.py Wed Sep 30 21:22:31 2015 -0700
+++ b/mercurial/commands.py Fri Oct 02 13:00:47 2015 -0700
@@ -2476,6 +2476,71 @@
'''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'''
--- a/tests/test-backout.t Wed Sep 30 21:22:31 2015 -0700
+++ b/tests/test-backout.t Fri Oct 02 13:00:47 2015 -0700
@@ -593,6 +593,23 @@
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
--- a/tests/test-completion.t Wed Sep 30 21:22:31 2015 -0700
+++ b/tests/test-completion.t Fri Oct 02 13:00:47 2015 -0700
@@ -91,6 +91,7 @@
debugknown
debuglabelcomplete
debuglocks
+ debugmergestate
debugnamecomplete
debugobsolete
debugpathcomplete
@@ -251,6 +252,7 @@
debugknown:
debuglabelcomplete:
debuglocks: force-lock, force-wlock
+ debugmergestate:
debugnamecomplete:
debugobsolete: flags, record-parents, rev, date, user
debugpathcomplete: full, normal, added, removed
--- a/tests/test-help.t Wed Sep 30 21:22:31 2015 -0700
+++ b/tests/test-help.t Fri Oct 02 13:00:47 2015 -0700
@@ -810,6 +810,8 @@
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