Patchwork D1556: py3: use pycompat.bytestr() in place of str()

login
register
mail settings
Submitter phabricator
Date Nov. 29, 2017, 11:10 p.m.
Message ID <differential-rev-PHID-DREV-vsoejm5jocbzp7iudqgm-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/25814/
State Superseded
Headers show

Comments

phabricator - Nov. 29, 2017, 11:10 p.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/D1556

AFFECTED FILES
  mercurial/cmdutil.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 30, 2017, 12:25 p.m.
yuja requested changes to this revision.
yuja added inline comments.
This revision now requires changes to proceed.

INLINE COMMENTS

> cmdutil.py:828
>          'H': lambda: hex(node),
> -        'R': lambda: str(repo.changelog.rev(node)),
> +        'R': lambda: pycompat.bytestr(repo.changelog.rev(node)),
>          'h': lambda: short(node),

'%d' is preferred if the value type is known.

(applies to the other integer values.)

> cmdutil.py:830
>          'h': lambda: short(node),
> -        'm': lambda: re.sub('[^\w]', '_', str(desc))
> +        'm': lambda: re.sub('[^\w]', '_', pycompat.bytestr(desc))
>          }

Perhaps this can be `desc or ''`.

`hg archive '%m'` creates a directory "None", but which is probably
a bug.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, yuja
Cc: yuja, mercurial-devel
phabricator - Dec. 2, 2017, 2:57 a.m.
yuja requested changes to this revision.
yuja added inline comments.
This revision now requires changes to proceed.

INLINE COMMENTS

> cmdutil.py:828
>          'h': lambda: short(node),
> -        'm': lambda: re.sub('[^\w]', '_', str(desc))
> +        'm': lambda: re.sub('[^\w]', '_', pycompat.bytestr(desc or ''))
>          }

and now no `str()` nor `bytestr()` should be needed.

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -825,9 +825,9 @@ 
                   total=None, seqno=None, revwidth=None, pathname=None):
     node_expander = {
         'H': lambda: hex(node),
-        'R': lambda: str(repo.changelog.rev(node)),
+        'R': lambda: pycompat.bytestr(repo.changelog.rev(node)),
         'h': lambda: short(node),
-        'm': lambda: re.sub('[^\w]', '_', str(desc))
+        'm': lambda: re.sub('[^\w]', '_', pycompat.bytestr(desc))
         }
     expander = {
         '%': lambda: '%',
@@ -838,14 +838,15 @@ 
         if node:
             expander.update(node_expander)
         if node:
-            expander['r'] = (lambda:
-                    str(repo.changelog.rev(node)).zfill(revwidth or 0))
+            expander['r'] = (lambda: pycompat.bytestr(
+                             repo.changelog.rev(node)).zfill(revwidth or 0))
         if total is not None:
-            expander['N'] = lambda: str(total)
+            expander['N'] = lambda: pycompat.bytestr(total)
         if seqno is not None:
-            expander['n'] = lambda: str(seqno)
+            expander['n'] = lambda: pycompat.bytestr(seqno)
         if total is not None and seqno is not None:
-            expander['n'] = lambda: str(seqno).zfill(len(str(total)))
+            expander['n'] = (lambda: pycompat.bytestr(seqno).zfill(
+                                                len(pycompat.bytestr(total))))
         if pathname is not None:
             expander['s'] = lambda: os.path.basename(pathname)
             expander['d'] = lambda: os.path.dirname(pathname) or '.'