Patchwork templater: shorten pure integers

login
register
mail settings
Submitter Sean Farley
Date Feb. 21, 2014, 8:10 p.m.
Message ID <efb1ea090de450c95d87.1393013427@laptop.local>
Download mbox | patch
Permalink /patch/3730/
State Superseded
Commit aa021ece4506f5e962c8d87ab58ab594a0105ced
Headers show

Comments

Sean Farley - Feb. 21, 2014, 8:10 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1392878773 21600
#      Thu Feb 20 00:46:13 2014 -0600
# Node ID efb1ea090de450c95d87e9a9c14cbf4a07bba4f9
# Parent  c1febc167d87a9f078707db9b8defa8fdf492fe9
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).
Sean Farley - Feb. 21, 2014, 8:57 p.m.
Sean Farley <sean.michael.farley@gmail.com> writes:

> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1392878773 21600
> #      Thu Feb 20 00:46:13 2014 -0600
> # Node ID efb1ea090de450c95d87e9a9c14cbf4a07bba4f9
> # Parent  c1febc167d87a9f078707db9b8defa8fdf492fe9
> 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 > len(cl):
> +                    return True
>                  return False
>              except ValueError:
>                  return True
>          except error.RevlogError:
>              return False

Go ahead and drop this patch, I noticed a typo in the comment and also
forgot --flag V2.

Patch

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 > len(cl):
+                    return True
                 return False
             except ValueError:
                 return True
         except error.RevlogError:
             return False