Commit Graph

117 Commits

Author SHA1 Message Date
Yuya Nishihara
14174e42d0 templatekw: change _showlist() to take mapping dict with no **kwargs expansion
There was a risk that a template keyword could conflict with an argument
name (e.g. 'name', 'values', 'plural', etc.) Let's make it less magical.
2017-04-05 21:40:38 +09:00
Yuya Nishihara
e7f0402cb5 templatekw: rename 'args' to 'mapping' in showlist()
The name 'args' provides no information. Call it 'mapping' as in templater.py.
2017-04-05 21:32:32 +09:00
Yuya Nishihara
ae7c681de5 templatekw: eliminate unnecessary temporary variable 'names' from _showlist()
Replace 'names' with the optional argument 'plural'.
2017-04-05 21:27:44 +09:00
Yuya Nishihara
2274942817 templatekw: add public function to wrap a dict by _hybrid object 2017-04-05 22:28:09 +09:00
Yuya Nishihara
f8dcd91891 templatekw: add public function to wrap a list by _hybrid object 2017-04-05 22:25:36 +09:00
Yuya Nishihara
17d1580914 templatekw: add default implementation of _hybrid.gen
This is convenient for new template keyword, which doesn't need to support
the legacy list hack (provided by _showlist()), but still wants to have
a string representation.
2017-04-12 21:10:47 +09:00
Yuya Nishihara
0aa51ecaec templater: make _hybrid provide more list/dict-like methods
So the JSON filter works.
2017-04-04 22:31:59 +09:00
Yuya Nishihara
e6e5ca157b templater: hide private variable of _hybrid 2017-04-04 22:20:06 +09:00
Yuya Nishihara
e6ea93a8d4 templater: remove __iter__() from _hybrid, resolve it explicitly
The goal is to fix "{hybrid_obj|json}" output.

A _hybrid object must act as a list or a dict as well as a generator of
legacy template strings. Before, _hybrid.__iter__() was assigned for legacy
template, which conflicted with list.__iter__() API.

This patch drops _hybrid.__iter__() and makes stringify/flatten functions
unwrap a generator instead.
2017-04-04 22:19:02 +09:00
Yuya Nishihara
606d44c4d1 templater: rewrite doc of _hybrid class as docstring 2016-04-24 19:15:34 +09:00
Matt Harbison
6376502430 templatekw: clarify the result of {latesttag} when no tag exists
My initial expectation was that the list would be empty, and therefore
detectable with {if()}.  The map for {latesttag()} is populated with real values
in this case (except {tag}), so it probably doesn't make any sense to change
this to an empty list.
2017-04-09 00:10:54 -04:00
Yuya Nishihara
caee220313 templater: provide loop counter as "index" keyword
This was originally written for JSON templating where we would have to be
careful to not add extra comma, but seems generally useful.

Inner loop started by % operator has its own counter.
2016-04-22 21:46:33 +09:00
Denis Laxalde
5f616436cb templatekw: add an "obsolete" keyword
Definition is the same as the one in evolve extension.
2017-03-25 10:34:11 +01:00
Yuya Nishihara
5ce2afb81d templatekw: make join() escape values of extras (BC) (issue5504)
Since extras may contain blob, the default template escapes its values:

  'extra': '{key}={value|stringescape}'

join() should follow the output style of the default template.
2017-03-15 23:21:30 +09:00
Yuya Nishihara
a69b51cf89 templatekw: move defaulttmpl constant from changeset_templater
These templates are used when rendering inner lists of some template keywords,
so it makes sense to define them in templatekw. This allows us to reuse them
to create a templateformatter knowing changectx.
2017-02-25 16:38:26 +09:00
Matt Harbison
511b164fad templater: add '{envvars}' to access environment variables
Since the option for ui.exportableenviron is experimental, so is this template
until the underlying API is sorted out.
2017-01-17 23:12:54 -05:00
Matthieu Laneuville
1146ca6217 templatekw: force noprefix=False to insure diffstat consistency (issue4755)
The result of diffstatdata should not depend on having noprefix set or not, as
was reported in issue 4755. Forcing noprefix to false on call makes sure the
parser receives the diff in the correct format and returns the proper result.

Another way to fix this would have been to change the regular expressions in
path.diffstatdata(), but that would have introduced many unecessary special
cases.
2017-01-12 21:06:55 +09:00
Denis Laxalde
0c89f1cb3e templatekw: add a "troubles" template keyword
The "troubles" template keyword returns a list of evolution troubles.
It is EXPERIMENTAL, as anything else related to changeset evolution.

Test it in test-obsolete.t which has troubled changesets.
2017-01-06 13:50:16 +01:00
Durham Goode
52b8095f37 manifest: remove last uses of repo.manifest
Now that all the functionality has been moved to manifestlog/manifestrevlog/etc,
we can finally change all the uses of repo.manifest to use the new versions. A
future diff will then delete repo.manifest.

One additional change in this commit is to change repo.manifestlog to be a
@storecache property instead of @property. This is required by some uses of
repo.manifest require that it be settable (contrib/perf.py and the static http
server). We can't do this in a prior change because we can't use @storecache on
this until repo.manifest is no longer used anywhere.
2016-11-10 02:13:19 -08:00
Simon Farnsworth
c7fbc87ac7 template: provide a termwidth keyword (issue5395)
We want to provide terminal-sized output. As a starting point, expose the
terminal width to the templater for use in things like fill.
2016-10-08 02:26:48 -07:00
Yuya Nishihara
bd360299a6 templatekw: change joinfmt to a mandatory argument of _hybrid object
We've fixed several bugs caused by the misuse of the default joinfmt. Make
it more explicit to prevent future bugs.

dict.values()[0] is replaced by dict[element] as showlist() knows what the
key is.
2016-07-23 13:08:43 +09:00
Yuya Nishihara
1c24b2522b templatekw: fix join format of parents keyword (issue5292)
Since the default joinfmt() can't process a dict of multiple keywords, we
need a dedicated joinfmt for showparents().

Unlike revset(), parents are formatted as '{rev}:{node|formatnode}' by default.
We copy the default formatting just like showextras() and showfilecopies() do.
2016-07-22 22:12:12 +09:00
Yuya Nishihara
9bf038789f templatekw: fix join format of revset() function
It's been broken since eef3c19484ca, which made makemap() return a dict of
multiple keywords. Because the default joinfmt() randomly picks one item
from a dict, we have to make revset() select d[name] explicitly.
2016-07-22 22:00:46 +09:00
FUJIWARA Katsunori
26097c8fbe templatekw: use templatekeyword to mark a function as template keyword
Using decorator can localize changes for adding (or removing) a
template keyword function in source code.

This patch also removes leading ":KEYWORD:" part in help document of
each keywords, because using templatekeyword makes it useless.

For similarity to decorator introduced by subsequent patches, this
patch uses 'templatekeyword' instead of 'keyword' as a decorator name,
even though the former is a little redundant in 'templatekw.py'.

    file                name              reason
    =================== ================= ==================================
    templatekw.py       templatekeyword   for similarity to others
    templatefilters.py  templatefilter    'filter' hides Python built-in one
    templaters.py       templatefunc      'func' is too generic
2016-03-13 05:17:06 +09:00
FUJIWARA Katsunori
adbb470b46 registrar: add templatekeyword to mark a function as template keyword (API)
_templateregistrarbase is defined as a super class of templatekeyword,
for ease of adding template common features between "keyword",
"filter" and "function".

This patch also adds loadkeyword() to templatekw, because this
combination helps to figure out how they cooperate with each other.

Listing up loadkeyword() in dispatch.extraloaders causes implicit
loading template keyword functions at loading (3rd party) extension.

This change requires that "templatekeyword" attribute of (3rd party)
extension is registrar.templatekeyword or so.
2016-03-13 05:17:06 +09:00
Yuya Nishihara
d1e05b5ef3 templatekw: switch ctx of list expression to rev of {parents} (BC)
This is the same semantics as revset() introduced at eef3c19484ca. Before
this patch, {parents} provided nothing useful in new-style template. For
example, '{parents % "{parent}"}' generated cryptic string like
"rev12345node0123abcdef...".

This patch drops {parent} variable since it was useless. We can get a revision
number by '{parents % "{rev}"}'.
2016-02-12 19:16:09 +09:00
Yuya Nishihara
5a1fcf8c16 templatekw: workaround for utf-8 round-trip of {desc}
Though our encoding strategy is best effort, {desc} is a primitive keyword
that should be worth enough to try hard to preserve UTF-8 bytes.
2015-12-27 20:21:37 +09:00
Yuya Nishihara
e51bed3d10 templater: factor out type conversion of revset() result
This makes it clear why we have to do repo[int(x)].
2016-02-12 18:39:48 +09:00
Yuya Nishihara
b9ea9debff templater: evaluate each item of revset() as integer revision
Because templater.revset() returns a list of strings, repo["-1"] was mapped to
the tipmost revision. Ideally, we should make revset() return a list of integer
revisions, but it turned out not simple. If revset() is a list of integers,
"{ifcontains(rev, revset(), ...)}" would fail because "ifcontains" casts "rev"
to a string.

So this patch just converts a string back to an integer revision.
2016-02-12 18:08:53 +09:00
Yuya Nishihara
c998aff68a templatekw: add {namespaces} keyword
This provides a general-purpose interface to all custom namespaces.

The {namespaces} keyword honors the definition order of namespaces as they
are kept by sortdict.
2016-01-12 23:56:48 +09:00
Yuya Nishihara
dbf185d983 templatekw: move shownames() helper to be sorted alphabetically
I'll add shownamespaces(), which is similar to this function. I want to put
them nearby.
2016-01-12 23:53:56 +09:00
Yuya Nishihara
20aed11e76 templater: make _hybrid not callable to avoid conflicting semantics
In templater, a callable symbol exists for lazy evaluation, which should have
f(**mapping) signature. On the other hand, _hybrid.__call__(), which was
introduced by 4e182fb53989, generates mapping for each element.

This patch renames _hybrid.__call__() to _hybrid.itermaps() so that a _hybrid
object can be a value of a mapping dict.

  {namespaces % "{namespace}: {names % "{name }"}\n"}
                               ~~~~~
                               a _hybrid object
2016-01-16 13:42:37 +09:00
Yuya Nishihara
e3b2f52bb0 templatekw: avoid slow creation of changectx objects in showgraphnode()
This mitigates the minor perf regression introduced by the previous patch.

  % hg log -G -R mozilla-central -l10000 --time > /dev/null
  (original) real 2.200 secs
  (previous) real 2.590 secs
  (this)     real 2.280 secs
2015-11-14 17:02:57 +09:00
Yuya Nishihara
f981890d2b graphlog: extract "graphnode" template keyword that represents node symbol
This provides a default node symbol. Tests will be added later.

"showparents" variable is renamed to "wpnodes" to avoid confusion with the
existing showparents() function.
2015-11-14 16:58:18 +09:00
Matt Harbison
06f8907a59 templatekw: add {changes}, {distance} and {tag} to the {latesttag} keyword 2015-08-24 23:30:17 -04:00
Matt Harbison
c5687426b2 templatekw: introduce showlatesttags() to handle {latesttag} keywords
The keywords {changes}, {distance} and {tag} will be available on a future
template method that will allow pattern matching against tag names.  For
consistency, these should be available on the existing {latesttag} keyword as
well.

I debated whether or not to add {tag} instead of just continuing with the
existing {latesttag}.  But it seems clearer not to have the same name for two
distinct things (a list in the LHS of %, and an individual tag value on the
right).

The value of latesttags[0] is the date of commit for the cset to which the tag
is applied (i.e. not the date the tag was applied), and therefore isn't made
visible because it doesn't seem interesting.  It appears that this is merely an
internal implementation detail for sorting csets in a stable manner when there
are different branches.
2015-08-24 23:07:00 -04:00
Matt Harbison
b225c29685 templatekw: factor out the changessincetag calculation to a private method
This will be reused in the next patch.
2015-10-05 21:11:50 -04:00
Matt Harbison
6a5f5d55b0 templatekw: allow getlatesttags() to match a specific tag pattern
This will allow the latest class of tag to be found, such as a release candidate
or final build, instead of just the absolute latest.  It will be exposed in a
future patch.

It's unfortunate that the original 'latesttags' cache can't be used to determine
the proper values, but it isn't fully populated for the entire repo.  For
example, the {latesttagdistance} keyword on the Mecurial repo builds the cache
up back to the revision for 1.4.  If the pattern was 're:^0\.\d$', that wouldn't
be in the cache.  Maybe this can be optimized some other way, but for now, this
is the simpliest implementation.
2015-08-23 23:22:55 -04:00
Yuya Nishihara
445fb293ff templatekw: hide help of "branches" by DEPRECATED marker
See 6bfcc0d9d2a0 for details.
2015-09-26 12:19:39 +09:00
Yuya Nishihara
897f0202e7 templatekw: remove dockeywords hack
Now all template keywords are defined as real functions.
2015-09-26 12:39:13 +09:00
Yuya Nishihara
dc974fcbf0 templatekw: port implementation of showparents() from changeset_templater
It isn't cool, but we can peek at ui flag via repo.ui. So, it is possible
to implement showparents() in templatekw, and therefore we can eliminate the
dockeywords hack.
2015-09-26 12:38:02 +09:00
Yuya Nishihara
26bfa27542 templatekw: reorder stub of showparents() function
It will have an implementation.
2015-09-26 12:32:03 +09:00
Yuya Nishihara
80896f8bec templater: switch ctx of list expression to rev of revset() (BC)
Because revset() function generates a list of revisions, it seems sensible
to switch the ctx as well where a list expression will be evaluated. I think
"{revset(...) % "..."}" expression wasn't considered well when it was
introduced at 45e0e191755f.
2015-09-12 00:21:41 +09:00
Gregory Szorc
36c361086a templatekw: use absolute_import 2015-08-08 20:09:43 -07:00
Yuya Nishihara
2f4ec7df91 templatekw: make {rev} return wdirrev instead of None
wdirrev/wdirnode identifiers are still experimental, but {node} is mapped to
wdirnode. So {rev} should do the same for consistency.

I'm not sure if templatekw can import scmutil. If not, we should move intrev()
to node module.
2015-07-02 22:18:21 +09:00
Yuya Nishihara
950db6aab2 templatekw: apply manifest template only if ctx.manifestnode() exists
This will prevent crash by "hg log -r 'wdir()' -Tdefault". We could use the
pseudo ff... hash introduced by 187c3ec3d83f, but it isn't proven idea yet.
For now, I want to make "hg log" just works in order to test 'wdir()' revset.

Note that unlike its name, "{manifest}" is not a list of files in that
revision, but a pair of (manifestrev, manifestnode).
2015-03-14 17:58:18 +09:00
Matt Harbison
edbaac787d templatekw: make {latesttag} a hybrid list
This maintains the previous behavior of expanding {latesttag} to a string
containing all of the tags, joined by ':'.  But now it also allows list type
operations.

I'm unsure if the plural handling is correct (i.e. it seems like it is usually
"{foos % '{foo}'}"), but I guess we are stuck with this because the singular
form previously existed.
2015-07-06 23:23:22 -04:00
Matt Harbison
bf6ad84ffa templatekw: allow the caller of showlist() to specify the join() separator
The keyword {latesttag} currently manually joins the list of tags using ':',
which prevents a transparent switch over to a hybrid list.
2015-07-06 23:12:24 -04:00
Matt Harbison
9e00498f91 templatekw: introduce the changessincelatesttag keyword
Archive is putting a value with the same name in the metadata file, to count all
of the changes not covered by the latest tag, instead of just along the longest
path.  It seems that this would be useful to have on the command line as well.
It might be nice for the name to start with 'latesttag' so that it is grouped
with the other tag keywords, but I can't think of a better name.

The initial version of this counted a clean wdir() and '.' as the same value,
and a dirty wdir() as the same value after it is committed.  Yuya objected on
the grounds of consistency [1].  Since revsets can be used to conditionally
select a dirty wdir() or '.' when clean, I can build the version string I need
and will defer to him on this.

[1] https://www.selenic.com/pipermail/mercurial-devel/2015-June/071588.html
2015-06-26 23:11:05 -04:00
Matt Harbison
1147e2bdb5 templatekw: use a list of tags in getlatesttags() instead of joining them
This will be used in the next patch.

It also points out that the documentation for '{latesttag}' is not quite
accurate, since it says "most recent global tag" (singular).  I assume it is too
radical of a change to convert it to a list of strings.  At least ':' is
currently a reserved character in tag names.
2015-06-26 23:23:10 -04:00