Commit Graph

38 Commits

Author SHA1 Message Date
Gregory Szorc
6c60659b4c namespaces: record and expose whether namespace is built-in
Currently, the templating layer tends to treat each namespace
as a one-off, with explicit usage of {bookmarks}, {tags}, {branch},
etc instead of using {namespaces}. It would be really useful if
we could iterate over namespaces and operate on them generically.
However, some consumers may wish to differentiate namespaces by
whether they are built-in to core Mercurial or provided by extensions.
Expected use cases include ignoring non-built-in namespaces or
emitting a generic label for non-built-in namespaces.

This commit introduces an attribute on namespace instances
that says whether the namespace is "built-in" and then exposes
this to the templating layer.

As part of this, we implement a reusable extension for defining
custom names on each changeset for testing. A second consumer
will be introduced in a subsequent commit.
2017-06-24 14:52:15 -07:00
Augie Fackler
47e0320f8b cleanup: rename all iteritems methods to items and add iteritems alias
Due to a quirk of our module importer setup on Python 3, all calls and
definitions of methods named iteritems() get rewritten at import
time. Unfortunately, this means there's not a good portable way to
access these methods from non-module-loader'ed code like our unit
tests. This change fixes that, which also unblocks test-manifest.py
from passing under Python 3.

We don't presently define any itervalues methods, or we'd need to give
those similar treatment.
2017-05-29 00:00:02 -04:00
Martin von Zweigbergk
c3406ac3db cleanup: use set literals
We no longer support Python 2.6, so we can now use set literals.
2017-02-10 16:56:29 -08:00
timeless
4e41a3b214 namespaces: fix name/node confusion
There was a lot of copy/paste here.
2016-03-16 23:12:43 +00:00
Gregory Szorc
a38da2c56f namespaces: use absolute_import 2015-08-08 19:42:58 -07:00
Mads Kiilerich
b2b60414f6 spelling: fixes from proofreading of spell checker issues 2015-01-18 02:38:57 +01:00
FUJIWARA Katsunori
8a439b3cc6 revset: mask specific names for named() predicate
Before this patch, revset predicate "tag()" and "named('tags')" differ
from each other, because the former doesn't include "tip" but the
latter does.

For equivalence, "named('tags')" shouldn't include the revision
corresponded to "tip". But just removing "tip" from the "tags"
namespace causes breaking backward compatibility, even though "tip"
itself is planned to be eliminated, as mentioned below.

    http://selenic.com/pipermail/mercurial-devel/2015-February/066157.html

To mask specific names ("tip" in this case) for "named()" predicate,
this patch introduces "deprecated" into "namespaces", and makes
"named()" predicate examine whether each names are masked by the
namespace, to which they belong.

"named()" will really work correctly after 3.3.1 (see a3c326a7f57a for
detail), and fixing this on STABLE before 3.3.1 can prevent initial
users of "named()" from expecting "named('tags')" to include "tip".

It is reason why this patch is posted for STABLE, even though problem
itself isn't so serious.

This may have to be flagged as "(BC)", if applied on DEFAULT.
2015-02-05 14:45:49 +09:00
FUJIWARA Katsunori
e42765e252 namespace: introduce logfmt to show l10n-ed messages for hg log correctly
Before this patch, "_()" is used incorrectly for "tag:" and
"bookmark:" fields. "changeset_printer()" looks up keys composed at
runtime, and it prevents "xgettext" command from getting strings to be
translated from source files.

Then, *.po files merged with updated "hg.pot" lose msgids for "tag:"
and "bookmark:".

This patch introduces "logfmt" information into "namespace" to show
l10n-ed messages "hg log" (or "changeset_printer()") correctly.

For similarity to other namespaces, this patch specifies "logfmt" for
"branches" namespace, even though it isn't needed (branch information
is handled in "changeset_printer()" specially).

