# HG changeset patch # User mpm@selenic.com # Date 1119682299 28800 # Node ID 6409d9a0df43abaa69c34b35d460b89407cf2f64 # Parent 7c1952b296568a6ea330e6ef12509c3482fe98ca add dirstate debugging commands -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 add dirstate debugging commands As I've played with various different merges and more recently rawcommit, I've found the following patch to be very very helpful in figuring out whether the dirstate is being left in a consistent or inconsistent state with respect to the current manifest. I attempted to deduce the invariants that were assumed by the current code, and then check it in this code. I may or may not have captured the design intent in this check; if not, I'd be very happy to hear more clearly what was intended, so that I can write tests to that expectation. Anyway, here's the patch. Not sure if it's a good idea to commit it to the mainline, or just leave it as a debugging aid. I attempted to package it so that it doesn't interfere with normal usage. Michael Fetterman (tweaked by mpm: remove -d magic) manifest hash: 869f5b5f954dc0f46ba27322359e811d5e21d71c -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCvP77ywK+sNU5EO8RArmtAKCCVuI2slANzWZ26P5edtH/ixdwNwCfZLWl 5P+V+C92II3usO4YW2MULKY= =/Pv4 -----END PGP SIGNATURE----- diff -r 7c1952b29656 -r 6409d9a0df43 mercurial/commands.py --- a/mercurial/commands.py Fri Jun 24 22:44:51 2005 -0800 +++ b/mercurial/commands.py Fri Jun 24 22:51:39 2005 -0800 @@ -275,6 +275,43 @@ """mark a file as copied or renamed for the next commit""" return repo.copy(*relpath(repo, (source, dest))) +def debugcheckdirstate(ui, repo): + parent1, parent2 = repo.dirstate.parents() + dc = repo.dirstate.dup() + keys = dc.keys() + keys.sort() + m1n = repo.changelog.read(parent1)[0] + m2n = repo.changelog.read(parent2)[0] + m1 = repo.manifest.read(m1n) + m2 = repo.manifest.read(m2n) + errors = 0 + for f in dc: + state = repo.dirstate.state(f) + if state in "nr" and f not in m1: + print "%s in state %s, but not listed in manifest1" % (f, state) + errors += 1 + if state in "a" and f in m1: + print "%s in state %s, but also listed in manifest1" % (f, state) + errors += 1 + if state in "m" and f not in m1 and f not in m2: + print "%s in state %s, but not listed in either manifest" % (f, state) + errors += 1 + for f in m1: + state = repo.dirstate.state(f) + if state not in "nrm": + print "%s in manifest1, but listed as state %s" % (f, state) + errors += 1 + if errors: + print ".hg/dirstate inconsistent with current parent's manifest, aborting" + sys.exit(1) + +def debugdumpdirstate(ui, repo): + dc = repo.dirstate.dup() + keys = dc.keys() + keys.sort() + for file in keys: + print "%s => %c" % (file, dc[file][0]) + def debugindex(ui, file): r = hg.revlog(hg.opener(""), file, "") print " rev offset length base linkrev"+\ @@ -677,6 +714,8 @@ ('u', 'user', "", 'user')], 'hg commit [files]'), "copy": (copy, [], 'hg copy '), + "debugcheckdirstate": (debugcheckdirstate, [], 'debugcheckdirstate'), + "debugdumpdirstate": (debugdumpdirstate, [], 'debugdumpdirstate'), "debugindex": (debugindex, [], 'debugindex '), "debugindexdot": (debugindexdot, [], 'debugindexdot '), "diff": (diff, [('r', 'rev', [], 'revision')],