git: initialize `extra` to have at least the branch name for nullid stable
authorMatt Harbison <matt_harbison@yahoo.com>
Tue, 27 Apr 2021 19:38:19 -0400
branchstable
changeset 47052 f8fa7ec53517
parent 47051 de26b9a7ec29
child 47053 4c7bc42a509e
git: initialize `extra` to have at least the branch name for nullid Otherwise, this crashes trying to convert to local encoding: ... File "/mnt/c/Users/Matt/hg/mercurial/logcmdutil.py", line 333, in _show branch = ctx.branch() File "/mnt/c/Users/Matt/hg/mercurial/context.py", line 675, in branch return encoding.tolocal(self._changeset.extra.get(b"branch")) File "/mnt/c/Users/Matt/hg/mercurial/encoding.py", line 181, in tolocal if isasciistr(s): TypeError: a bytes-like object is required, not 'NoneType' This was originally reported to the thg bug tracker. https://foss.heptapod.net/mercurial/tortoisehg/thg/-/issues/5629 Differential Revision: https://phab.mercurial-scm.org/D10528
hgext/git/gitlog.py
tests/test-git-interop.t
--- a/hgext/git/gitlog.py	Tue Apr 27 18:39:59 2021 -0400
+++ b/hgext/git/gitlog.py	Tue Apr 27 19:38:19 2021 -0400
@@ -221,9 +221,10 @@
             n = self.node(nodeorrev)
         else:
             n = nodeorrev
+        extra = {b'branch': b'default'}
         # handle looking up nullid
         if n == nullid:
-            return hgchangelog._changelogrevision(extra={}, manifest=nullid)
+            return hgchangelog._changelogrevision(extra=extra, manifest=nullid)
         hn = gitutil.togitnode(n)
         # We've got a real commit!
         files = [
@@ -253,7 +254,7 @@
             filesremoved=filesremoved,
             description=c.message.encode('utf8'),
             # TODO do we want to handle extra? how?
-            extra={b'branch': b'default'},
+            extra=extra,
         )
 
     def ancestors(self, revs, stoprev=0, inclusive=False):
--- a/tests/test-git-interop.t	Tue Apr 27 18:39:59 2021 -0400
+++ b/tests/test-git-interop.t	Tue Apr 27 19:38:19 2021 -0400
@@ -57,6 +57,12 @@
   $ hg init --git
   $ hg heads
   [1]
+  $ hg tip
+  changeset:   -1:000000000000
+  tag:         tip
+  user:        
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  
   $ cd ..
 
 Make a new repo with git: