From patchwork Thu Feb 6 04:37:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: template: fix shortest(node) function in pure mercurial From: Durham Goode X-Patchwork-Id: 3489 Message-Id: To: mercurial-devel@selenic.com Date: Wed, 05 Feb 2014 20:37:44 -0800 # HG changeset patch # User Durham Goode # Date 1391660548 28800 # Wed Feb 05 20:22:28 2014 -0800 # Node ID d16e720434515abbe537e03a102ce151d1931165 # Parent aa51392da50763f3e7b9ec40acc3a97682488b66 template: fix shortest(node) function in pure mercurial Pure mercurial (i.e. without c extensions) does not support partialmatch() on the revlog index, so we must fall back to use revlog._partialmatch() to handle that case for us. The tests caught this. We don't use revlog._partialmatch() for the normal case because it performs a very expensive index iteration when the string being tested fails to find a unique result via index.partialmatch(). It does this in order to filter out hidden revs in hopes of the string being unique amongst non-hidden revs. For the shortest(node) case, we'd prefer performance over worrying about hidden revs. diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -368,7 +368,14 @@ cl = mapping['ctx']._repo.changelog def isvalid(test): try: - cl.index.partialmatch(test) + try: + cl.index.partialmatch(test) + except AttributeError: + # Pure mercurial doesn't support partialmatch on the index. + # Fallback to the slow way. + if cl._partialmatch(test) is None: + return False + try: int(test) return False