Commit Graph

82 Commits

Author SHA1 Message Date
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
Yuya Nishihara
a861e28d3d templatekw: give name to lambda that constructs variables map of templater
The constructed list is useless for "ifcontains()" and "get()". Instead,
makemap() and raw dict will be passed to _hybrid object.
2015-03-08 14:38:50 +09:00
Yuya Nishihara
e4dfa9d6a0 templatekw: convert list of key/value pairs to sortdict
These sortdict objects will be passed to _hybrid later, which will allow
us to handle them by "ifcontains()" and "get()" as expected.
2015-03-08 14:17:35 +09:00
Yuya Nishihara
4c5195bbaa templatekw: fix {join(bookmarks, sep)} to always show associated bookmarks
The default joinfmt, "x.values()[0]", can't be used here because it picks
either 'bookmark' or 'current' randomly.

I got wrong result with PYTHONHASHSEED=1 on my amd64 machine.
2015-02-18 22:17:35 +09:00
Yuya Nishihara
80c7f8aa9b templatekw: inline showlist() into showbookmarks()
showlist() is the helper to build _hybrid object from a trivial list. It can't
be applied if each value has more than one items, 'bookmark' and 'current' in
this case.

This change is necessary to fix random failure of "{join(bookmarks, sep)}".
2015-02-18 22:10:17 +09:00
FUJIWARA Katsunori
beb57d53bc templatekw: re-add showtags() to list tags keyword up in online help
Changeset 427a0ac924e4 removed "showtags()" definition for "tags"
template keyword from "templatekw.py", because "namespaces" puts a
helper function for it into template keyword map automatically. This
works correctly from the point of view of templating functionality.

But on the other hand, it removed "tags" template keyword from "hg
help templates" unexpectedly, because online help text is built before
"namespaces" puts a helper function for "tags" into template keyword
map.

This patch is a kind of backing 427a0ac924e4 out, but this implements
"showtags()" with newly introduced "shownames()" instead of originally
used "showlist()".
2015-02-01 09:36:47 +09:00
Sean Farley
2ab14b992b templatekw: update namespace calls
Previous patches changed the namespace api to be more of an object-oriented
approach. This patch updates the template function to use said api changes.
2014-12-21 14:01:52 -08:00
Sean Farley
cc2595a676 templatekw: remove unneeded showtags
Now that we have the machinery of namespaces in-place, we use that instead of
hand-rolling our own template function.

Note, this can only be used for tags because both branches and bookmarks have
special case logic for 'default' and the current bookmark (which is something
outside the namespace api for now).
2014-12-15 09:40:02 -08:00
Sean Farley
bb554af3db templatekw: add helper method to generate a template keyword for a namespace
This marks our second feature of the namespace api: automatic template keyword.
This patch adds a method that takes in a namespace and uses the node-to-name
map to output the list of names.
2014-12-14 19:15:37 -08:00
Anton Shestakov
c4f325bd82 templater: implement __len__ for _hybrid
Objects of class _hybrid are returned by such template keywords as children,
bookmarks, tags and others, and also by revset() template function. They are
representing "list of strings" (as hg help template says) for use in templates.
So it would be logical to implement a handy way to count the number of strings
in such list, and that's what __len__ method does.
2014-09-08 20:12:58 +09:00
FUJIWARA Katsunori
f09e7bc4c8 templatekw: add 'subrepos' keyword to show updated subrepositories
'subrepos' template keyword newly added by this patch shows updated
subrepositories.

For the compatibility with the list of subrepositories shown in the
editor at commit:

  - 'subrepos' is empty, at revisions removing '.hgsub' itself

  - 'subrepos' is calculated between the revision and the first parent
    of it, at merge revisions

To avoid silent regression, this patch also confirms "hg diff" of
".hgsubstate" and parents for each target revisions in the test.
2014-07-15 23:34:13 +09:00
FUJIWARA Katsunori
843d08c987 templatekw: add 'currentbookmark' keyword to show current bookmark easily
Before this patch, complicated template expression below is required
to show current active bookmark if it is associated with the
changeset.

    "{bookmarks % '{ifeq(bookmark, current, \"{bookmark}\")}'}"

This patch add 'currentbookmark' keyword to show current bookmark
easily.
2014-07-15 23:34:13 +09:00
Augie Fackler
f8666738b4 templatekw: move from dict() construction to {} literals
The latter are both faster and more consistent across Python 2 and 3.
2014-03-12 13:20:42 -04:00
Durham Goode
2d869e6a8e template: add 'current' to scope during {bookmarks % ...}
This adds the keyword 'current' to the template scope when processing a
bookmark list. The 'current' keyword resolves to the name of the currently
active bookmark in the repo. This allows us to apply special labels to the
current bookmark to distinguish it (especially in the case where there are
multiple bookmarks on the same commit).

Example: "{bookmarks % '{bookmark}{ifeq(bookmark, current, \"*\")} '}"

Results in a space separated list of bookmarks where the current bookmark has
an asterix.
2014-02-11 21:40:33 -08:00
Andrew Shadura
88eaae271b templatekw: allow tagtypes other than global in getlatesttags
hg-git uses tagtype 'git', for example, so it's better
to check for tagtype != 'local', not strictly for 'global'
2013-12-23 14:14:31 +01:00
Matthew Turk
c0982bbb31 template: modify showextras to return a hybrid
This modifies slightly the behavior introduced in fcc482469a3c to allow
showextras to return a hybrid, rather than showlist.  The example in the
template help file now executes and returns meaningful results.
2013-11-21 15:46:49 -05:00
Matt Mackall
df890e8b8a merge with stable 2013-11-21 15:08:30 -06:00
Matt Mackall
1b2df1cd91 help: drop help for branches template keyword
The {branches} keyword dates to pre-1.0 Mercurial's tag-like branch
scheme which allowed changesets to be on multiple branches. This is
the last visible vestige of that scheme, users should instead be using
{branch}, possibly with if().
2013-11-21 11:49:31 -06:00
Matt Mackall
fb22d26dbd templater: makes branches work correctly with stringify (issue4108) 2013-11-21 11:30:52 -06:00
Matthew Turk
5493f40b2a template: change extras to use showlist rather than manual templ call.
This enables start_extras and end_extras in template maps.
2013-11-15 18:08:50 -05:00
Matthew Turk
3fa07ee864 help: document about {extras} template keyword
This adds text about the "extras" template keyword, similar to that proposed by
Yuya Nishihara previously.
2013-11-15 16:53:54 -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