Patchwork D1795: py3: use pycompat.bytestr() instead of str()

login
register
mail settings
Submitter phabricator
Date Dec. 29, 2017, 12:49 a.m.
Message ID <differential-rev-PHID-DREV-ttt3pyzqhpklzbg2drae-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26493/
State Superseded
Headers show

Comments

phabricator - Dec. 29, 2017, 12:49 a.m.
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/D1795

AFFECTED FILES
  mercurial/debugcommands.py
  mercurial/subrepo.py
  mercurial/verify.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Jan. 11, 2018, 2:34 p.m.
yuja added a comment.


  `bytes()` or `"%d"` is preferred. Can you send a follow up?

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, durin42
Cc: yuja, mercurial-devel
phabricator - Jan. 12, 2018, 11:46 a.m.
pulkit added a comment.


  In https://phab.mercurial-scm.org/D1795#31282, @yuja wrote:
  
  > `bytes()` or `"%d"` is preferred. Can you send a follow up?
  
  
  I am not sure which one needs to be changed.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, durin42
Cc: yuja, mercurial-devel
phabricator - Jan. 12, 2018, 12:25 p.m.
yuja added inline comments.

INLINE COMMENTS

> subrepo.py:392
>          if source.isabs():
> -            return str(source)
> +            return pycompat.bytestr(source)
>          source.path = posixpath.normpath(source.path)

bytes()

> subrepo.py:399
>              parent.path = posixpath.normpath(parent.path)
> -            return str(parent)
> +            return pycompat.bytestr(parent)
>      else: # recursion reached top repo

bytes()

> verify.py:110
> +                self.warn(_(" (expected %s)") % " ".join
> +                          (map(pycompat.bytestr, linkrevs)))
>              lr = None # can't be trusted

'%d', perhaps.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, durin42
Cc: yuja, mercurial-devel
phabricator - Jan. 12, 2018, 1:34 p.m.
pulkit added inline comments.

INLINE COMMENTS

> yuja wrote in verify.py:110
> '%d', perhaps.

Looks like we cannot use "%d" here as None can be possible value also and test-treemanifest.t has tests with None as a part of output.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, durin42
Cc: yuja, mercurial-devel
phabricator - Jan. 12, 2018, 1:41 p.m.
yuja added inline comments.

INLINE COMMENTS

> pulkit wrote in verify.py:110
> Looks like we cannot use "%d" here as None can be possible value also and test-treemanifest.t has tests with None as a part of output.

Ugh, it smells, but let's just leave it for now.

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/mercurial/verify.py b/mercurial/verify.py
--- a/mercurial/verify.py
+++ b/mercurial/verify.py
@@ -17,6 +17,7 @@ 
 
 from . import (
     error,
+    pycompat,
     revlog,
     scmutil,
     util,
@@ -105,7 +106,8 @@ 
                                     if self.lrugetctx(l)[f].filenode() == node]
                     except Exception:
                         pass
-                self.warn(_(" (expected %s)") % " ".join(map(str, linkrevs)))
+                self.warn(_(" (expected %s)") % " ".join
+                          (map(pycompat.bytestr, linkrevs)))
             lr = None # can't be trusted
 
         try:
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -389,14 +389,14 @@ 
     if util.safehasattr(repo, '_subparent'):
         source = util.url(repo._subsource)
         if source.isabs():
-            return str(source)
+            return pycompat.bytestr(source)
         source.path = posixpath.normpath(source.path)
         parent = _abssource(repo._subparent, push, abort=False)
         if parent:
             parent = util.url(util.pconvert(parent))
             parent.path = posixpath.join(parent.path or '', source.path)
             parent.path = posixpath.normpath(parent.path)
-            return str(parent)
+            return pycompat.bytestr(parent)
     else: # recursion reached top repo
         if util.safehasattr(repo, '_subtoppath'):
             return repo._subtoppath
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -179,7 +179,7 @@ 
         ui.progress(_('building'), id, unit=_('revisions'), total=total)
         for type, data in dagparser.parsedag(text):
             if type == 'n':
-                ui.note(('node %s\n' % str(data)))
+                ui.note(('node %s\n' % pycompat.bytestr(data)))
                 id, ps = data
 
                 files = []