To find related code paths out easily, this patch adds "i18n: column
positioning ..."  comment to the line composing "logfmt" by default,
even though this line itself doesn't contain any strings to be
translated.
2015-01-28 22:22:59 +09:00
Sean Farley
8f432b351e namespaces: add colorname member to namespace object
Previously, there was no way to change the color label used for 'hg log'
output. This patch just adds the member to the object, a future patch will
change 'hg log' to use this.
2015-01-14 20:11:02 -08:00
Sean Farley
899d50e422 namespaces: add logname member to namespace object
Previously, there was no way to change the name used for 'hg log' output. This
was inconvenient for extensions that want a template name longer than 12
characters (e.g. remotebookmarks) but a different name for 'hg log'.

This patch only adds the member to the object, a future patch will update the
'hg log' code.
2015-01-14 20:06:44 -08:00
Sean Farley
6acd704926 namespaces: use named args for namespace api
This is just a style change but makes adding new arguments more robust for
callers.
2015-01-14 19:55:20 -08:00
Sean Farley
fe60a42bd6 namespaces: make the constructor into named args
None of the arguments are truly optional but this makes adding future arguments
more robust and perhaps optional.
2015-01-14 19:39:13 -08:00
Sean Farley
28f3ddd179 localrepo: add ignoremissing parameter to branchtip
Previously, in the namespaces api, the only caller of branchtip was singlenode
which happened to raise the same exception that branchtip raised: KeyError.

This is a minor change but will allow upcoming patches to use repo.branchtip to
not raise an exception if a branch doesn't exist. After that, it will be
possible for extensions to use the namespace api in a stable way.
2014-10-16 21:49:28 -07:00
Sean Farley
6bc9243ecb namespaces: add method to return a list of nodes for a given name
This is a helpful method that some extensions can make use of (e.g. for custom
revsets); currently not used in core.
2014-12-15 14:46:04 -08:00
Sean Farley
0891487d00 namespaces: add __iter__ and iteritems methods
Iterating over all the namespaces is a common operation, naturally, so we add
those methods now. Since we are using a sorted dictionary, this method just
calls the underlying __iter__ or iteritems method.
2014-12-22 09:07:37 -08:00
Sean Farley
c40032685e namespaces: add 'listnames' property
Currently, we have no way to list all the names in a given namespace. This is
needed for things such as tab completion. Future patches will use this patch
for exactly that purpose.
2014-12-15 14:09:00 -08:00
Sean Farley
fd5469b9b3 namespaces: remove templatename method on the namespaces object
Now that there is an object for each individual namespace, we use the
templatename property on that object instead of the method on the collection of
namespaces.
2014-12-21 14:34:07 -08:00
Sean Farley
2d1b575fbb namespaces: remove names method on the namespaces object
Now that there is an object for each individual namespace, we use that instead
of the method on the collection of namespaces.
2014-12-21 14:04:20 -08:00
Sean Farley
84f3cb1f9a namespaces: add __getitem__ property
Since the namespaces object uses an underlying (sorted) dictionary to store the
namespaces, it makes sense to expose this to naturally gain access to those
namespaces.
2014-12-21 13:56:32 -08:00
Sean Farley
852fbf7d43 namespaces: update documentation and code indentation
The previous patch changed just the functionality, while this patch focuses on
the documentation and indentation to keep review simple.
2014-12-21 13:06:24 -08:00
Sean Farley
2598d162b2 namespaces: use namespace object instead of dictionary
This isn't as bad as the diff seems, it only looks like scary. In this patch,
we use the 'namespace' object instead of accessing keys in a dictionary.

This required the 'templatename' and 'names' method to change their
implementation. Later, we will remove these functions entirely due to a better
api.
2014-12-19 17:27:20 -08:00
Sean Farley
286a310694 namespaces: copy implementation to new namespace object 2014-12-19 17:17:17 -08:00
Sean Farley
fd9be99b96 namespaces: add a namespace object
Currently, we use a dictionary object to store the namespace properties. This
is python so let's use an object. This will allow us to be more flexible in our
method signatures in the future.
2014-12-19 17:00:28 -08:00
Sean Farley
96df4dc9b7 namespaces: generate template keyword when registering a namespace
For any namespace, we generate a template keyword. For example, given a
namespace 'babar', we automatically have the ability to use it in a template:

hg log -r . -T '{babars % "King: {babar}\n"}'

Furthermore, we only generate this keyword for a namespace if one doesn't
already exist. This is necessary for 'branches' and 'bookmarks' since both of
those have concepts of 'current' (something outside the namespace api) and also
allows extensions to override default behavior if desired.
2014-10-16 23:19:09 -07:00
Sean Farley
01b442aa2a namespaces: add names method to return list of names for a given node
In the previous patch, we added a node-to-name map property. This patch just
exposes that interface to the api.
2014-12-14 18:54:50 -08:00
Sean Farley
0eb677308a namespaces: add nodemap property
This patch adds a node-to-name map property to the namespace. This is necessary
because we cannot simply invert the name-to-node map because we do not assume
the name-to-node map to be unique (for example, consider named branches: many
nodes have one branch name).

The node-to-name is helpful in log commands where we are already iterating over
a set of nodes and want to display some kind of naming information to the user.
2014-12-15 00:24:23 -08:00
Sean Farley
8649ff43b3 namespaces: add method to get template name of namespace
This patch adds the public api for getting the template name of a namespace so
that the next patch can use it to generate a template keyword automatically.
2014-12-14 19:12:27 -08:00
Sean Farley
840bbb8c70 namespaces: add template name of a namespace
The template name property will be used in upcoming patches to automatically
generate a template keyword. For example, given a namespace called 'babars', we
will automatically generate a template keyword 'babar' such that we can use it
in the following way,

$ hg log -r . -T '{babars % "King: {babar}\n"}'
2014-12-15 00:09:52 -08:00
Sean Farley
a106407d01 namespaces: add branches
Note that the exception-catching from the previous branchtip check is moved up
to catch exceptions from the try block surrounding the namespace lookup.
2014-10-17 15:27:12 -07:00
Sean Farley
066d5cf84a namespaces: add tags 2014-10-17 15:27:33 -07:00
Ryan McElroy
28a1fb3f8a namespaces: remove weakref; always pass in repo
It turns out that maintaining a reference of any sort (even weak!) to the repo
when constructed doesn't work because we may at some point pass in a repoview
filtered by something other than what the initial repo was.
2014-12-14 19:11:44 -08:00
Sean Farley
d27dee10d8 namespaces: add a method to the first matching node for a given name 2014-10-17 15:28:40 -07:00
Sean Farley
80fbfb49cc namespaces: add bookmarks to the names data structure
This marks the first use of abstracting our different types of named objects
(bookmarks, tags, branches, etc.) and upcoming patches will use this to
simplify logic.
2014-12-14 12:53:50 -08:00
Sean Farley
d9e45fae2c namespaces: add a convenience property for the weakref _repo 2014-12-14 16:22:24 -08:00
Sean Farley
2b5c02f672 namespaces: pass repo to __init__
We store repo as a weakref so that we can prevent a cycle between namespaces
and localrepo.
2014-12-14 15:35:57 -08:00
Sean Farley
94c99a3639 namespaces: add a function to turn single results into lists 2014-12-14 15:04:40 -08:00
Sean Farley
06715bc235 namespaces: add a method to register new namespaces 2014-10-17 11:25:51 -07:00
Sean Farley
6f6baebff4 namespaces: introduce a generic way to map between names and nodes
This patch begins the work to provide a way to register a namespace to handle
'names'. Benefits of this would be,

- improved templating: This would provide {name} which could output any branch,
  bookmark, tag, or any extension registered namespace all without having the
  extension doing any extra work

- improved tab completion: Since this provides a single source of all 'names',
  tab completion would not need to know of each namespace

- changeset lookup: Similar to before, a unified place to get all 'names' will
  allow finding changesets without any extension code having to reimplement
  this

Also, 6c946e059d3b has shown us that for internal code which expects a certain
type of method or behavior, we should provide an easy way for extensions to
check this behavior.
2014-12-14 12:29:28 -08:00