comparison mercurial/commands.py @ 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 a1e91c24dab5
children 9ae0034f2772
comparison
equal deleted inserted replaced
459:7c1952b29656 460:6409d9a0df43
273 273
274 def copy(ui, repo, source, dest): 274 def copy(ui, repo, source, dest):
275 """mark a file as copied or renamed for the next commit""" 275 """mark a file as copied or renamed for the next commit"""
276 return repo.copy(*relpath(repo, (source, dest))) 276 return repo.copy(*relpath(repo, (source, dest)))
277 277
278 def debugcheckdirstate(ui, repo):
279 parent1, parent2 = repo.dirstate.parents()
280 dc = repo.dirstate.dup()
281 keys = dc.keys()
282 keys.sort()
283 m1n = repo.changelog.read(parent1)[0]
284 m2n = repo.changelog.read(parent2)[0]
285 m1 = repo.manifest.read(m1n)
286 m2 = repo.manifest.read(m2n)
287 errors = 0
288 for f in dc:
289 state = repo.dirstate.state(f)
290 if state in "nr" and f not in m1:
291 print "%s in state %s, but not listed in manifest1" % (f, state)
292 errors += 1
293 if state in "a" and f in m1:
294 print "%s in state %s, but also listed in manifest1" % (f, state)
295 errors += 1
296 if state in "m" and f not in m1 and f not in m2:
297 print "%s in state %s, but not listed in either manifest" % (f, state)
298 errors += 1
299 for f in m1:
300 state = repo.dirstate.state(f)
301 if state not in "nrm":
302 print "%s in manifest1, but listed as state %s" % (f, state)
303 errors += 1
304 if errors:
305 print ".hg/dirstate inconsistent with current parent's manifest, aborting"
306 sys.exit(1)
307
308 def debugdumpdirstate(ui, repo):
309 dc = repo.dirstate.dup()
310 keys = dc.keys()
311 keys.sort()
312 for file in keys:
313 print "%s => %c" % (file, dc[file][0])
314
278 def debugindex(ui, file): 315 def debugindex(ui, file):
279 r = hg.revlog(hg.opener(""), file, "") 316 r = hg.revlog(hg.opener(""), file, "")
280 print " rev offset length base linkrev"+\ 317 print " rev offset length base linkrev"+\
281 " p1 p2 nodeid" 318 " p1 p2 nodeid"
282 for i in range(r.count()): 319 for i in range(r.count()):
675 ('l', 'logfile', "", 'commit text file'), 712 ('l', 'logfile', "", 'commit text file'),
676 ('d', 'date', "", 'data'), 713 ('d', 'date', "", 'data'),
677 ('u', 'user', "", 'user')], 714 ('u', 'user', "", 'user')],
678 'hg commit [files]'), 715 'hg commit [files]'),
679 "copy": (copy, [], 'hg copy <source> <dest>'), 716 "copy": (copy, [], 'hg copy <source> <dest>'),
717 "debugcheckdirstate": (debugcheckdirstate, [], 'debugcheckdirstate'),
718 "debugdumpdirstate": (debugdumpdirstate, [], 'debugdumpdirstate'),
680 "debugindex": (debugindex, [], 'debugindex <file>'), 719 "debugindex": (debugindex, [], 'debugindex <file>'),
681 "debugindexdot": (debugindexdot, [], 'debugindexdot <file>'), 720 "debugindexdot": (debugindexdot, [], 'debugindexdot <file>'),
682 "diff": (diff, [('r', 'rev', [], 'revision')], 721 "diff": (diff, [('r', 'rev', [], 'revision')],
683 'hg diff [-r A] [-r B] [files]'), 722 'hg diff [-r A] [-r B] [files]'),
684 "export": (export, [], "hg export <changeset>"), 723 "export": (export, [], "hg export <changeset>"),