Commit Graph

330 Commits

Author SHA1 Message Date
Ryan McElroy
dbe0173b5a templater: introduce indent function 2015-04-04 01:03:52 -07:00
Jordi Gutiérrez Hermoso
4663e5eaa7 templater: look for mapfiles in template paths
This will allow %include statements to search the default template
paths in addition to the directory where the %including file is.
2015-05-15 09:07:27 -04:00
Yuya Nishihara
d32b63ddfe templater: update error message of invalid number passed to word() function
"word(3, desc)" is valid now.
2015-05-02 15:49:38 +09:00
Yuya Nishihara
c9018b3968 templater: tokenize decimal integer literal (issue4638) (BC)
Before this patch, we had to quote integer literals to pass to template
functions. It was error-prone, so we should allow "word(0, x)" syntax.
Currently only decimal integers are allowed. It's easy to support 0x, 0b and 0
prefixes, but I don't think they are useful.

This patch assumes that template keywords and names defined in map files do
not start with digits, except for positional variables seen in the schemes
extension.
2015-05-01 20:43:55 +09:00
Yuya Nishihara
6c84ac9a59 templater: switch methods table on compileexp() of func args and inner expr
The next patch will introduce integer literals, but the schemes extension
expects that '{1}', '{2}', ... are interpreted as keywords. This patch allows
us to process '{foo(1)}' as 'func(integer)', whereas '{1}' as 'symbol'.
2015-05-02 18:05:04 +09:00
Yuya Nishihara
5fa62c1dd9 templater: rename parsestring() to unquotestring() (API)
Since e926f2ef639a, it doesn't parse string escapes.
2015-05-04 10:03:13 +09:00
Yuya Nishihara
71c4aa007f templater: remove noop calls of parsestring(s, quoted=False) (API)
Since e926f2ef639a, parsestring(s, quoted=False) just returns s.
2015-05-04 10:01:03 +09:00
Yuya Nishihara
42c8c2abc2 templater: strip single backslash before quotation mark in quoted template
e926f2ef639a fixed the issue of double escapes, but it made the following
template fail with syntax error because of <\">. Strictly speaking, <\">
appears to be invalid in non-string part, but we are likely to escape <">
if surrounded by quotes, and we are used to write such templates by trial
and error.

  [templates]
  sl = "{tags % \"{ifeq(tag,'tip','',label('log.tag', ' {tag}'))}\"}"

So, for backward compatibility between 2.8.1 and 3.4, a single backslash
before quotation mark is stripped only in quoted template. We don't care
for <\"> in string literal in quoted template, which never worked as expected
before.

  template  result
  --------- ------------------------
  {\"\"}    parse error
  "{""}"    {""} -> <>
  "{\"\"}"  {""} -> <>
  {"\""}    {"\""} -> <">
  '{"\""}'  {"\""} -> <">
  "{"\""}"  parse error (don't care)
2015-05-08 18:11:26 +09:00
Matt Harbison
298c02c65a templater: don't overwrite the keyword mapping in runsymbol() (issue4362)
This keyword remapping was introduced in 236440938a03 as part of converting
generator based iterators into list based iterators, mentioning "undesired
behavior in template" when a generator is exhausted, but doesn't say what and
introduces no tests.

The problem with the remapping was that it corrupted the output for keywords
like 'extras', 'file_copies' and 'file_copies_switch' in templates such as:

    $ hg log -r 82a4f5557c6b --template "{file_copies % ' File: {file_copy}\n'}"
    File: mercurial/changelog.py (mercurial/hg.py)
    File: mercurial/changelog.py (mercurial/hg.py)
    File: mercurial/changelog.py (mercurial/hg.py)
    File: mercurial/changelog.py (mercurial/hg.py)
    File: mercurial/changelog.py (mercurial/hg.py)
    File: mercurial/changelog.py (mercurial/hg.py)
    File: mercurial/changelog.py (mercurial/hg.py)
    File: mercurial/changelog.py (mercurial/hg.py)

What was happening was that in the first call to runtemplate() inside runmap(),
'lm' mapped the keyword (e.g. file_copies) to the appropriate showxxx() method.
On each subsequent call to runtemplate() in that loop however, the keyword was
mapped to a list of the first item's pieces, e.g.:

   'file_copy': ['mercurial/changelog.py', ' (', 'mercurial/hg.py', ')']

Therefore, the dict for the second and any subsequent items were not processed
through the corresponding showxxx() method, and the first item's data was
reused.

The 'extras' keyword regressed in 56b014c52204, and 'file_copies' regressed in
4e182fb53989 for other reasons.  The common thread of things fixed by this seems
to be when a list of dicts are passed to the templatekw._hybrid class.
2014-11-03 12:08:03 -05:00
FUJIWARA Katsunori
3bf105df13 i18n: add i18n comment to error messages of template functions 2014-11-01 02:43:08 +09:00
Matt Mackall
7e6c7ddb4e merge with stable 2014-10-10 12:15:46 -05:00
Matt Mackall
8090c41031 templater: fix ifcontains when list is a string (issue4399) 2014-10-10 11:38:00 -05:00
FUJIWARA Katsunori
0365f0be0a templater: add i18n comments to error messages of newly added functions
This patch adds i18n comments to error messages of newly added
functions "startswith" (introduced by 970f27eeba13) and "word" (by
de9bbd245713).
2014-08-01 02:14:24 +09:00
Mads Kiilerich
3326c1de0b templater: don't search randomly for templates - trust util.datapath
The search was introduced in 501e9ec9a85d. It might have been necessary back
then when using __file__ directly and frozen-ness wasn't considered. Now we
should know exactly where the templates can be found.
2014-09-28 16:57:37 +02:00
Mads Kiilerich
74b470ec55 templater: inline global 'path' list in templatepaths 2014-09-28 16:57:37 +02:00
Mads Kiilerich
374f35aab5 templater: introduce templatepaths for getting paths searched for templates
Avoid function with different return types depending on parameters.
2014-09-28 16:57:37 +02:00
Mads Kiilerich
e9c0145df2 util: introduce datapath for getting the location of supporting data files
templates, help and locale data is normally stored as sub folders in the
directory containing the source of the mercurial module. In a frozen build they
live as sub folders next to 'hg.exe' and 'library.zip'.

These different kind of data were handled in different ways. Unify that by
introducing util.datapath. The value is computed from the environment and is
always used, so we just calculate the value on module load.
2014-09-28 16:57:06 +02:00
FUJIWARA Katsunori
330bc07caa templater: add "diff" template function
"diff" allows to embed changes in the target revision into template
output, even if the command itself doesn't take "--patch" option

Combination of "[committemplate]" configuration and "diff" template
function can achieve the feature like issue231 ("option to have diff
displayed in commit editor buffer")

    http://bz.selenic.com/show_bug.cgi?id=231

For example, templating below can be used to add each "diff" output
lines "HG: " prefix::

      {splitlines(diff) % 'HG: {line}\n'}

This patch implements "diff" not as "a template keyword" but as "a
template function" to take include/exclude patterns at runtime.

It allows to specify target files of command (by -I/-X command line
options) and "diff" separately.
2014-08-28 22:45:36 +09:00
FUJIWARA Katsunori
baa869750d templater: enable alias predicates to be used in "revset()" function
Before this patch, predicates defined in "[revsetalias]" can't be used
in the query specified to template function "revset()", because:

  - "revset()" uses "localrepository.revs()" to get query result, but
  - "localrepository.revs()" passes "None" as "ui" to "revset.match()", then
  - "revset.match()" can't recognize any alias predicates

To enable alias predicates to be used in "revset()" function, this
patch invokes "revset.match()" directly with "repo.ui".

This patch doesn't make "localrepository.revs()" pass "self.ui" to
"revset.match()", because this may be intentional implementation to
prevent alias predicates from shadowing built-in ones and breaking
functions internally using "localrepository.revs()".

Even if it isn't intentional one, the check for shadowing should be
implemented (maybe on default branch) before fixing it for safety.
2014-08-23 21:23:02 +09:00
Ryan McElroy
2464893018 templater: introduce word function
This function allows returning only the nth "word" from a string. By default
a string is split as by Python's split() function default, but an optional
third parameter can also override what string the string is split by.
2014-06-12 18:02:23 -07:00
Ryan McElroy
e3b09c4564 templater: add symbol to error
This patch makes it easier to debug writing templater functions by
telling the user exactly what was sent to the templater.
2014-06-12 18:07:21 -07:00
Ryan McElroy
f735b30979 templater: introduce startswith function
This function returns a string only if it starts with a given string.
It is particularly useful when combined with splitlines and/or used with
conditionals that fail when empty strings are passed in to take action
based on the contents of a line.
2014-06-12 17:53:37 -07:00
Augie Fackler
29ea24d6d3 templater: restore use of callable() since it was readded in Python 3.2 2014-06-23 09:24:56 -04:00
Durham Goode
63d5c92a11 templates: fix ifcontains against sets with length > 1 (issue4259)
Previously the ifcontains revset was checking against the set using a pure
__contains__ check.  It turns out the set was actually a list of
formatted strings meant for ui output, which meant the contains check failed if
the formatted string wasn't significantly different from the raw value.

This change makes it check against the raw data, prior to it being formatted.
2014-05-23 16:25:55 -07:00
Kevin Bullock
c63d1fcf68 merge with stable
This should correct an earlier couple of bad merges (5433856b2558 and
596960a4ad0d, now pruned) that accidentally brought in a change that had
been marked obsolete (244ac996a821).
2014-03-31 10:12:07 -05:00
Sean Farley
029b060498 templater: raise error for unknown func
Previously, if a template '{foo()}' was given, the buildfunc would not be able
to match it and hit a code path that would not return so it would error out
later in the templater stating that NoneType was not iterable. This patch makes
sure that a proper error is raised so that the user can be informed.

Tests have been updated.
2014-03-27 17:21:27 -05:00
FUJIWARA Katsunori
d28789bf48 templater: make strings in template expressions be "string-escape"-ed correctly
Changeset 83ff877959a6 (released with 2.8.1) fixed "recursively
evaluate string literals as templates" problem (issue4102) by moving
the location of "string-escape"-ing from "tokenizer()" to
"compiletemplate()".

But some parts in template expressions below are not processed by
"compiletemplate()", and it may cause unexpected result.

  - 'expr' of 'if(expr, then, else)'
  - 'expr's of 'ifeq(expr, expr, then, else)'
  - 'sep' of 'join(list, sep)'
  - 'text' and 'style' of 'rstdoc(text, style)'
  - 'text' and 'chars' of 'strip(text, chars)'
  - 'pat' and 'repl' of 'sub(pat, repl, expr)'

For example, '\n' of "{join(extras, '\n')}" is not "string-escape"-ed
and treated as a literal '\n'. This breaks "Display the contents of
the 'extra' field, one per line" example in "hg help templates".

Just "string-escape"-ing on each parts above may not work correctly,
because inside expression of nested ones already applies
"string-escape" on string literals. For example:

  - "{join(files, '\n')}" doesn't return "string-escape"-ed string, but
  - "{join(files, if(branch, '\n', '\n'))}" does

To fix this problem, this patch does:

  - introduce "rawstring" token and "runrawstring" method to handle
    strings not to be "string-escape"-ed correctly, and

  - make "runstring" method return "string-escape"-ed string, and
    delay "string-escape"-ing until evaluation

This patch invokes "compiletemplate()" with "strtoken=exp[0]" in
"gettemplate()", because "exp[1]" is not yet evaluated. This code path
is tested via mapping ("expr % '{template}'").

In the other hand, this patch invokes it with "strtoken='rawstring'"
in "_evalifliteral()", because "t" is the result of "arg" evaluation
and it should be "string-escape"-ed if "arg" is "string" expression.

This patch doesn't test "string-escape"-ing on 'expr' of 'if(expr,
then, else)', because it doesn't affect the result.
2014-03-10 01:01:43 +09:00
FUJIWARA Katsunori
f3e5f1e6c1 templater: apply "stringify()" on sub expression to get string correctly
Templating syntax allows nested expression to be specified as parts
below, but they are evaluated as a generator and don't work correctly.

  - 'sep' of 'join(list, sep)'
  - 'text' and 'chars' of 'strip(text, chars)'

In the former case, 'sep' returns expected string only for the first
separation, and empty one for the second or later, because the
generator has only one element.

In the latter case, templating is aborted by exception, because the
generator doesn't have 'strip()' method (as 'text') and can't be
passed as the argument to 'str.strip()' (as 'chars').

This patch applies "stringify()" on these sub expression to get string
correctly.
2014-03-10 01:01:43 +09:00
FUJIWARA Katsunori
7a7d1bc22c templater: avoid recursive evaluation of string literals completely
Changeset c84f81c3e120 (released with 2.8.1) fixed "recursively
evaluate string literals as templates" problem (issue4103) by
introducing "_evalifliteral()".

But some parts in template expressions below are still processed by
the combination of "compiletemplate()" and "runtemplate()", and may
cause same problem unexpectedly.

  - 'init' and 'hang' of 'fill(text, width, init, hang)'
  - 'expr' of 'sub(pat, repl, expr)'
  - 'label' of 'label(label, expr)'

This patch processes them by "_evalifliteral()" instead of the
combination of "compiletemplate()" and "runtemplate()" to avoid
recursive evaluation of string literals completely.
2014-03-10 01:01:42 +09:00
Matt Mackall
3672c23fd5 merge with stable 2014-03-11 16:19:08 -05:00
Sean Farley
4e69c94634 templater: shorten pure integers
Originally, the addition of the 'shorten' template function in 83d773060c28
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).
2014-02-20 00:46:13 -06:00
Durham Goode
f8aca20bcb template: add revset() template function
Adds a template function that executes a revset and returns the list of
revisions as the result. It has the signature 'revset(query [, args...])'. The
args are optional and are applied to the query string using the standard
python string.format(args) pattern. This allows things like:
'{revset("parents({0})", rev)}' to produce the parents of each individual
commit in the log output.  If no args are specified, the revset result is
cached for the duration of the templater; so it's better to not use args if
performance is a concern.

By itself, revset() can be used to print commit parents, print the common
ancestor of a commit with the main branch, etc.

It can be used with the ifcontains() function to do things like
'{ifcontains(rev, revset('.'), label(...), ...)}' to color the working copy
parent, to color certain branches, to color draft commits, etc.
2014-02-11 21:04:12 -08:00
Durham Goode
cb61deed09 template: add ifcontains template function
Adds a template function with the signature 'ifcontains(item, set, then[,
else])'.  It can be used to do things like '{ifcontains('.hgignore',
file_mods, label(...), ...)}' to color commits that edit the .hgignore file.
A future patch will add the revset() function which will combine with
ifcontains to allow us to color commits if they are in the revset.
2014-02-11 21:10:00 -08:00
Durham Goode
41c61c62a7 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.
2014-02-05 20:22:28 -08:00
Durham Goode
fe9653ca83 template: add pad function for padding output
Adds a pad template function with the following signature:

pad(text, width, fillchar=' ', right=False)

This uses the standard python ljust and rjust functions to produce a string
that is at least a certain width. This is useful for aligning variable length
strings in log output (like user names or shortest(node) output).
2014-01-17 00:16:48 -08:00
Durham Goode
156d6da226 template: add shortest(node) template function
Adds a '{shortest(node)}' template function that results in the shortest hex node
that uniquely identifies the changeset at that time. The minimum length can be
specified as an optional second argument and defaults to 4.

This is useful for producing prettier log output, like so:

@  durham  shortestnode
|  77cf    template: add pad function for padding output
|
o  durham
|  b183    template: add shortestnode keyword
|
o  pierre-yves @
|  6545    backout: add a message after backout that need manual commit
|
| o  durham   manifestcache
|/   93f0    manifest cache
|
| o  durham   catperf
| |  c765    cat: increase perf when catting single files
| |
| o  durham
|/   9c53    changectx: increase perf of walk function
|
2014-01-17 00:10:37 -08:00
Simon Heimberg
f9ed3a6ac4 templater: selecting a style with no templates does not crash (issue4140)
Running `hg log --style compact` (or any other style) raised a traceback when
no template directory was there. Now there is a message:

Abort: style 'compact' not found
(available styles: no templates found, try `hg debuginstall` for more info)


There is no test because this would require to rename the template directory.
But this would influence other tests running in parallel. And when the test
would be aborted the wrong named directory would remain, especially a problem
when running with -l.
2014-01-23 01:29:50 +01:00
Matt Mackall
52dafe7a2a templater: only recursively evaluate string literals as templates (issue4103) 2013-11-18 15:37:09 -05:00
Matt Mackall
c9a233d77e templater: fix escaping in nested string literals (issue4102)
Before the templater got extended for nested expressions, it made
sense to decode string escapes across the whole string. Now we do it
on a piece by piece basis.
2013-11-18 14:02:26 -05:00
Alexander Plavin
38dc1f0139 templater: support using templates with non-standard names from map file
Allow to add arbitrarily-named entries to a template map file and then
reference them, to make it possible to deduplicate and simplify
templates code.
2013-09-22 13:52:18 +04:00
Alexander Plavin
66771f0e45 templater: sort functions alphabetically, as filters are 2013-06-29 14:27:53 +04:00
Alexander Plavin
10b1e709b7 templater: add strip function with chars as an extra argument
This allows specifying characters to strip, like the Python strip function.
2013-06-25 21:02:22 +04: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
Augie Fackler
40d8d30902 templater: fix output instability from gsoc patches 2013-05-02 20:41:22 -05:00
Iulian Stana
5b8686673c templater: show the style list when I try to use a wrong one
When someone try to use a wrong style, a list with sugestions will appear.

In the test-log.t file it's a test that prove this thing.
2013-05-02 20:23:14 -05:00
Alexander Plavin
fb005d78d7 hgweb: make help verbose again (issue3899)
Due to regression introduced in 5fc7d589c700, help in hgweb
was rendered in non-verbose form (issue3899)
2013-04-22 12:27:56 +04:00
Sean Farley
766233e4bb template: call runtemplate on the src argument to sub
This allows using a template keyword on calls to the sub function and brings
the function inline with most other semantics of the other template functions.
2013-04-10 19:27:49 -05:00
Matt Mackall
7f909e9c22 templatekw: add default styles for hybrid types (issue3887)
This allows elements like file_copies to be printed as 'name (source)'
when used with join.
2013-04-16 09:44:29 -05:00
Brendan Cully
6bf5800d14 templater: back out 0da42d2ff029, it breaks schemes ({1}) 2013-04-09 21:38:08 -07:00
Bryan O'Sullivan
7c51d9d3e5 templater: fix check-code error 2013-04-08 15:04:17 -07:00
Brendan Cully
1c111a8da8 template: allow unquoted int function arguments 2013-04-07 23:25:50 -07:00
Dan Villiom Podlaski Christiansen
9e387ff40b hgweb: generate HTML documentation
It's generated from the raw ReST source, as returned from help.help_().
2013-02-09 21:51:21 +00:00
Benoit Boissinot
077bafacf4 templater: add get() function to access dict element (e.g. extra) 2013-02-08 23:49:14 +01:00
Sean Farley
3247f202be templater: add no-op template function 'label' 2012-12-22 21:46:26 -06:00
Weiwen
64b5450a1f hgweb: display diff for a changeset against any parents (issue2810)
During merge of branches, it is useful to compare merge results against
the two parents.  This change adds this support to hgweb.  To specify
which parent to compare to, use rev/12300:12345 where 12300 is a
parent changeset number.  Two links are added to changeset web page so
that one can choose which parent to compare to.
2012-11-12 14:05:39 -08:00
Weiwen
75df7d78cd template engine: convert generator-based iterator to list-based iterator
If a template iterator is implemented with generator, the iterator is exhau=
sted
after we use it.  This leads to undesired behavior in template.  This chang=
e
converts a generator-based iterator to list-based iterator when template en=
gine
first detects a generator-based iterator.  All future usages of iterator wi=
ll
use list instead.
2012-11-28 14:55:42 -08:00
FUJIWARA Katsunori
78e9fa90ae i18n: add "i18n" comment to error messages of template functions 2012-10-31 03:59:27 +09:00
Matt Mackall
12037daac2 templater: drop redundant return in _flatten 2012-10-08 16:21:24 -05:00
Matt Mackall
d55a703a7d templater: pull in functions defined in templatefilters 2012-09-24 15:28:04 -05:00
Matt Mackall
e32befe1a7 templater: add if/ifeq conditionals 2012-09-24 15:26:56 -05:00
Matt Mackall
0aa788b5f2 templater: add sub() function 2012-09-24 15:26:17 -05:00
Matt Mackall
07ad449236 templater: correctly deal with r"" strings 2012-09-24 15:24:27 -05:00
Matt Mackall
01ed21300f template: add join function
This allows:

{join(files % "{files}", ", ") }\n

to produce a properly comma-separated list
2012-09-22 13:04:36 -05:00
Matt Mackall
bf4fb1e322 templater: factor out runtemplate method
As a side-effect, this makes the output of runmap non-flattened
2012-09-22 13:02:33 -05:00
Matt Mackall
0dd30183db templating: make new-style templating features work with command line lists 2012-09-21 18:54:00 -05:00
Neil Kodner
68912667a4 templater: abort when a template filter raises an exception (issue2987) 2012-08-17 15:12:01 -07:00
Ross Lagerwall
48a670fcaf templater: handle a missing value correctly
Before, using a broken style such as:
changeset =
would result in a traceback.

This fixes a regression introduced in 47618355ffc8.
2012-08-04 14:37:17 +02:00
Brodie Rao
a7ef0a0cc5 cleanup: "not x in y" -> "x not in y" 2012-05-12 16:00:57 +02:00
Augie Fackler
2e41c2e64a globally: use safehasattr(x, '__iter__') instead of hasattr(x, '__iter__') 2011-07-25 15:30:19 -05:00
Augie Fackler
fdd2f9d735 globally: use safehasattr(x, '__call__') instead of hasattr(x, '__call__') 2011-07-25 16:24:37 -05:00
Augie Fackler
c1bfd9e71f windows: check util.mainfrozen() instead of ad-hoc checks everywhere 2011-07-25 16:14:02 -05:00
Matt Mackall
4257ca8615 templater: use a global funcs table 2011-07-23 14:33:35 -05:00
Dan Villiom Podlaski Christiansen
511c941422 prevent transient leaks of file handle by using new helper functions
These leaks may occur in environments that don't employ a reference
counting GC, i.e. PyPy.

This implies:
 - changing opener(...).read() calls to opener.read(...)
 - changing opener(...).write() calls to opener.write(...)
 - changing open(...).read(...) to util.readfile(...)
 - changing open(...).write(...) to util.writefile(...)
