D12367: hgext: use io.BytesIO instead of util.stringio
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Thu Mar 10 01:08:53 UTC 2022
indygreg created this revision.
Herald added subscribers: mercurial-patches, Kwan.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
util.stringio is an alias to io.BytesIO. Let's just use io.BytesIO
directly.
I'm doing this because I noticed that in some cases pytype wasn't able
to infer the proper type of `util.stringio`. Removing the indirection
will enable type checking to work better.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D12367
AFFECTED FILES
hgext/absorb.py
hgext/convert/cvs.py
hgext/convert/hg.py
hgext/convert/subversion.py
hgext/infinitepush/bundleparts.py
hgext/patchbomb.py
hgext/phabricator.py
CHANGE DETAILS
diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -660,7 +660,7 @@
def getdiff(basectx, ctx, diffopts):
"""plain-text diff without header (user, commit message, etc)"""
- output = util.stringio()
+ output = io.BytesIO()
for chunk, _label in patch.diffui(
ctx.repo(), basectx.p1().node(), ctx.node(), None, opts=diffopts
):
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -77,6 +77,7 @@
import email.mime.multipart as emimemultipart
import email.utils as eutil
import errno
+import io
import os
import socket
@@ -104,8 +105,6 @@
urlutil,
)
-stringio = util.stringio
-
cmdtable = {}
command = registrar.command(cmdtable)
@@ -228,7 +227,7 @@
tmpl = ui.config(b'patchbomb', b'flagtemplate')
if not tmpl:
return b' '.join(flags)
- out = util.stringio()
+ out = io.BytesIO()
spec = formatter.literal_templatespec(templater.unquotestring(tmpl))
with formatter.templateformatter(ui, out, b'patchbombflag', {}, spec) as fm:
fm.startitem()
@@ -360,7 +359,7 @@
for r in revs:
if r == prev and (repo[None].files() or repo[None].deleted()):
ui.warn(_(b'warning: working directory has uncommitted changes\n'))
- output = stringio()
+ output = io.BytesIO()
cmdutil.exportfile(
repo, [r], output, opts=patch.difffeatureopts(ui, opts, git=True)
)
@@ -995,7 +994,7 @@
if not mbox:
# Exim does not remove the Bcc field
del m['Bcc']
- fp = stringio()
+ fp = io.BytesIO()
generator = mail.Generator(fp, mangle_from_=False)
generator.flatten(m, False)
alldests = to + bcc + cc
diff --git a/hgext/infinitepush/bundleparts.py b/hgext/infinitepush/bundleparts.py
--- a/hgext/infinitepush/bundleparts.py
+++ b/hgext/infinitepush/bundleparts.py
@@ -3,6 +3,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
+import io
from mercurial.i18n import _
from mercurial.node import hex
@@ -114,7 +115,7 @@
self.params = part.params
self.mandatorykeys = part.mandatorykeys
# copy the buffer
- self._io = util.stringio(part.read())
+ self._io = io.BytesIO(part.read())
def consume(self):
return
diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -3,6 +3,7 @@
# Copyright(C) 2007 Daniel Holth et al
import codecs
+import io
import locale
import os
import pickle
@@ -26,7 +27,6 @@
from . import common
-stringio = util.stringio
propertycache = util.propertycache
urlerr = util.urlerr
urlreq = util.urlreq
@@ -1267,12 +1267,12 @@
if self.module != new_module:
self.module = new_module
self.reparent(self.module)
- io = stringio()
- info = svn.ra.get_file(self.ra, file, revnum, io)
- data = io.getvalue()
+ bio = io.BytesIO()
+ info = svn.ra.get_file(self.ra, file, revnum, bio)
+ data = bio.getvalue()
# ra.get_file() seems to keep a reference on the input buffer
# preventing collection. Release it explicitly.
- io.close()
+ bio.close()
if isinstance(info, list):
info = info[-1]
mode = (b"svn:executable" in info) and b'x' or b''
diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -17,6 +17,7 @@
# the converted revision to have a different identity than the
# source.
+import io
import os
import re
import time
@@ -43,8 +44,6 @@
)
from mercurial.utils import dateutil
-stringio = util.stringio
-
from . import common
mapfile = common.mapfile
@@ -149,7 +148,7 @@
self.before()
def _rewritetags(self, source, revmap, data):
- fp = stringio()
+ fp = io.BytesIO()
for line in data.splitlines():
s = line.split(b' ', 1)
if len(s) != 2:
@@ -169,7 +168,7 @@
return fp.getvalue()
def _rewritesubstate(self, source, data):
- fp = stringio()
+ fp = io.BytesIO()
for line in data.splitlines():
s = line.split(b' ', 1)
if len(s) != 2:
diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py
--- a/hgext/convert/cvs.py
+++ b/hgext/convert/cvs.py
@@ -6,6 +6,7 @@
# GNU General Public License version 2 or any later version.
import errno
+import io
import os
import re
import socket
@@ -30,7 +31,6 @@
cvsps,
)
-stringio = util.stringio
checktool = common.checktool
commit = common.commit
converter_source = common.converter_source
@@ -260,7 +260,7 @@
# file-objects returned by socket.makefile() do not handle
# large read() requests very well.
chunksize = 65536
- output = stringio()
+ output = io.BytesIO()
while count > 0:
data = fp.read(min(count, chunksize))
if not data:
diff --git a/hgext/absorb.py b/hgext/absorb.py
--- a/hgext/absorb.py
+++ b/hgext/absorb.py
@@ -33,6 +33,7 @@
import collections
+import io
from mercurial.i18n import _
from mercurial.node import (
@@ -968,7 +969,7 @@
a1 = hunk.fromline + len(hunk.before) - 1
# remove before and after context
hunk.before = hunk.after = []
- buf = util.stringio()
+ buf = io.BytesIO()
hunk.write(buf)
patchlines = mdiff.splitnewlines(buf.getvalue())
# hunk.prettystr() will update hunk.removed
To: indygreg, #hg-reviewers
Cc: Kwan, mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list