# HG changeset patch # User Manuel Jacob # Date 1596771701 -7200 # Fri Aug 07 05:41:41 2020 +0200 # Node ID 7aec15c8f9f11d31dc8c0ed6e6d7c9bea24c21ef # Parent 9e47dd1088ef0f037a736dfb85ac931a85e96a14 overlay: support {gitnode} keyword in templates for incoming changes Fixes #239. diff --git a/hggit/overlay.py b/hggit/overlay.py --- a/hggit/overlay.py +++ b/hggit/overlay.py @@ -12,6 +12,7 @@ context, manifest, match as matchmod, + node, util, ) from mercurial.node import bin, hex, nullid @@ -438,6 +439,21 @@ ) +class overlaygithandler(object): + # This was added to support the {gitnode} keyword in templates for incoming. + # For this, falling back to the underlying repository is not necessary. + + def __init__(self, repo): + self.repo = repo + + def map_git_get(self, sha): + # Normally, the parameter contains the hg hash. However, for incoming + # changesets, it contains the git hash, so we can return it as-is + # (after sanity-checking that it is the hash of an incoming commit). + assert node.bin(sha) in self.repo.revmap + return sha + + class overlayrepo(object): def __init__(self, handler, commits, refs): self.handler = handler @@ -472,6 +488,8 @@ except (AttributeError, ImportError): pass + self.githandler = overlaygithandler(self) + def _constructmanifest(self): return overlaymanifestrevlog(self, self.handler.repo._constructmanifest()) diff --git a/tests/test-incoming.t b/tests/test-incoming.t --- a/tests/test-incoming.t +++ b/tests/test-incoming.t @@ -95,12 +95,10 @@ +gamma 2 -incoming with a template that uses gitnode shows no git hash, but does not crash - $ hg incoming -r master --template 'changeset {rev}:{node|short}\ngitnode {gitnode}\n' | grep -v 'no changes found' + $ hg incoming -r master --template 'changeset: {rev}:{node|short}\ngitnode: {gitnode}\n' | grep -v 'no changes found' comparing with $TESTTMP/gitrepo - changeset 1:9497a4ee62e1 - gitnode - + changeset: 1:9497a4ee62e1 + gitnode: 9497a4ee62e16ee641860d7677cdb2589ea15554 incoming -r $ hg incoming -r master | grep -v 'no changes found'