changeset 460:6409d9a0df43

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-----
author mpm@selenic.com
date Fri, 24 Jun 2005 22:51:39 -0800
parents 7c1952b29656
children 9ae0034f2772
files mercurial/commands.py
diffstat 1 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 <source> <dest>'),
+    "debugcheckdirstate": (debugcheckdirstate, [], 'debugcheckdirstate'),
+    "debugdumpdirstate": (debugdumpdirstate, [], 'debugdumpdirstate'),
     "debugindex": (debugindex, [], 'debugindex <file>'),
     "debugindexdot": (debugindexdot, [], 'debugindexdot <file>'),
     "diff": (diff, [('r', 'rev', [], 'revision')],