Patchwork D271: obsolete: use bytestr() instead of str() so the node is bytes on py3

login
register
mail settings
Submitter phabricator
Date Aug. 8, 2017, 7:49 p.m.
Message ID <differential-rev-PHID-DREV-yti3p37otfb2cror2u7s-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/22761/
State Superseded
Headers show

Comments

phabricator - Aug. 8, 2017, 7:49 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I'm not sure this is right, since this should either be bytes or str
  to match what's going on in the revlog layer.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/obsolete.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - Aug. 9, 2017, 1:57 p.m.
yuja added inline comments.

INLINE COMMENTS

> obsolete.py:587
>  
> -        marker = (str(prec), tuple(succs), int(flag), metadata, date, parents)
> +        prec = bytes(pycompat.bytestr(prec))
> +        marker = (prec, tuple(succs), int(flag), metadata, date, parents)

Why can't this be just `bytes(prec)` ?

I don't think `str(prec).encode('ascii')` is valid for binary node id.

REPOSITORY
  rHG Mercurial

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

To: durin42, #hg-reviewers, quark
Cc: yuja, mercurial-devel
phabricator - Aug. 9, 2017, 2:24 p.m.
durin42 marked an inline comment as done.
durin42 added inline comments.

INLINE COMMENTS

> yuja wrote in obsolete.py:587
> Why can't this be just `bytes(prec)` ?
> 
> I don't think `str(prec).encode('ascii')` is valid for binary node id.

I swear that didn't work before. But it does work, so yay!

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -79,6 +79,7 @@ 
     obsutil,
     phases,
     policy,
+    pycompat,
     util,
 )
 
@@ -583,7 +584,8 @@ 
 
         metadata = tuple(sorted(metadata.iteritems()))
 
-        marker = (str(prec), tuple(succs), int(flag), metadata, date, parents)
+        prec = bytes(pycompat.bytestr(prec))
+        marker = (prec, tuple(succs), int(flag), metadata, date, parents)
         return bool(self.add(transaction, [marker]))
 
     def add(self, transaction, markers):