Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revlog.py @ 38890:781b2720d2ac
index: don't include nullid in len()
I suspect the reason the nullid is in the index in the last position
is that it lets index[i] for regular revision number, even when index
was just a regular Python list. An alternative solution would have
been to reserve revision number 0 for the null revision. I don't know
why that wasn't done. Now that we have classes backing the index, we
can easily make index[-1] get the nullid without having to put it last
in the list and including it in the len().
This patch just hides the nullid -- it will still be accessible at
index[len(index)].
I realize that this will be annoying when checking out across this
commit for debugging (including bisection).
Differential Revision: https://phab.mercurial-scm.org/D4022
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 20 Jul 2018 08:10:32 -0700 |
parents | 6104b203bec8 |
children | a3dacabd476b |
line wrap: on
line diff
--- a/mercurial/revlog.py Wed Aug 01 10:57:14 2018 -0700 +++ b/mercurial/revlog.py Fri Jul 20 08:10:32 2018 -0700 @@ -791,10 +791,8 @@ indexformatv0_unpack = indexformatv0.unpack class revlogoldindex(list): - def __len__(self): - return list.__len__(self) + 1 def __getitem__(self, i): - if i == -1 or i == len(self) - 1: + if i == -1 or i == len(self): return (0, 0, 0, -1, -1, -1, -1, nullid) return list.__getitem__(self, i) @@ -1066,11 +1064,11 @@ yield fp def tip(self): - return self.node(len(self.index) - 2) + return self.node(len(self.index) - 1) def __contains__(self, rev): return 0 <= rev < len(self) def __len__(self): - return len(self.index) - 1 + return len(self.index) def __iter__(self): return iter(pycompat.xrange(len(self))) def revs(self, start=0, stop=None): @@ -1139,7 +1137,7 @@ i = self.index p = self._nodepos if p is None: - p = len(i) - 2 + p = len(i) - 1 else: assert p < len(i) for r in pycompat.xrange(p, -1, -1):