2011-05-02 10:11:18 +02:00
Bernhard Leiner
baf797018e revset: report a parse error if a revset is not parsed completely (issue2654) 2011-03-16 23:09:14 +01:00
Matt Mackall
a892ad5a23 templater: clarify engine caching 2010-12-22 13:16:03 -06:00
Matt Mackall
0b9296f805 templater: use the parser.py parser to extend the templater syntax 2010-12-20 12:09:00 -06:00
Matt Mackall
39437f5a68 templater: give slightly nicer error for unknown map entries 2010-12-20 12:09:00 -06:00
Wagner Bruna
40109aa29c templater: fix variable name
'format' was renamed to 'parsed' in ec66346c8238
2010-11-18 19:52:58 -02:00
Dan Villiom Podlaski Christiansen
a1632cd61b templater: add a few comments. 2010-09-21 23:55:32 +02:00
Dirkjan Ochtman
64bb18f0dd cleanups: undefined variables 2010-06-08 09:30:45 +02:00
Matt Mackall
bb539b800d templater: drop \ when handling escaped { 2010-04-05 15:25:08 -05:00
Matt Mackall
d5c8978fe3 templater: strip whitespace inside template methods 2010-04-05 15:25:08 -05:00
Matt Mackall
0c19c19e10 templater: drop raw method 2010-04-05 15:25:08 -05:00
Matt Mackall
484c6d04d0 templater: raise nested functions 2010-04-05 15:25:08 -05:00
Matt Mackall
92fd5b132b templater: use recursive flattening
This avoids slow list operations compared to the iterative version
2010-04-05 15:25:08 -05:00
Matt Mackall
7e256edce5 templater: cache self.defaults.get 2010-04-05 15:25:08 -05:00
Matt Mackall
39b48fa1ce templater: privatize class variables 2010-04-05 15:25:08 -05:00
Matt Mackall
8d0693deb8 templater: map -> mapping 2010-04-05 15:25:08 -05:00
Matt Mackall
7834a75f92 templater: extend preparsing
preparse filters and formats and supply functions to apply
2010-04-05 15:25:08 -05:00
Matt Mackall
cefead81fd templater: preparse templates and cache
This breaks templates down into a list of literal and {} groups, with
group types preidentified.
2010-04-05 15:25:08 -05:00
Matt Mackall
7455c67fcd templater: directly parse templates, no regexes 2010-04-05 14:33:41 -05:00
Benoit Boissinot
4371f512b2 fix spaces/identation issues 2010-02-05 18:50:08 +01:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -06:00
Matt Mackall
cd3ef170f7 Merge with stable 2010-01-19 22:45:09 -06:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Dirkjan Ochtman
c93b170e46 hgweb: don't choke when an inexistent style is requested (issue1901) 2009-11-12 16:39:11 +01:00
Dirkjan Ochtman
2f2b5e0e4f templater: remove support for ## template variables 2009-08-20 10:41:56 +02:00
Patrick Mezard
f32df1c921 Make {file_copies} usable as a --template key
Before this, to display file copies in templates, you had to write something
like {file_copies%filecopy}. For some reason, the {file_copy} subtemplate was
used by default but not defined by default in changeset_templater, while styles
were already using it. Here we define {file_copy} in changeset_templater, and
change the templater to handle formatting strings like {file_copies%filecopy}
with already expanded keys (in this case {file_copies}), for backward
compatibility.
2009-12-13 18:06:24 +01:00
Martin Geisler
e651951731 templater: lowercase error message
Changing this messages should be safe: automated scripts ought to have
debugged their templates and wont grep for this error message.
2009-05-17 16:25:48 +02:00
Matt Mackall
cfe14089d0 templater: replace eval with closure 2009-05-17 18:17:04 -05:00
Dirkjan Ochtman
140e5350fc templater: keep a cache of Python functions for filter expressions 2009-05-17 16:08:47 +02:00
Dirkjan Ochtman
56f023f70e templater: replace regex complexity by simple str containment checks 2009-05-17 16:06:48 +02:00
Dirkjan Ochtman
f421494a6a templater: clean up the process method, separating code paths 2009-05-17 16:05:50 +02:00
Dirkjan Ochtman
43d9564cff some modernization cleanups, forward compatibility 2009-05-13 14:08:39 +02:00
Dirkjan Ochtman
6f7f8e3dec templater: make the templating engine pluggable to some extent 2009-05-12 12:05:19 +02:00
Dirkjan Ochtman
5c6c43b746 templater: provide the standard template filters by default 2009-05-12 12:04:05 +02:00
Simon Heimberg
09ac1e6c92 separate import lines from mercurial and general python modules 2009-04-28 17:40:46 +02:00
Martin Geisler
750183bdad updated license to be explicit about GPL version 2 2009-04-26 01:08:54 +02:00
Dirkjan Ochtman
6bfc24b2af templater: fix little problem from stylemap() changes 2009-04-27 16:26:31 +02:00
Dirkjan Ochtman
388d357896 templater: separate template management and actual string processing 2009-04-06 15:09:54 +02:00
Matt Mackall
86dab18ddb config: getsource -> source 2009-04-26 16:50:43 -05:00
Matt Mackall
581beec905 templater: use new config parser
This gives us the ability to use includes and continuations
2009-04-26 16:50:43 -05:00
Dirkjan Ochtman
23935afdfe templatefilters: strings are iterators, but shouldn't be joined anyway 2009-04-06 16:26:57 +02:00
Dirkjan Ochtman
0b1a57839b templater: move stylemap function from hgweb to templater 2009-04-04 17:46:11 +02:00
Dirkjan Ochtman
d963dd0023 kill some trailing spaces 2008-11-27 16:07:13 +01:00
Brendan Cully
f4cee1477f templater: return data in increasing chunk sizes
Currently hgweb is not streaming its output -- it accumulates the
entire response before sending it. This patch restores streaming
behaviour. To avoid having to synchronously write many tiny fragments,
this patch also adds buffering to the template generator. Local
testing of a fetch of a 100,000 line file with wget produces a slight
slowdown overall (up from 6.5 seconds to 7.2 seconds), but instead of
waiting 6 seconds for headers to arrive, output begins immediately.
2008-11-21 15:51:40 -08:00
Brendan Cully
34868ca5be Allow hgweb to search for templates in more than one path.
This patch is constructed to make it easy for external extensions to
provide their own templates, by updating templater.path.
2008-10-17 11:34:31 -07:00
Dirkjan Ochtman
b79ad5315b templater: make a template a string-only iterator 2008-06-29 13:16:25 +02:00
Matt Mackall
1cca88367c hgweb: minor improvements for new web style
- make renamelink take a context
- pass current node to shortlog page rather than tip
- pass user/desc/date/rename to filediff
- improve template error reporting for foo%bar
2008-03-31 21:49:33 -05:00
Dirkjan Ochtman
c9f3b5991c give better error message on non-existent mapfile (issue813) 2008-03-21 12:05:01 +01:00
Matt Mackall
41e5c79455 templates: move filters to their own module
This eliminates just about all Mercurial dependencies in templater.py
2008-01-31 14:44:19 -06:00
Matt Mackall
a849fab9e4 templater: move email function to util 2008-01-31 14:44:19 -06:00
Matt Mackall
7b0d46c8cd templater: remove node import 2008-01-31 14:44:19 -06:00
Christian Ebert
5c18a69d2e Prefer i in d over d.has_key(i) 2008-01-20 14:39:25 +01:00
Robert Bachmann
ecb337b8cb Added support for the Atom syndication format 2007-08-30 16:42:17 +02:00
Alexis S. L. Carvalho
f9b8c79d22 hgweb: use lrwxrwxrwx as the permissions of a symlink 2007-07-03 03:06:40 -03:00
Matt Mackall
e293a4cd6d Merge with stable 2007-04-10 14:05:15 -05:00
TK Soh
424b1a050d minor typo fix in templater's docstring 2007-04-10 12:24:28 -05:00
Alexis S. L. Carvalho
d725a42fd8 merge with crew-stable 2006-12-16 02:51:16 -02:00
Alexis S. L. Carvalho
2726e242c0 templater.py: fix obfuscate 2006-12-16 02:21:46 -02:00
Matt Mackall
296d6a7cb8 Simplify i18n imports 2006-12-14 20:25:19 -06:00
Matt Mackall
f17a4e1934 Replace demandload with new demandimport 2006-12-13 13:27:09 -06:00
Matt Mackall
2fe74d8035 further simplify stringify 2006-11-15 15:51:58 -06:00
Matt Mackall
c50c09da0a templates: move changeset templating bits to cmdutils 2006-11-13 13:26:57 -06:00
Matt Mackall
6950309cf6 templater: changeset templater reorganization and optimizations 2006-11-13 13:26:57 -06:00
Matt Mackall
e0d8e4b198 templater: speed up changeset writes and stringify 2006-11-13 13:26:57 -06:00
Matt Mackall
9d8ded34e9 changeset_templater: remove changes arg 2006-11-13 13:26:57 -06:00
Matt Mackall
5c95b0e092 templater: simplify parsestring 2006-11-13 13:26:57 -06:00
Matt Mackall
c517977e84 template: fold template() into __call__, minor optimizations
- use non-grouping operator to avoid some extra processing
- avoid copying and updating defaults
- unnest main template body
- avoid returning extra empty string if format
2006-11-13 13:26:57 -06:00
Matt Mackall
6fe92f16bb templater: simplify cache and remove filter argument in __call__ 2006-11-13 13:26:57 -06:00
Matt Mackall
1b0a187e45 templater: simplify template function 2006-11-13 13:26:57 -06:00
Matt Mackall
aceb3199d6 templater: take cStringIO out of indent 2006-11-13 13:26:57 -06:00
Matt Mackall
3c62f52384 templater: remove cStringIO from stringify 2006-11-13 13:26:57 -06:00
Matt Mackall
00715e3a82 templater: remove cStringIO for fill 2006-11-13 13:26:57 -06:00
Matt Mackall
4fe7850499 templater: use str.decode in parse_string 2006-11-13 13:26:57 -06:00
Thomas Arendsen Hein
a67b9554ca Added extra changeset info to templater and map-cmdline.default. 2006-10-18 18:09:32 +02:00
Thomas Arendsen Hein
affb901953 Add new branch info to templater and use it in map-cmdline.default.
The template currently shows old (hg log -b style) branch tags, too,
but not in the same way as the built in changeset_printer.
2006-10-18 17:58:51 +02:00
Thomas Arendsen Hein
9e595ef83b templater: Better exception for errors in foo%bar formatting. 2006-10-11 20:53:02 +02:00
Brendan Cully
b5fb63f535 Templater expects an iterable copies variable (fixes notify). 2006-09-29 18:17:29 -07:00
Brendan Cully
d1c28696d4 Show copies in hg log.
The format is:
copies: destination (source)...
2006-09-29 13:01:19 -07:00
Vadim Gelfer
80d6f2f7c7 remove localrepository.changes.
use localrepository.status instead.
2006-08-12 16:40:12 -07:00
Brendan Cully
86244f1a64 Preserve multibyte UTF-8 characters when obfuscating.
This version uses the unicode 'replace' option, so non-UTF-8
encodings will still be mangled. Luckily, there aren't any
of those.
2006-07-21 02:36:17 +02:00
Brendan Cully
40833b0f4d templater.firstline should handle empty strings 2006-07-04 15:36:05 -07:00
Thomas Arendsen Hein
693aaef4a8 Merged WSGI fixes from http://hg.omnifarious.org/~hopper/webmerc/ 2006-06-30 21:36:45 +02:00
Benoit Boissinot
e2896f54f1 add a new template function 'hgdate'
'hgdate' turns a date into a cset timestamp as printed by 'hg export'
2006-06-30 10:15:18 +02:00
Eric Hopper
cbbc59972c Arrange for old copies of CGI scripts to still work. 2006-06-29 19:06:18 -07:00
Vadim Gelfer
9a0c813fdc use demandload more. 2006-06-20 23:58:21 -07:00
Vadim Gelfer
9a2b3a6303 make templater.stringio a tiny bit more use. 2006-05-04 14:45:57 -07:00
Vadim Gelfer
c40534f466 move stringio class from bugzilla extension into templater module. 2006-05-04 12:02:32 -07:00
Vadim Gelfer
b30de1431a make templater bit more flexible and efficient for external users. 2006-05-03 14:35:17 -07:00
Vadim Gelfer
f6f81d8d37 move changeset_templater into templater module. 2006-05-03 10:25:28 -07:00
Lee Cantey
da54525c97 Windows py2exe version didn't handle names given to templatepath() correctly 2006-03-24 10:33:18 -08:00
Vadim Gelfer
2e0f1be283 add changelog style to command line template.
to use, "hg log --style=changelog".  makes different output with no
flags, -q, -v, --debug.

templater module has new template filters for this.
email - committer email address
fill68 - refill text to 68 colums
fill76 - refill text to 76 colums
tabindent - prefix every not empty line with tab
shortdate - iso 8631 date, no time zone
stringify - turn template iterator into string
2006-03-21 23:29:21 -08:00
Shun-ichi Goto
9730814eb2 Duplicate cache when creating templater. 2006-03-18 09:51:25 -08:00
Vadim Gelfer
d737c6c2b3 fix template bug that made hgweb break.
problem found by Shun-ichi Goto <shunichi.goto@gmail.com>.
this fix tested with command template and hgweb templates.
2006-03-15 11:28:00 -08:00
Shun-ichi GOTO
e268844d18 Fix the py2exe template path problem (issue:152) again.
This patch is same with 1834:d15fc6ce9d87 which is leaved behind by
1897:d8f0b3f8f638.
2006-03-15 06:39:04 +01:00
Vadim Gelfer
49cb97855a make --style=compact look for map-cmdline.compact.
change name of key in map file from changelog to changeset.
rename command map files to start with map-cmdline.
rename ui.logmap to ui.style in hgrc.

now --style=foo does this:
tries to open foo as file.
tries as map-cmdline.foo in template path.
tries as foo in template path.
2006-03-04 15:15:18 -08:00
Vadim Gelfer
5de8501662 fix some things people wanted to be cleaner.
rename --map-file to --style.
no more -t alias for --template.
update docs.
rename template entry in map files to changelog.
if --verbose, use changelog_verbose if there, else changelog.
2006-03-04 12:40:10 -08:00
Vadim Gelfer
8f15689d73 hide some functions behind lambdas, so demandload is useful. 2006-02-28 07:24:54 -08:00
Vadim Gelfer
9640cecf04 add doc comments to template code. 2006-02-27 15:07:25 -08:00
Vadim Gelfer
1a7e33442f add iso date template filter. 2006-02-27 12:50:49 -08:00
Vadim Gelfer
21aff25a2a improve template errors when something is wrong. 2006-02-27 12:41:20 -08:00
Vadim Gelfer
94422c87f2 improve templating.
allow {foo} as well as #foo#.
add new functions for changeset authors.
2006-02-27 11:33:09 -08:00
Vadim Gelfer
957bd7ed50 make parsestring work with strings that do not have quotes. 2006-02-27 11:18:56 -08:00
Vadim Gelfer
e8d01e14ea use safer string parser for template engine. 2006-02-27 09:35:43 -08:00
Vadim Gelfer
41badccf28 move repeated work out of inner loops. 2006-02-27 09:15:59 -08:00
Vadim Gelfer
9f0cbe341c many small changes to templater.
get string code to parse escapes. uses eval now, should parse strings
itself soon.

let caller check if fragment is defined using "in".

make templatepath take optional file name.
2006-02-26 20:53:37 -08:00
Vadim Gelfer
1db1ed4f1f move hgweb.templatepath into templater 2006-02-26 13:09:26 -08:00
Vadim Gelfer
5b07616ef3 move hgweb template code out to templater 2006-02-26 12:59:28 -08:00