Commit Graph

103 Commits

Author SHA1 Message Date
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
Matt Harbison
906e3d1b5d templatekw: correct typo in activebookmark documentation 2015-06-24 11:15:00 -04:00
Matt Mackall
f0c000187c merge with stable 2015-06-01 14:47:02 -05:00
FUJIWARA Katsunori
1d5cc643a1 templatekw: compare target context and its parent exactly (issue4690)
Before this patch, template keywords `{file_mods}`, `{file_adds}` and
`{file_dels}` use values gotten by `repo.status(ctx.p1().node(),
ctx.node())`.

But this doesn't work as expected if `ctx` is `memctx` or
`workingcommitctx`. Typical case of templating with these contexts is
customization of the text shown in the commit message editor by
`[committemplate]` configuration.

In this case, `ctx.node()` returns None and it causes comparison
between `ctx.p1()` and `workingctx`. `workingctx` lists up all changed
files in the working directory even at selective committing.

BTW, `{files}` uses `ctx.files()` and it works as expected.

To compare target context and its parent exactly, this patch passes
`ctx.p1()` and `ctx` without `node()`-nize. This avoids unexpected
comparison with `workingctx`.

This patch uses a little redundant template configurations in
`test-commit.t`, but they are needed to avoid regression around
problems fixed by 17e2fda16f58 and 2b999bc2d89a: accessing on `ctx`
may break `ctx._status` field.
2015-06-02 02:28:33 +09:00
Ryan McElroy
9fa69b0d75 templatekw: display active bookmark more consistently (issue4552) (BC)
Previously, the template keyword '{activebookmark}' would only display the
active bookmark if it was also pointing to the working directory's parent.
Meanwhile, the '{active}' subkeyword of the '{bookmarks}' keyword displays
the active bookmark regardless of whether it also points to the working
directory's parent. This is confusing.

Consider the output of these two templates:

  $ hg log -T '{activebookmark}\n' -r indent

  $ hg log -T '{bookmarks % "{bookmark}"}\n' -r indent
  indent

This is the current behavior that can arise after, eg, a pull moves a bookmark
out from under you. After this patch, the first template will also return the
active bookmark that points to a revision, even if it is not the current
parent of the working directory. A test has been added to show the new behavior.
2015-04-15 09:07:54 -07:00
Ryan McElroy
7cd7aaf7a6 templatekw: introduce active subkeyword from bookmarks keyword
Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-05-28 20:03:42 -07:00
Yuya Nishihara
e4b8aeed9f templatekw: have {manifest} use ctx.manifestnode() for consistency
changeset_printer was updated at dbba1dc6a539 to not access changeset by
index.
2015-04-08 21:04:06 +09:00
Ryan McElroy
c8de25429e templatekw: introduce activebookmark keyword
Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-04-15 08:12:04 -07:00
Ryan McElroy
ecf5daf629 templatekw: rename variable current to active
Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-04-15 08:26:01 -07:00
Ryan McElroy
be754988cc bookmarks: simplify iscurrent to isactivewdirparent (API)
Previously this function accepted two optional parameters that were unused by
any callers and complicated the function.

Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-04-14 12:45:15 -07:00
Ryan McElroy
7a091e748f bookmarks: rename bookmarkcurrent to activebookmark (API)
Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-04-14 13:17:33 -07:00
Matt Harbison
229d34fc55 templater: replace 'ctx._repo' with 'ctx.repo()' 2015-03-12 23:11:15 -04:00
Yuya Nishihara
f407d33cc5 templatekw: forward _hybrid.get to raw values so that get(extras, key) works
fffa7616be9d implies that the primary goal is to allow "{get(extras, key)}",
but it didn't work.

I'm not sure if _hybrid should forward all unknown attributes to values, so
only "get" is forwarded for now.
2015-02-18 23:17:52 +09:00
Yuya Nishihara
3a37788d5b templater: implement _hybrid.__contains__ so that ifcontains can accept dict
7678263f920c is fine for "{revset()}", but "i.values()[0]" does not work if
each item has more than one values such as "{bookmarks}".

This fixes the problem by using list.__contains__ or dict.__contains__
appropriately.
2015-02-18 23:01:33 +09:00
Yuya Nishihara
5614b9665b templatekw: keep raw list or dict in _hybrid object
This will allow us to handle bookmarks, extras and copies properly in
"ifcontains()" and "get()".
2015-03-08 14:46:42 +09:00