D4018: index: handle index[-1] as nullid more explicitly

2018-08-03 Thread martinvonz (Martin von Zweigbergk)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGf3d394ea17db: index: handle index[-1] as nullid more 
explicitly (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4018?vs=9777=9881

REVISION DETAIL
  https://phab.mercurial-scm.org/D4018

AFFECTED FILES
  mercurial/cext/revlog.c
  mercurial/pure/parsers.py

CHANGE DETAILS

diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -55,9 +55,9 @@
 return i
 
 def __getitem__(self, i):
+if i == -1 or i == len(self) - 1:
+return (0, 0, 0, -1, -1, -1, -1, nullid)
 i = self._fix_index(i)
-if i == len(self) - 1:
-return (0, 0, 0, -1, -1, -1, -1, nullid)
 if i >= self._lgt:
 return self._extra[i - self._lgt]
 index = self._calculate_index(i)
diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -158,19 +158,19 @@
Py_ssize_t length = index_length(self);
PyObject *entry;
 
+   if (pos == -1 || pos == length - 1) {
+   Py_INCREF(nullentry);
+   return nullentry;
+   }
+
if (pos < 0)
pos += length;
 
if (pos < 0 || pos >= length) {
PyErr_SetString(PyExc_IndexError, "revlog index out of range");
return NULL;
}
 
-   if (pos == length - 1) {
-   Py_INCREF(nullentry);
-   return nullentry;
-   }
-
if (pos >= self->length - 1) {
PyObject *obj;
obj = PyList_GET_ITEM(self->added, pos - self->length + 1);



To: martinvonz, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4018: index: handle index[-1] as nullid more explicitly

2018-08-01 Thread martinvonz (Martin von Zweigbergk)
martinvonz updated this revision to Diff 9777.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4018?vs=9718=9777

REVISION DETAIL
  https://phab.mercurial-scm.org/D4018

AFFECTED FILES
  mercurial/cext/revlog.c
  mercurial/pure/parsers.py

CHANGE DETAILS

diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -55,9 +55,9 @@
 return i
 
 def __getitem__(self, i):
+if i == -1 or i == len(self) - 1:
+return (0, 0, 0, -1, -1, -1, -1, nullid)
 i = self._fix_index(i)
-if i == len(self) - 1:
-return (0, 0, 0, -1, -1, -1, -1, nullid)
 if i >= self._lgt:
 return self._extra[i - self._lgt]
 index = self._calculate_index(i)
diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -158,19 +158,19 @@
Py_ssize_t length = index_length(self);
PyObject *entry;
 
+   if (pos == -1 || pos == length - 1) {
+   Py_INCREF(nullentry);
+   return nullentry;
+   }
+
if (pos < 0)
pos += length;
 
if (pos < 0 || pos >= length) {
PyErr_SetString(PyExc_IndexError, "revlog index out of range");
return NULL;
}
 
-   if (pos == length - 1) {
-   Py_INCREF(nullentry);
-   return nullentry;
-   }
-
if (pos >= self->length - 1) {
PyObject *obj;
obj = PyList_GET_ITEM(self->added, pos - self->length + 1);



To: martinvonz, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4018: index: handle index[-1] as nullid more explicitly

2018-08-01 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I find it more intuitive to check if "pos == -1" than to first add the
  index length (which includes one extra item for the nullid) and
  compare that to "length - 1". However, because test-parseindex2.py
  compares the whole index (up to len(index)-1), we need to also
  preserve that other check for a little while more. I'll remove it
  soon.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4018

AFFECTED FILES
  mercurial/cext/revlog.c
  mercurial/pure/parsers.py

CHANGE DETAILS

diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -55,9 +55,9 @@
 return i
 
 def __getitem__(self, i):
+if i == -1 or i == len(self) - 1:
+return (0, 0, 0, -1, -1, -1, -1, nullid)
 i = self._fix_index(i)
-if i == len(self) - 1:
-return (0, 0, 0, -1, -1, -1, -1, nullid)
 if i >= self._lgt:
 return self._extra[i - self._lgt]
 index = self._calculate_index(i)
diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -158,19 +158,19 @@
Py_ssize_t length = index_length(self);
PyObject *entry;
 
+   if (pos == -1 || pos == length - 1) {
+   Py_INCREF(nullentry);
+   return nullentry;
+   }
+
if (pos < 0)
pos += length;
 
if (pos < 0 || pos >= length) {
PyErr_SetString(PyExc_IndexError, "revlog index out of range");
return NULL;
}
 
-   if (pos == length - 1) {
-   Py_INCREF(nullentry);
-   return nullentry;
-   }
-
if (pos >= self->length - 1) {
PyObject *obj;
obj = PyList_GET_ITEM(self->added, pos - self->length + 1);



To: martinvonz, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel