[patch][0.15] better DirState._validate
John Arbash Meinel
john at arbash-meinel.com
Mon Mar 26 16:49:47 BST 2007
Martin Pool wrote:
> Following on from John's move_children_correctly here is a patch that:
Thanks. I'm sorry that I didn't get a chance to catch all the other edge
cases before I submitted it. (I can only blame it being 7pm on a Friday)
> * updates DirState._validate to be more correct
> * adds some tests for different types of incorrectness that we can detect
> * changes assertRaisess to return the exception object, so that we
> can examine it
> * moves some test-creation code into the test_dirstate base class so
> that it can be used by more tests
> Since John's fix needs to be merged for 0.15 but it's validation
> changes I want to put this in for the rc3, but review would be very
v- I think having a check that all entries are the right width (number
of columns) is reasonable. In case anyone starts poking at _dirblocks
directly. Since they are lists, there is no strong constraint, but they
do have a very specific form.
> + # TODO: All entries must have some content that's not 'a' or 'r',
> + # otherwise it could just be removed.
> + #
> + # TODO: All relocations must point directly to a real entry.
> + #
> + # TODO: No repeated keys.
> + #
> + # -- mbp 20070325
> from pprint import pformat
> - # TODO: All entries should have the same length?
> + self._read_dirblocks_if_needed()
> if len(self._dirblocks) > 0:
> assert self._dirblocks == '', \
> "dirblocks don't start with root block:\n" + \
> @@ -2191,57 +2199,67 @@
> for dirblock in self._dirblocks:
v- You say 'accumulate' but you don't seem to be doing it. Is it a
change you later removed?
> # within each dirblock, the entries are sorted by filename and
> - # then by id.
> + # then by id. also accumulate all ids in the dirstate for later
> + # use.
> + for entry in dirblock:
> + assert dirblock == entry, \
> + "entry key for %r doesn't match directory name in\n%r" % \
> + (entry, pformat(dirblock))
> assert dirblock == sorted(dirblock), \
> "dirblock for %r is not sorted:\n%s" % \
> (dirblock, pformat(dirblock))
More information about the bazaar