From: David Kågedal Date: Wed, 19 Dec 2007 18:00:10 +0000 (+0000) Subject: Check bottom and invariants X-Git-Tag: v0.15-rc1~345 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/0e1c86f9ff8a81055a45c807cf1218d3ff28d986 Check bottom and invariants This code adds some checks that the bottom is actually always the parent of top. It also checks that the top is the same as what the patch ref points to. This is only to ensure that the next patches are correct. Signed-off-by: David Kågedal Signed-off-by: Karl Hasselström --- diff --git a/stgit/stack.py b/stgit/stack.py index f1f75e4..f54bec4 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -208,9 +208,15 @@ class Patch(StgitObject): self.__update_top_ref(top) def get_old_bottom(self): - return self._get_field('bottom.old') + old_bottom = self._get_field('bottom.old') + old_top = self.get_old_top() + assert old_bottom == git.get_commit(old_top).get_parent() + return old_bottom def get_bottom(self): + bottom = self._get_field('bottom') + top = self.get_top() + assert bottom == git.get_commit(top).get_parent() return self._get_field('bottom') def set_bottom(self, value, backup = False): @@ -223,7 +229,13 @@ class Patch(StgitObject): return self._get_field('top.old') def get_top(self): - return self._get_field('top') + top = self._get_field('top') + try: + ref = git.rev_parse(self.__top_ref) + except: + ref = None + assert not ref or top == ref + return top def set_top(self, value, backup = False): if backup: @@ -231,6 +243,7 @@ class Patch(StgitObject): self._set_field('top.old', curr) self._set_field('top', value) self.__update_top_ref(value) + self.get_bottom() # check the assert def restore_old_boundaries(self): bottom = self._get_field('bottom.old')