D2618: py3: use b"%d" to covert integer to bytes instead of str

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Sat Mar 3 23:19:15 UTC 2018


pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/journal.py
  hgext/mq.py
  hgext/patchbomb.py
  hgext/schemes.py

CHANGE DETAILS

diff --git a/hgext/schemes.py b/hgext/schemes.py
--- a/hgext/schemes.py
+++ b/hgext/schemes.py
@@ -94,7 +94,7 @@
             parts = parts[:-1]
         else:
             tail = ''
-        context = dict((str(i + 1), v) for i, v in enumerate(parts))
+        context = dict(('%d' % (i + 1), v) for i, v in enumerate(parts))
         return ''.join(self.templater.process(self.url, context)) + tail
 
 def hasdriveletter(orig, path):
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -212,7 +212,7 @@
     if not numbered:
         return '[PATCH%s]' % flag
     else:
-        tlen = len(str(total))
+        tlen = len("%d" % total)
         return '[PATCH %0*d of %d%s]' % (tlen, idx, total, flag)
 
 def makepatch(ui, repo, rev, patchlines, opts, _charsets, idx, total, numbered,
@@ -630,7 +630,7 @@
     if outgoing:
         revs = _getoutgoing(repo, dest, revs)
     if bundle:
-        opts['revs'] = [str(r) for r in revs]
+        opts['revs'] = ["%d" % r for r in revs]
 
     # check if revision exist on the public destination
     publicurl = repo.ui.config('patchbomb', 'publicurl')
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1932,7 +1932,7 @@
             length = len(self.series) - start
         if not missing:
             if self.ui.verbose:
-                idxwidth = len(str(start + length - 1))
+                idxwidth = len("%d" % (start + length - 1))
             for i in xrange(start, start + length):
                 patch = self.series[i]
                 if patch in applied:
@@ -2098,7 +2098,7 @@
         if not self.ui.verbose:
             p = pname
         else:
-            p = str(self.series.index(pname)) + " " + pname
+            p = ("%d" % self.series.index(pname)) + " " + pname
         return p
 
     def qimport(self, repo, files, patchname=None, rev=None, existing=None,
diff --git a/hgext/journal.py b/hgext/journal.py
--- a/hgext/journal.py
+++ b/hgext/journal.py
@@ -351,7 +351,7 @@
                 # Read just enough bytes to get a version number (up to 2
                 # digits plus separator)
                 version = f.read(3).partition('\0')[0]
-                if version and version != str(storageversion):
+                if version and version != "%d" % storageversion:
                     # different version of the storage. Exit early (and not
                     # write anything) if this is not a version we can handle or
                     # the file is corrupt. In future, perhaps rotate the file
@@ -361,7 +361,7 @@
                     return
                 if not version:
                     # empty file, write version first
-                    f.write(str(storageversion) + '\0')
+                    f.write(("%d" % storageversion) + '\0')
                 f.seek(0, os.SEEK_END)
                 f.write(bytes(entry) + '\0')
 
@@ -413,7 +413,7 @@
 
         lines = raw.split('\0')
         version = lines and lines[0]
-        if version != str(storageversion):
+        if version != "%d" % storageversion:
             version = version or _('not available')
             raise error.Abort(_("unknown journal file version '%s'") % version)
 



To: pulkit, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list