From patchwork Thu Feb 20 06:52:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: templater: shorten pure integers From: Sean Farley X-Patchwork-Id: 3719 Message-Id: <8ce8e771f4656449181b.1392879165@laptop.local> To: mercurial-devel@selenic.com Date: Thu, 20 Feb 2014 00:52:45 -0600 # HG changeset patch # User Sean Farley # Date 1392878773 21600 # Thu Feb 20 00:46:13 2014 -0600 # Node ID 8ce8e771f4656449181b013d7f16f941f2058ece # Parent 0e2877f8605dcaf4fdf2ab7e0046f1f6f80161dd templater: shorten pure integers Originally, the addition of the 'shorten' template function in 9c6b86dd2ed2 would not consider pure integers for shortening. This patch considers two simple cases: when the integer starts with zero (which is parsed by Mercurial as a hash first) and when the integer is larger than the tip (obviously not a rev). diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -414,11 +414,16 @@ def shortest(context, mapping, args): # Fallback to the slow way. if cl._partialmatch(test) is None: return False try: - int(test) + i = int(test) + # if we are a pure int, then starting with zero will not be + # confused as a rev; or, obviously, if the int larger than the + # value of the tip + if test[0] == '0' or i > cl.rev(cl.tip()): + return True return False except ValueError: return True except error.RevlogError: return False