Mercurial > hg
changeset 31650:23391acfc421
py3: fix manifestdict.fastdelta() to be compatible with memoryview
This doesn't look nice, but a straightforward way to support Python 3.
bytes(m[start:end]) is needed because a memoryview doesn't support ordering
operations. On Python 2, m[start:end] returns a bytes object even if m is
a buffer, so calling bytes() should involve no additional copy.
I'm tired of trying cleaner alternatives, including:
a. extend memoryview to be compatible with buffer type
=> memoryview is not an acceptable base type
b. wrap memoryview by buffer-like class
=> zlib complains it isn't bytes-like
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 26 Mar 2017 19:06:48 +0900 |
parents | 4bc3e55cf386 |
children | d3140fd322bf |
files | mercurial/manifest.py |
diffstat | 1 files changed, 5 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/manifest.py Sun Mar 26 17:00:23 2017 -0700 +++ b/mercurial/manifest.py Sun Mar 26 19:06:48 2017 +0900 @@ -650,10 +650,10 @@ that string. If start == end the string was not found and they indicate the proper sorted insertion point. - m should be a buffer or a string - s is a string''' + m should be a buffer, a memoryview or a byte string. + s is a byte string''' def advance(i, c): - while i < lenm and m[i] != c: + while i < lenm and m[i:i + 1] != c: i += 1 return i if not s: @@ -664,10 +664,10 @@ while lo < hi: mid = (lo + hi) // 2 start = mid - while start > 0 and m[start - 1] != '\n': + while start > 0 and m[start - 1:start] != '\n': start -= 1 end = advance(start, '\0') - if m[start:end] < s: + if bytes(m[start:end]) < s: # we know that after the null there are 40 bytes of sha1 # this translates to the bisect lo = mid + 1 lo = advance(end + 40, '\n') + 1