# HG changeset patch
# User muxator <a.mux@inwind.it>
# Date 1596493386 -7200
#      Tue Aug 04 00:23:06 2020 +0200
# Node ID d6ac1ae9027a438a4cad5174c7236a2335243774
# Parent  8b51b82cfb4840e87ef0a90314c549b62d8e43c1
gitnodekw: do not crash on hg incoming when log template includes gitnode()

Before this change, if the user's log template included a call to gitnode() to
show the git commit hash, invoking "hg incoming" on a git repository that had at
least one incoming change failed with:

   AttributeError: 'overlayrepo' object has no attribute 'githandler'

Since an incoming changeset should already have well defined git commit hashes,
there is no apparent reason for which "hg incoming" should not have this
information already.

This change is a workaround that removes any reference to the hg-git structures
from the incoming changeset, thus merely avoiding the crash.

Fixes #239 (https://foss.heptapod.net/mercurial/hg-git/-/issues/239)

diff --git a/hggit/__init__.py b/hggit/__init__.py
--- a/hggit/__init__.py
+++ b/hggit/__init__.py
@@ -442,6 +442,8 @@
 
 
 def _gitnodekw(node, repo):
+    if not hasattr(repo, 'githandler'):
+        return None
     gitnode = repo.githandler.map_git_get(node.hex())
     if gitnode is None:
         gitnode = b''
diff --git a/hggit/overlay.py b/hggit/overlay.py
--- a/hggit/overlay.py
+++ b/hggit/overlay.py
@@ -441,6 +441,7 @@
 class overlayrepo(object):
     def __init__(self, handler, commits, refs):
         self.handler = handler
+        self._activebookmark = None
 
         self.changelog = overlaychangelog(self, handler.repo.changelog)
         if util.safehasattr(handler.repo, b'manifest'):