From patchwork Wed Apr 28 15:08:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D10528: git: initialize `extra` to have at least the branch name for nullid From: phabricator X-Patchwork-Id: 48847 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Wed, 28 Apr 2021 15:08:33 +0000 mharbison72 created this revision. Herald added a reviewer: durin42. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches. pulkit accepted this revision. This revision is now accepted and ready to land. REVISION SUMMARY 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 REPOSITORY rHG Mercurial BRANCH stable REVISION DETAIL https://phab.mercurial-scm.org/D10528 AFFECTED FILES hgext/git/gitlog.py tests/test-git-interop.t CHANGE DETAILS To: mharbison72, durin42, #hg-reviewers Cc: mercurial-patches, mercurial-devel diff --git a/tests/test-git-interop.t b/tests/test-git-interop.t --- a/tests/test-git-interop.t +++ b/tests/test-git-interop.t @@ -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: diff --git a/hgext/git/gitlog.py b/hgext/git/gitlog.py --- a/hgext/git/gitlog.py +++ b/hgext/git/gitlog.py @@ -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):