py3: use bytearray() instead of array('c', ...) constructions
Portable from 2.6-3.6.
--- a/mercurial/branchmap.py Sat Mar 11 20:58:26 2017 -0500
+++ b/mercurial/branchmap.py Sun Mar 12 03:32:21 2017 -0400
@@ -357,7 +357,7 @@
assert repo.filtername is None
self._repo = repo
self._names = [] # branch names in local encoding with static index
- self._rbcrevs = array('c') # structs of type _rbcrecfmt
+ self._rbcrevs = bytearray()
self._rbcsnameslen = 0 # length of names read at _rbcsnameslen
try:
bndata = repo.vfs.read(_rbcnames)
@@ -371,7 +371,7 @@
if self._names:
try:
data = repo.vfs.read(_rbcrevs)
- self._rbcrevs.fromstring(data)
+ self._rbcrevs[:] = data
except (IOError, OSError) as inst:
repo.ui.debug("couldn't read revision branch cache: %s\n" %
inst)
@@ -390,8 +390,7 @@
self._rbcnamescount = 0
self._namesreverse.clear()
self._rbcrevslen = len(self._repo.changelog)
- self._rbcrevs = array('c')
- self._rbcrevs.fromstring('\0' * (self._rbcrevslen * _rbcrecsize))
+ self._rbcrevs = bytearray(self._rbcrevslen * _rbcrecsize)
def branchinfo(self, rev):
"""Return branch name and close flag for rev, using and updating
@@ -454,8 +453,7 @@
def _setcachedata(self, rev, node, branchidx):
"""Writes the node's branch data to the in-memory cache data."""
rbcrevidx = rev * _rbcrecsize
- rec = array('c')
- rec.fromstring(pack(_rbcrecfmt, node, branchidx))
+ rec = bytearray(pack(_rbcrecfmt, node, branchidx))
if len(self._rbcrevs) < rbcrevidx + _rbcrecsize:
self._rbcrevs.extend('\0' *
(len(self._repo.changelog) * _rbcrecsize -
--- a/mercurial/bundlerepo.py Sat Mar 11 20:58:26 2017 -0500
+++ b/mercurial/bundlerepo.py Sun Mar 12 03:32:21 2017 -0400
@@ -209,7 +209,7 @@
node = self.node(node)
if node in self.fulltextcache:
- result = self.fulltextcache[node].tostring()
+ result = '%s' % self.fulltextcache[node]
else:
result = manifest.manifestrevlog.revision(self, nodeorrev)
return result
--- a/mercurial/manifest.py Sat Mar 11 20:58:26 2017 -0500
+++ b/mercurial/manifest.py Sun Mar 12 03:32:21 2017 -0400
@@ -7,7 +7,6 @@
from __future__ import absolute_import
-import array
import heapq
import os
import struct
@@ -628,8 +627,9 @@
else:
# For large changes, it's much cheaper to just build the text and
# diff it.
- arraytext = array.array('c', self.text())
- deltatext = mdiff.textdiff(base, arraytext)
+ arraytext = bytearray(self.text())
+ deltatext = mdiff.textdiff(
+ util.buffer(base), util.buffer(arraytext))
return arraytext, deltatext
@@ -687,12 +687,12 @@
# for large addlist arrays, building a new array is cheaper
# than repeatedly modifying the existing one
currentposition = 0
- newaddlist = array.array('c')
+ newaddlist = bytearray()
for start, end, content in x:
newaddlist += addlist[currentposition:start]
if content:
- newaddlist += array.array('c', content)
+ newaddlist += bytearray(content)
currentposition = end
@@ -1240,7 +1240,7 @@
else:
text = m.text(self._usemanifestv2)
n = self.addrevision(text, transaction, link, p1, p2)
- arraytext = array.array('c', text)
+ arraytext = bytearray(text)
if arraytext is not None:
self.fulltextcache[n] = arraytext
@@ -1420,7 +1420,7 @@
else:
rl = self._revlog()
text = rl.revision(self._node)
- arraytext = array.array('c', text)
+ arraytext = bytearray(text)
rl._fulltextcache[self._node] = arraytext
self._data = manifestdict(text)
return self._data
@@ -1529,7 +1529,7 @@
self._data = m
else:
text = rl.revision(self._node)
- arraytext = array.array('c', text)
+ arraytext = bytearray(text)
rl.fulltextcache[self._node] = arraytext
self._data = treemanifest(dir=self._dir, text=text)
--- a/mercurial/tags.py Sat Mar 11 20:58:26 2017 -0500
+++ b/mercurial/tags.py Sun Mar 12 03:32:21 2017 -0400
@@ -428,13 +428,12 @@
self.lookupcount = 0
self.hitcount = 0
- self._raw = array('c')
try:
data = repo.vfs.read(_fnodescachefile)
except (OSError, IOError):
data = ""
- self._raw.fromstring(data)
+ self._raw = bytearray(data)
# The end state of self._raw is an array that is of the exact length
# required to hold a record for every revision in the repository.
@@ -475,7 +474,7 @@
self.lookupcount += 1
offset = rev * _fnodesrecsize
- record = self._raw[offset:offset + _fnodesrecsize].tostring()
+ record = '%s' % self._raw[offset:offset + _fnodesrecsize]
properprefix = node[0:4]
# Validate and return existing entry.
@@ -516,7 +515,7 @@
def _writeentry(self, offset, prefix, fnode):
# Slices on array instances only accept other array.
- entry = array('c', prefix + fnode)
+ entry = bytearray(prefix + fnode)
self._raw[offset:offset + _fnodesrecsize] = entry
# self._dirtyoffset could be None.
self._dirtyoffset = min(self._dirtyoffset, offset) or 0