Patchwork D7181: py3: make chistedit render

login
register
mail settings
Submitter phabricator
Date Oct. 31, 2019, 10:23 p.m.
Message ID <differential-rev-PHID-DREV-fzidp4dxgd3twyolo3ai-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42625/
State Superseded
Headers show

Comments

phabricator - Oct. 31, 2019, 10:23 p.m.
martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Now you can see the list of commits, but it crashes when you press a
  key.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/histedit.py

CHANGE DETAILS




To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 1, 2019, 2:39 a.m.
indygreg added inline comments.

INLINE COMMENTS

> histedit.py:1120
>  
> -    def __str__(self):
> +    def __bytes__(self):
>          # Some actions ('fold' and 'roll') combine a patch with a previous one.

`__bytes__` doesn't exist in Python 2. Did this patch regress Python 2?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7181/new/

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

To: martinvonz, durin42, #hg-reviewers
Cc: indygreg, mercurial-devel
phabricator - Nov. 1, 2019, 4:11 a.m.
martinvonz added inline comments.

INLINE COMMENTS

> indygreg wrote in histedit.py:1120
> `__bytes__` doesn't exist in Python 2. Did this patch regress Python 2?

Oh, good point! I'll make sure to test it on Python 2 as well. Update coming soon.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7181/new/

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

To: martinvonz, durin42, #hg-reviewers
Cc: indygreg, mercurial-devel

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1117,7 +1117,7 @@ 
         self.pos = pos
         self.conflicts = []
 
-    def __str__(self):
+    def __bytes__(self):
         # Some actions ('fold' and 'roll') combine a patch with a previous one.
         # Add a marker showing which patch they apply to, and also omit the
         # description for 'roll' (since it will get discarded). Example display:
@@ -1135,9 +1135,8 @@ 
         desc = self.ctx.description().splitlines()[0].strip()
         if self.action == b'roll':
             desc = b''
-        return b"#{0:<2} {1:<6} {2}:{3}   {4}".format(
-            self.origpos, action, r, h, desc
-        )
+        return b"#%s %s %d:%s   %s" % ((b'%d' % self.origpos).ljust(2),
+                                       action.ljust(6), r, h, desc)
 
     def checkconflicts(self, other):
         if other.pos > self.pos and other.origpos <= self.origpos:
@@ -1324,7 +1323,7 @@ 
     whitespace characters, so that the color appears on the whole line"""
     maxy, maxx = win.getmaxyx()
     length = maxx - 1 - x
-    line = (b"{0:<%d}" % length).format(str(line).strip())[:length]
+    line = bytes(line).ljust(length)[:length]
     if y < 0:
         y = maxy + y
     if x < 0:
@@ -1395,17 +1394,17 @@ 
         maxy, maxx = win.getmaxyx()
         length = maxx - 3
 
-        line = b"changeset: {0}:{1:<12}".format(ctx.rev(), ctx)
+        line = b"changeset: %d:%s" % (ctx.rev(), ctx.hex())
         win.addstr(1, 1, line[:length])
 
-        line = b"user:      {0}".format(ctx.user())
+        line = b"user:      %s" % ctx.user()
         win.addstr(2, 1, line[:length])
 
         bms = repo.nodebookmarks(ctx.node())
-        line = b"bookmark:  {0}".format(b' '.join(bms))
+        line = b"bookmark:  %s" % b' '.join(bms)
         win.addstr(3, 1, line[:length])
 
-        line = b"summary:   {0}".format(ctx.description().splitlines()[0])
+        line = b"summary:   %s" % (ctx.description().splitlines()[0])
         win.addstr(4, 1, line[:length])
 
         line = b"files:     "
@@ -1426,7 +1425,7 @@ 
         conflicts = rule.conflicts
         if len(conflicts) > 0:
             conflictstr = b','.join(map(lambda r: str(r.ctx), conflicts))
-            conflictstr = b"changed files overlap with {0}".format(conflictstr)
+            conflictstr = b"changed files overlap with %s" % conflictstr
         else:
             conflictstr = b'no overlap'