##// END OF EJS Templates
index: don't include nullid in len()...
Martin von Zweigbergk -
r39124:781b2720 default
parent child Browse files
Show More
@@ -713,7 +713,7 b' void dirs_module_init(PyObject *mod);'
713 void manifest_module_init(PyObject *mod);
713 void manifest_module_init(PyObject *mod);
714 void revlog_module_init(PyObject *mod);
714 void revlog_module_init(PyObject *mod);
715
715
716 static const int version = 6;
716 static const int version = 7;
717
717
718 static void module_init(PyObject *mod)
718 static void module_init(PyObject *mod)
719 {
719 {
@@ -77,8 +77,8 b' typedef struct {'
77 static Py_ssize_t index_length(const indexObject *self)
77 static Py_ssize_t index_length(const indexObject *self)
78 {
78 {
79 if (self->added == NULL)
79 if (self->added == NULL)
80 return self->length;
80 return self->length - 1;
81 return self->length + PyList_GET_SIZE(self->added);
81 return self->length + PyList_GET_SIZE(self->added) - 1;
82 }
82 }
83
83
84 static PyObject *nullentry;
84 static PyObject *nullentry;
@@ -155,7 +155,7 b' static PyObject *index_get(indexObject *'
155 int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2;
155 int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2;
156 const char *c_node_id;
156 const char *c_node_id;
157 const char *data;
157 const char *data;
158 Py_ssize_t length = index_length(self);
158 Py_ssize_t length = index_length(self) + 1;
159 PyObject *entry;
159 PyObject *entry;
160
160
161 if (pos == -1 || pos == length - 1) {
161 if (pos == -1 || pos == length - 1) {
@@ -225,7 +225,7 b' static PyObject *index_get(indexObject *'
225 */
225 */
226 static const char *index_node(indexObject *self, Py_ssize_t pos)
226 static const char *index_node(indexObject *self, Py_ssize_t pos)
227 {
227 {
228 Py_ssize_t length = index_length(self);
228 Py_ssize_t length = index_length(self) + 1;
229 const char *data;
229 const char *data;
230
230
231 if (pos == length - 1 || pos == -1)
231 if (pos == length - 1 || pos == -1)
@@ -285,7 +285,7 b' static PyObject *index_append(indexObjec'
285 if (node_check(PyTuple_GET_ITEM(obj, 7), &node) == -1)
285 if (node_check(PyTuple_GET_ITEM(obj, 7), &node) == -1)
286 return NULL;
286 return NULL;
287
287
288 len = index_length(self);
288 len = index_length(self) + 1;
289
289
290 if (self->added == NULL) {
290 if (self->added == NULL) {
291 self->added = PyList_New(0);
291 self->added = PyList_New(0);
@@ -435,7 +435,7 b' static Py_ssize_t add_roots_get_min(inde'
435 {
435 {
436 PyObject *iter = NULL;
436 PyObject *iter = NULL;
437 PyObject *iter_item = NULL;
437 PyObject *iter_item = NULL;
438 Py_ssize_t min_idx = index_length(self) + 1;
438 Py_ssize_t min_idx = index_length(self) + 2;
439 long iter_item_long;
439 long iter_item_long;
440
440
441 if (PyList_GET_SIZE(list) != 0) {
441 if (PyList_GET_SIZE(list) != 0) {
@@ -477,7 +477,7 b' static PyObject *reachableroots2(indexOb'
477 PyObject *reachable = NULL;
477 PyObject *reachable = NULL;
478
478
479 PyObject *val;
479 PyObject *val;
480 Py_ssize_t len = index_length(self) - 1;
480 Py_ssize_t len = index_length(self);
481 long revnum;
481 long revnum;
482 Py_ssize_t k;
482 Py_ssize_t k;
483 Py_ssize_t i;
483 Py_ssize_t i;
@@ -629,7 +629,7 b' static PyObject *compute_phases_map_sets'
629 PyObject *phaseset = NULL;
629 PyObject *phaseset = NULL;
630 PyObject *phasessetlist = NULL;
630 PyObject *phasessetlist = NULL;
631 PyObject *rev = NULL;
631 PyObject *rev = NULL;
632 Py_ssize_t len = index_length(self) - 1;
632 Py_ssize_t len = index_length(self);
633 Py_ssize_t numphase = 0;
633 Py_ssize_t numphase = 0;
634 Py_ssize_t minrevallphases = 0;
634 Py_ssize_t minrevallphases = 0;
635 Py_ssize_t minrevphase = 0;
635 Py_ssize_t minrevphase = 0;
@@ -740,7 +740,7 b' static PyObject *index_headrevs(indexObj'
740 }
740 }
741 }
741 }
742
742
743 len = index_length(self) - 1;
743 len = index_length(self);
744 heads = PyList_New(0);
744 heads = PyList_New(0);
745 if (heads == NULL)
745 if (heads == NULL)
746 goto bail;
746 goto bail;
@@ -844,7 +844,7 b' static PyObject *index_deltachain(indexO'
844 int stoprev, iterrev, baserev = -1;
844 int stoprev, iterrev, baserev = -1;
845 int stopped;
845 int stopped;
846 PyObject *chain = NULL, *result = NULL;
846 PyObject *chain = NULL, *result = NULL;
847 const Py_ssize_t length = index_length(self);
847 const Py_ssize_t length = index_length(self) + 1;
848
848
849 if (!PyArg_ParseTuple(args, "iOi", &rev, &stoparg, &generaldelta)) {
849 if (!PyArg_ParseTuple(args, "iOi", &rev, &stoparg, &generaldelta)) {
850 return NULL;
850 return NULL;
@@ -1098,7 +1098,7 b' static int nt_init(indexObject *self)'
1098 return -1;
1098 return -1;
1099 }
1099 }
1100 self->ntlength = 1;
1100 self->ntlength = 1;
1101 self->ntrev = (int)index_length(self) - 1;
1101 self->ntrev = (int)index_length(self);
1102 self->ntlookups = 1;
1102 self->ntlookups = 1;
1103 self->ntmisses = 0;
1103 self->ntmisses = 0;
1104 if (nt_insert(self, nullid, -1) == -1) {
1104 if (nt_insert(self, nullid, -1) == -1) {
@@ -1393,7 +1393,7 b' static int index_contains(indexObject *s'
1393
1393
1394 if (PyInt_Check(value)) {
1394 if (PyInt_Check(value)) {
1395 long rev = PyInt_AS_LONG(value);
1395 long rev = PyInt_AS_LONG(value);
1396 return rev >= -1 && rev < index_length(self);
1396 return rev >= -1 && rev < index_length(self) + 1;
1397 }
1397 }
1398
1398
1399 if (node_check(value, &node) == -1)
1399 if (node_check(value, &node) == -1)
@@ -1673,7 +1673,7 b' static PyObject *index_commonancestorshe'
1673 revs = PyMem_Malloc(argcount * sizeof(*revs));
1673 revs = PyMem_Malloc(argcount * sizeof(*revs));
1674 if (argcount > 0 && revs == NULL)
1674 if (argcount > 0 && revs == NULL)
1675 return PyErr_NoMemory();
1675 return PyErr_NoMemory();
1676 len = index_length(self) - 1;
1676 len = index_length(self);
1677
1677
1678 for (i = 0; i < argcount; i++) {
1678 for (i = 0; i < argcount; i++) {
1679 static const int capacity = 24;
1679 static const int capacity = 24;
@@ -1795,7 +1795,7 b' static void nt_invalidate_added(indexObj'
1795 static int index_slice_del(indexObject *self, PyObject *item)
1795 static int index_slice_del(indexObject *self, PyObject *item)
1796 {
1796 {
1797 Py_ssize_t start, stop, step, slicelength;
1797 Py_ssize_t start, stop, step, slicelength;
1798 Py_ssize_t length = index_length(self);
1798 Py_ssize_t length = index_length(self) + 1;
1799 int ret = 0;
1799 int ret = 0;
1800
1800
1801 /* Argument changed from PySliceObject* to PyObject* in Python 3. */
1801 /* Argument changed from PySliceObject* to PyObject* in Python 3. */
@@ -69,7 +69,7 b' def _importfrom(pkgname, modname):'
69 (r'cext', r'bdiff'): 3,
69 (r'cext', r'bdiff'): 3,
70 (r'cext', r'mpatch'): 1,
70 (r'cext', r'mpatch'): 1,
71 (r'cext', r'osutil'): 4,
71 (r'cext', r'osutil'): 4,
72 (r'cext', r'parsers'): 6,
72 (r'cext', r'parsers'): 7,
73 }
73 }
74
74
75 # map import request to other package or module
75 # map import request to other package or module
@@ -39,7 +39,7 b' def offset_type(offset, type):'
39
39
40 class BaseIndexObject(object):
40 class BaseIndexObject(object):
41 def __len__(self):
41 def __len__(self):
42 return self._lgt + len(self._extra) + 1
42 return self._lgt + len(self._extra)
43
43
44 def append(self, tup):
44 def append(self, tup):
45 self._extra.append(tup)
45 self._extra.append(tup)
@@ -47,12 +47,12 b' class BaseIndexObject(object):'
47 def _fix_index(self, i):
47 def _fix_index(self, i):
48 if not isinstance(i, int):
48 if not isinstance(i, int):
49 raise TypeError("expecting int indexes")
49 raise TypeError("expecting int indexes")
50 if i < 0 or i >= len(self):
50 if i < 0 or i >= len(self) + 1:
51 raise IndexError
51 raise IndexError
52 return i
52 return i
53
53
54 def __getitem__(self, i):
54 def __getitem__(self, i):
55 if i == -1 or i == len(self) - 1:
55 if i == -1 or i == len(self):
56 return (0, 0, 0, -1, -1, -1, -1, nullid)
56 return (0, 0, 0, -1, -1, -1, -1, nullid)
57 i = self._fix_index(i)
57 i = self._fix_index(i)
58 if i >= self._lgt:
58 if i >= self._lgt:
@@ -210,7 +210,7 b' class repoview(object):'
210 unfichangelog = unfi.changelog
210 unfichangelog = unfi.changelog
211 # bypass call to changelog.method
211 # bypass call to changelog.method
212 unfiindex = unfichangelog.index
212 unfiindex = unfichangelog.index
213 unfilen = len(unfiindex) - 1
213 unfilen = len(unfiindex)
214 unfinode = unfiindex[unfilen - 1][7]
214 unfinode = unfiindex[unfilen - 1][7]
215
215
216 revs = filterrevs(unfi, self.filtername, self._visibilityexceptions)
216 revs = filterrevs(unfi, self.filtername, self._visibilityexceptions)
@@ -791,10 +791,8 b' indexformatv0_pack = indexformatv0.pack'
791 indexformatv0_unpack = indexformatv0.unpack
791 indexformatv0_unpack = indexformatv0.unpack
792
792
793 class revlogoldindex(list):
793 class revlogoldindex(list):
794 def __len__(self):
795 return list.__len__(self) + 1
796 def __getitem__(self, i):
794 def __getitem__(self, i):
797 if i == -1 or i == len(self) - 1:
795 if i == -1 or i == len(self):
798 return (0, 0, 0, -1, -1, -1, -1, nullid)
796 return (0, 0, 0, -1, -1, -1, -1, nullid)
799 return list.__getitem__(self, i)
797 return list.__getitem__(self, i)
800
798
@@ -1066,11 +1064,11 b' class revlog(object):'
1066 yield fp
1064 yield fp
1067
1065
1068 def tip(self):
1066 def tip(self):
1069 return self.node(len(self.index) - 2)
1067 return self.node(len(self.index) - 1)
1070 def __contains__(self, rev):
1068 def __contains__(self, rev):
1071 return 0 <= rev < len(self)
1069 return 0 <= rev < len(self)
1072 def __len__(self):
1070 def __len__(self):
1073 return len(self.index) - 1
1071 return len(self.index)
1074 def __iter__(self):
1072 def __iter__(self):
1075 return iter(pycompat.xrange(len(self)))
1073 return iter(pycompat.xrange(len(self)))
1076 def revs(self, start=0, stop=None):
1074 def revs(self, start=0, stop=None):
@@ -1139,7 +1137,7 b' class revlog(object):'
1139 i = self.index
1137 i = self.index
1140 p = self._nodepos
1138 p = self._nodepos
1141 if p is None:
1139 if p is None:
1142 p = len(i) - 2
1140 p = len(i) - 1
1143 else:
1141 else:
1144 assert p < len(i)
1142 assert p < len(i)
1145 for r in pycompat.xrange(p, -1, -1):
1143 for r in pycompat.xrange(p, -1, -1):
General Comments 0
You need to be logged in to leave comments. Login now