Commit Graph

66 Commits

Author SHA1 Message Date
Anton Shestakov
ca791cb0ef templater: add count template filter, plus tests
Previously there was no way of telling how much children or bookmarks or tags a
certain changeset has in a template. It was possible to tell if a changeset has
either 0 or not 0 bookmarks, but not to tell if it has 1 or 2 of them, for
example.

This filter, simply named count, makes it possible to count the number of items
in a list or the length of a string (or, anything that python's len can count).
E.g.: {children|count}, {bookmarks|count}, {file_adds|count}.

Testing the filter on node hash and shortened node hash is chosen because they
both have defined length.

As for lists of strings - children, tags and file_adds are used, because they
provide some variety and also prove that what's counted is the number of string
items in the list, and not the list stringified (they are lists of non-empty,
multi-character strings).

Additionally, revset template function is used for testing the filter, since
the combination is very flexible and will possibly be used together a lot.

(The previous version of this patch had an incorrect email subject and was
apparently lost - patchwork says the patch has been accepted, but it's not so.
The changes between that and this patch are minimal: now the filter does not
disturb the alphabetical order of function definitions and dict keys.)
2014-09-09 22:14:13 +09:00
Matt Mackall
5fc8526562 merge with stable 2014-07-14 18:53:03 -05:00
Matt Mackall
de2b99d87c templates: escape NUL bytes in jsonescape (issue4303)
It's currently possible for various fields to contain NUL bytes, which
are disallowed in JSON.
2014-07-14 12:44:45 -05:00
Ryan McElroy
9f5399cbcd templatefilter: add splitlines function
This is useful for applying changes to each line, and it's especially powerful
when used in conjunction with conditionals to modify lines based on content.
2014-06-12 17:45:41 -07:00
Matt Mackall
397a3b5d72 merge with stable 2013-10-09 14:15:34 -07:00
Matt Mackall
23bced957e json: add more paranoid escaping 2013-10-09 11:50:19 -07:00
Mads Kiilerich
1e900bb145 check-code: check for spaces around = for named parameters 2013-10-03 14:50:47 +02:00
David Soria Parra
bd9e14bcec templatefilters: add short format for age formatting
Implements a short output format for ages e.g. "1 second ago" is
abbrevated as "1s ago".
2013-09-17 17:42:13 +02:00
Matt Mackall
dbd9dd9280 template: fix tabindent docstring (issue2880) 2013-07-19 12:58:30 -05:00
Sean Farley
44577c753d templater: add indentation arguments to the fill function 2013-04-18 15:48:22 -05:00
Sean Farley
8a5d9c21d4 templater: move templatefilters.func into the same place as the other funcs 2013-04-10 18:56:38 -05:00
Mads Kiilerich
00a100f5a5 merge with stable 2013-02-28 14:51:59 +01:00
Mads Kiilerich
93a2b8faf0 templatefilters: add missing import of _ 2013-02-28 13:55:00 +01:00
Angel Ezquerra
ed79324ad4 hgweb: add websub template filter
The purpose of this new filter is to make it possible to partially replace the
functionality of the interhg extension. The idea is to be able to define regular
expression based substitutions on a new "websub" config section. hgweb will then
be able to apply these substitutions wherever the "websub" filter is used on a
template.

This first revision just adds the code necessary to load the websub expressions
and adds the websub filter, but it does not add any calls to the websub filter
itself on any of the templates. That will be done on the following revisions.
2013-02-08 18:05:32 +01:00
Siddharth Agarwal
a03ea859ec hgweb: make the escape filter remove null characters (issue2567) 2012-10-15 09:43:34 -07:00
Christian Ebert
15900b9e01 templatefilters: avoid traceback caused by bogus date input (issue3344)
Wrap datefilters which split date texts with util.parsedate.

We do not abort, as the bogus date must have been given by the user.
2012-08-10 20:37:20 +01:00
Matt Mackall
14f92efff9 templatefilters: add parameterized date method 2012-09-24 15:54:45 -05:00
Matt Mackall
3289404a04 templatefilters: add parameterized fill function 2012-09-24 15:54:44 -05:00
Brodie Rao
a7ef0a0cc5 cleanup: "not x in y" -> "x not in y" 2012-05-12 16:00:57 +02:00
Matteo Capobianco
8305e8d305 templates/filters: extracting the user portion of an email address
Currently, the 'user' filter is using util.shortuser(text) (which clearly
doesn't extract only the user portion of an email address, even though the
help text says it does).

The new 'emailuser' filter uses the new util.emailuser(text) function which,
instead, does exactly that.

The help text on the 'user' filter has been modified accordingly.
2012-03-28 16:06:20 +02:00
Yann E. MORIN
e24b85ec3e templates/filters: add doctest to the 'person' filter
Add a doctest with an hopefuly-comprehensive list of combinations
we can expect in real-life situations.

This does not cover corner cases, for example when a CR or LF is
embedded in the name (allowed by RFC 5322!).

Code in tests/test-doctest.py contributed by:
    Martin Geisler <mg@aragost.com>
Thanks!

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
2012-03-07 01:02:12 +01:00
Yann E. MORIN
14521673fb templates/filters: strip quotes from {author|person}
RFC5322 (Internet Message Format) [0] says that the 'display name' of
an internet address [1] (what Mercurial calls 'person') can be quoted
with DQUOTE (ASCII 34: ") if it contains non-atom characters [2].
For example, dot '.' is a non-atom character. Also, DQUOTEs in a
quoted string will be escaped using "\" [2][3].

The current {author|person} template+filter just extracts the part
before an email address as-is. This can look ugly, especially on the
web interface, or when generating output for post-processing...

Moreover, as an example, the Mercurial repository has a bunch of
incoherent uses of DQUOTES in author names. As per Matt's digging:

  $ hg log --template "{author|person}\n" | grep '"' | sort | uniq
  "Andrei Vermel
  "Aurelien Jacobs
  "Daniel Santa Cruz
  "Hidetaka Iwai
  "Hiroshi Funai"
  "Mathieu Clabaut
  "Paul Moore
  "Peter Arrenbrecht"
  "Rafael Villar Burke
  "Shun-ichi GOTO"
  "Wallace, Eric S"
  "Yann E. MORIN"
  Josef "Jeff" Sipek
  Radoslaw "AstralStorm" Szkodzinski

Fix the 'person' filter to remove leading and trailing DQUOTES,
and unescape remaining DQUOTES.

Given this author: "J. \"random\" DOE" <john@doe.net>
  before:   {author|person} : "J. \"random\" DOE"
  after:    {author|person} : J. "random" DOE

For the Mercurial repository, that leaves us with two authors with
DQUOTES, in acceptable positions:

  $ hg log --template "{author|person}\n" | grep '"' | sort | uniq
  Josef "Jeff" Sipek
  Radoslaw "AstralStorm" Szkodzinski

[0] https://tools.ietf.org/html/rfc5322
[1] https://tools.ietf.org/html/rfc5322#section-3.4
[2] https://tools.ietf.org/html/rfc5322#section-3.2.4
[3] https://tools.ietf.org/html/rfc5322#section-3.2.1

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
2012-03-06 23:23:30 +01:00
Yann E. MORIN
ad9ca506f5 templates: add 'bisect' keyword to return a cset's bisect status
This new 'bisect' template expands to a cset's bisection status (good,
bad and so on...). There is also a new 'shortbisect' filter that yields
a single char representing the cset's bisection status.

It uses the two recently-added hbisect.label() and .shortlabel() functions.

Example output using the repository in test-bisect2.t, and some made-up
state of the 'end at merge' test (with graphlog, it's so explicit):

  $ hg glog --template '{rev}:{node|short} {bisect}\n'  \
            -r 'bisect(range)|bisect(ignored)'
  o  17:228c06deef46: bad
  |
  o  16:609d82a7ebae: bad (implicit)
  |
  o    15:857b178a7cf3: bad
  |\
  | o  13:b0a32c86eb31: good
  | |
  | o  12:9f259202bbe7: good (implicit)
  | |
  | o  11:82ca6f06eccd: good
  | |
  @ |    10:429fcd26f52d: untested
  |\ \
  | o |  9:3c77083deb4a: skipped
  | |/
  | o  8:dab8161ac8fc: good
  | |
  o |    6:a214d5d3811a: ignored
  |\ \
  | o |  5:385a529b6670: ignored
  | | |
  o | |  4:5c668c22234f: ignored
  | | |
  o | |  3:0950834f0a9c: ignored
  |/ /
  o /  2:051e12f87bf1: ignored
  |/

And now the same with the short label:

  $ hg log --template '{bisect|shortbisect} {rev}:{node|short}\n'
    18:d42e18c7bc9b
  B 17:228c06deef46
  B 16:609d82a7ebae
  B 15:857b178a7cf3
    14:faa450606157
  G 13:b0a32c86eb31
  G 12:9f259202bbe7
  G 11:82ca6f06eccd
  U 10:429fcd26f52d
  S 9:3c77083deb4a
  G 8:dab8161ac8fc
    7:50c76098bbf2
  I 6:a214d5d3811a
  I 5:385a529b6670
  I 4:5c668c22234f
  I 3:0950834f0a9c
  I 2:051e12f87bf1
    1:4ca5088da217
    0:33b1f9bc8bc5

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
2011-09-22 01:36:01 +02:00
Augie Fackler
ababdf1e2e templatefilters: use safehasattr instead of hasattr 2011-07-25 16:02:42 -05:00
Augie Fackler
2e41c2e64a globally: use safehasattr(x, '__iter__') instead of hasattr(x, '__iter__') 2011-07-25 15:30:19 -05:00
Matt Mackall
1d5abac148 help: consolidate topic hooks in help.py
This removes loops like cmdutil->revset->help->extensions->cmdutil and
simplifies the code.
2011-05-13 12:57:27 -05:00
Adrian Buehlmann
3a0445e3c8 templatefilters: improve person() for john.doe@example.com
BEFORE: person('john.doe@example.com') -> 'john'
AFTER:  person('john.doe@example.com') -> 'john doe'
2011-04-17 21:34:25 +02:00
timeless
56241a1f0c templates: provide granularity for future values for age filter 2011-03-16 03:28:56 +01:00
Patrick Mezard
d297dd65c7 help: extract items doc generation function 2011-03-12 12:46:31 +01:00
Patrick Mezard
daf132553b templatefilters: move doc from templates.txt to docstrings 2011-03-12 12:46:31 +01:00
Patrick Mezard
456bc03d53 templatefilters: wrap all filters in dedicated functions
This will highly simplify the docstring integration. I measured "hg log
--style=changelog" duration on mercurial itself and could not detect any
difference.
2011-03-12 12:46:31 +01:00
Patrick Mezard
b7b401fb97 templatefilters: prefix helper functions 2011-03-12 12:46:31 +01:00
Patrick Mezard
7d70363658 templatefilters: sort function definitions 2011-03-12 12:46:31 +01:00
Patrick Mezard
9a81e9d084 templatefilters: match filter keys and function names 2011-03-12 12:46:31 +01:00
Patrick Mezard
be156e05ac templatefilters: sort filters table 2011-03-12 12:46:31 +01:00
Dan Villiom Podlaski Christiansen
9c75aee050 templater: add hex filter. 2010-09-22 00:14:57 +02:00
Patrick Mezard
cfb0a4943f templatefilters: unnest uescape() 2010-08-15 17:50:52 +02:00
Yuya Nishihara
f6cfbe6d14 templatefilters: use \uxxxx style escape for JSON string
It's embeddable in plain javascript, and also conforms to JSON standard.
2010-08-11 01:06:21 +09:00
Yuya Nishihara
aaffe8d6bf templatefilters: make json filter handle multibyte characters correctly
It aims to fix javascript error of hgweb's graph view in Japanese 'cp932'
encoding.

'cp932' contains multibyte characters ending with '\x5c' (backslash),
e.g. '\x94\x5c' for Japanese Kanji 'Noh'.
Due to json filter escapes '\' to '\\', multibyte string ending with
'\x5c' is translated to "xxx\", resulting javascript parse error on
a web browser.

This patch changes json() to pass unicode to jsonescape().

Unicode decoding error handler changed to 'replace' by Patrick Mézard.
2010-08-07 16:27:16 +09:00
FUJIWARA Katsunori
9cce255bec replace Python standard textwrap by MBCS sensitive one for i18n text
Mercurial has problem around text wrapping/filling in MBCS encoding
environment, because standard 'textwrap' module of Python can not
treat it correctly. It splits byte sequence for one character into two
lines.

According to unicode specification, "east asian width" classifies
characters into:

   W(ide), N(arrow), F(ull-width), H(alf-width), A(mbiguous)


W/N/F/H can be always recognized as 2/1/2/1 bytes in byte sequence,
but 'A' can not. Size of 'A' depends on language in which it is used.

Unicode specification says:

   If the context(= language) cannot be established reliably they
   should be treated as narrow characters by default

but many of class 'A' characters are full-width, at least, in Japanese
environment.

So, this patch treats class 'A' characters as full-width always for
safety wrapping.

This patch focuses only on MBCS safe-ness, not on writing/printing
rule strict wrapping for each languages

MBCS sensitive textwrap class is originally implemented
by ITO Nobuaki <daydream.trippers@gmail.com>.
2010-06-06 17:20:10 +09:00
Matt Mackall
0c7546ee5b templatefilters: fix check-code warning 2010-03-29 16:11:40 -05:00
Benoit Boissinot
10e5d90501 templatefilters: store the agescales in reverseorder directly 2010-03-06 13:29:54 +01:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -06:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Dirkjan Ochtman
c08c589861 templater: readable dates older than 24 months revert to ISO8601 (issue1006) 2009-11-05 15:19:54 +01:00
Dirkjan Ochtman
2f9a035003 templater: put 'ago' inside the age template filter 2009-11-05 14:44:29 +01:00
Nicolas Dumazet
fbdff4820a templatefilters: indent: do not compute text.endswith('\n') in each iteration 2009-08-22 19:40:15 +02:00
Nicolas Dumazet
7eadbe8d42 for calls expecting bool args, pass bool instead of int
str.splitlines and email.message.as_string both expect a bool argument
defaulting at False: replace f(1) by f(True) and f(0) by f()
2009-07-13 09:50:26 +09:00
Alejandro Santos
3183e52503 compat: use // for integer division 2009-07-05 11:00:44 +02:00
Marco Beck
47e33d1f81 templater: retain author's full name if no email is supplied (issue1685) 2009-06-03 14:50:03 +02:00