Commit Graph

289 Commits

Author SHA1 Message Date
FUJIWARA Katsunori
07e0e6566d keyword: wrap functions only once at loading keyword extension
Before this patch, some functions are wrapped in reposetup(), but this
causes redundant nested wrapping, if two ore more repositories enable
keyword extension (e.g. hgweb serves multiple repositories).

Now, there is no need to define these wrapper functions in
reposetup(), because previous patches made them not directly refer to
kwtemplater instanciated in reposetup().

This patch factors these wrapper functions out from reposetup(), and
uses them to wrap functions only at once at loading keyword extension.
2017-06-26 03:47:11 +09:00
FUJIWARA Katsunori
2e705b83b8 keyword: use _keywordkwt of repository instead of kwtools['templater']
Now, kwtemplater instance can be obtained via _keywordkwt property of
repository.
2017-06-26 03:46:17 +09:00
FUJIWARA Katsunori
d5dd62b804 keyword: obtain kwtemplater instance via repository at runtime
Wrapper functions of keyword extension are defined in reposetup(),
because they refer to kwtemplater instantiated in reposetup().

This patch makes them obtain kwtemplater instance via repository at
runtime. For reviewability, this patch focuses on wrapper functions,
which handle generator.

This is a part of preparations for defining them statically.
2017-06-26 03:44:50 +09:00
FUJIWARA Katsunori
194e8aed9d keyword: obtain kwtemplater instance via repository at runtime
Wrapper functions of keyword extension are defined in reposetup(),
because they refer to kwtemplater instantiated in reposetup().

This patch makes them obtain kwtemplater instance via repository at
runtime.

This is a part of preparations for defining them statically.
2017-06-26 03:43:47 +09:00
FUJIWARA Katsunori
5ed9c1efe5 keyword: make wrapped repository and kwtemplater refer to each other
Wrapper functions of keyword extension are defined in reposetup(),
because they refer to kwtemplater instantiated in reposetup().

But these functions can be defined statically, if kwtemplater can be
obtained via repository at runtime.

This is a part of preparations for defining them statically.

To avoid cyclic reference, this patch makes kwtemplater use weakref to
refer related repository instance.
2017-06-26 03:42:17 +09:00
FUJIWARA Katsunori
3692ff90a9 keyword: make comparison webcommand suppress keyword expansion
Before this patch, diff in "comparison" webcommand doesn't suppress
keyword expansion as same as diff output of other webcommands.
2017-06-26 03:40:12 +09:00
FUJIWARA Katsunori
68301828cc keyword: restore kwtemplater.match at the end of wrapped webcommands
Before this patch, kwweb_skip doesn't restore kwtemplater.match after
wrapped webcommands. This suppresses keyword expansion at wrapped
webcommands.

Typical usecase of this issue is "file" webcommand after annotate,
changeset, filediff or so on.

To ensure kwtemplater.match=util.never while original webcommand
running, this patch makes kwweb_skip yield values returned by it,
because it returns generator object.
2017-06-26 03:40:06 +09:00
FUJIWARA Katsunori
bd6e3a5360 keyword: restore kwtemplater.restrict at the end of wrapped patch.diff
Before this patch, kwdiff doesn't restore kwtemplater.restrict after
invocation of wrapped patch.diff(). This suppresses keyword expansion
at subsequent filelog.read().

Typical usecase of this issue is "hg cat" after "hg diff" with command
server. In this case, kwtemplater.restrict=True is kept in command
server process even after "hg diff".

To ensure kwtemplater.restrict=True while original patch.diff()
running, this patch makes kwdiff() yield values returned by it,
because it returns generator object.

Strictly speaking, if filelog.read() is invoked before completely
evaluating the result of previous patch.diff(), keyword expansion is
still suppressed, because kwtemplater.restrict isn't restored yet.

But this fixing should be reasonable enough, because patch.diff() is
consumed immediately, AFAIK.
2017-06-26 03:38:12 +09:00
Christian Ebert
d05e4bb5d6 keyword: use context manager for rollback locking 2017-06-20 12:51:36 +01:00
Yuya Nishihara
ca018ac743 cmdutil: factor out helper to create changeset_templater with literal template
changeset_templater has lots of arguments, but most callers only need to
specify a literal template 'tmpl'.

"hg debugtemplate" has no diff option, which means 'opts' were effectively {},
so dropped opts.
2017-04-22 18:42:03 +09:00
Yuya Nishihara
6c2103bc71 commands: move templates of common command options to cmdutil (API)
The goal is to get rid of the debugcommands -> commands dependency.

Since globalopts is the property of the commands, it's kept in the commands
module.
2017-05-14 16:19:47 +09:00
Yuya Nishihara
3e663dde68 registrar: move cmdutil.command to registrar module (API)
cmdutil.command wasn't a member of the registrar framework only for a
historical reason. Let's make that happen. This patch keeps cmdutil.command
as an alias for extension compatibility.
2016-01-09 23:07:20 +09:00
Pierre-Yves David
3f8c57e798 keyword: directly use repo.vfs.join
The 'repo.join' method is about to be deprecated.
2017-03-08 16:51:57 -08:00
Christian Ebert
bfdeb77b45 keyword: handle filectx _customcmp
Suggested by Yuya Nishihara:
https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-October/089461.html

Related to issue5364.
2016-10-17 17:42:46 +02:00
timeless
8cd11bcddf keyword: use single quotes in use warning 2016-09-20 23:45:15 +00:00
Augie Fackler
4e1c384d0a extensions: change magic "shipped with hg" string
I've caught multiple extensions in the wild lying about being
'internal', so it's time to move the goalposts on people. Goalpost
moving will continue until third party extensions stop trying to
defeat the system.
2016-08-23 11:26:08 -04:00
Christian Ebert
6e0f6b6bd8 keyword: avoid traceback when kwdemo is run outside a repo
68ae3063a47d causes a fatal AttributeError if kwdemo is run outside a repo
because in the temporary repo creation repo is None and therefore cannot have a
baseui attribute.
In this case fall back to using ui.

Add test case.
2016-07-27 13:57:51 +01:00
FUJIWARA Katsunori
f46b49a0e3 check-code: detect "missing _() in ui message" more exactly
Before this patch, "missing _() in ui message" rule overlooks
translatable message, which starts with other than alphabet.

To detect "missing _() in ui message" more exactly, this patch
improves the regexp with assumptions below.

  - sequence consisting of below might precede "translatable message"
    in same string token

    - formatting string, which starts with '%'
    - escaped character, which starts with 'b' (as replacement of '\\'), or
    - characters other than '%', 'b' and 'x' (as replacement of alphabet)

  - any string tokens might precede a string token, which contains
    "translatable message"

This patch builds an input file, which is used to examine "missing _()
in ui message" detection, before '"$check_code" stringjoin.py' in
test-contrib-check-code.t, because this reduces amount of change churn
in subsequent patch.

This patch also applies "()" instead of "_()" on messages below to
hide false-positives:

  - messages for ui.debug() or debug commands/tools
    - contrib/debugshell.py
    - hgext/win32mbcs.py (ui.write() is used, though)
    - mercurial/commands.py
      - _debugchangegroup
      - debugindex
      - debuglocks
      - debugrevlog
      - debugrevspec
      - debugtemplate

  - untranslatable messages
    - doc/gendoc.py (ReST specific text)
    - hgext/hgk.py (permission string)
    - hgext/keyword.py (text written into configuration file)
    - mercurial/cmdutil.py (formatting strings for JSON)
2016-06-21 00:50:39 +09:00
Yuya Nishihara
a5c934df3c py3: move up symbol imports to enforce import-checker rules
Since (b) is banned, we should do the same for (a) for consistency.

 a) from mercurial import hg
    from mercurial.i18n import _

 b) from . import hg
    from .i18n import _
2016-05-14 14:03:12 +09:00
Christian Ebert
81c2d303c5 keyword: replace use of _filerev with _filenode
To be independent of rev numbers.
Analogous to b558712637b8.
2016-04-19 11:00:15 +01:00
FUJIWARA Katsunori
a35dfb0209 keyword: use templatefilter to mark a function as template filter
This patch also adds test for filter 'svnisodate' and 'svnutcdate' for
safety, because there is no test using them, yet.
2016-03-30 02:10:44 +09:00
Christian Ebert
131615fd5b keyword: compact writing of temporary kwdemo hgrc 2016-03-11 08:27:11 +00:00
Christian Ebert
929efdce88 keyword: use absolute_import 2016-03-01 10:33:06 +00:00
Bryan O'Sullivan
65ee17ba0b with: use context manager for wlock in kw_dorecord 2016-01-15 13:14:46 -08:00
Bryan O'Sullivan
a9fe3cefa5 with: use context manager for wlock in kw_copy 2016-01-15 13:14:46 -08:00
Bryan O'Sullivan
85a3bcab4f with: use context manager for wlock in kw_amend 2016-01-15 13:14:46 -08:00
Bryan O'Sullivan
6b60d65449 with: use context manager for wlock in keyword demo 2016-01-15 13:14:46 -08:00
Bryan O'Sullivan
82870250ec with: use context manager for wlock in _kwfwrite 2016-01-15 13:14:46 -08:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
FUJIWARA Katsunori
419251cb13 keyword: make restrict mode False while updating files for rollback
This is a preparation for using 'repo.rollback()' instead of aborting
a current running transaction for "shelve" and "unshelve".

Before this patch, updating files as a part of 'repo.rollback()'
overridden by keyword extension always follows 'restrict' mode of the
command currently executed.

"merge", "unshelve" and so on should be 'restrict'-ed, because keyword
expansion may cause unexpected conflicts at merging while these
commands.

But, if 'repo.rollback()' is invoked while executing 'restrict'-ed
commands, modified files in the working directory are marked as
"CLEAN" unexpectedly by code path below:

        # 'lookup' below is True at updating modified files for rollback
        kwcmd = self.restrict and lookup # kwexpand/kwshrink
            :
                if kwcmd:
                    self.repo.dirstate.normal(f)

On the other hand, "rollback" command isn't 'restrict'-ed, because
rollbacking itself doesn't imply merging.

Therefore, disabling 'restrict' mode while updating files as a part of
'repo.rollback()' regardless of current 'restrict' mode should be
reasonable.
2015-10-04 21:33:29 +09:00
Matt Mackall
5e1b4ad958 urls: bulk-change primary website URLs 2015-09-30 15:43:49 -05:00
Augie Fackler
f95a6caba1 extensions: document that testedwith = 'internal' is special
Extension authors (notably at companies using hg) have been
cargo-culting the `testedwith = 'internal'` bit from hg's own
extensions, which then defeats our "file bugs over here" logic in
dispatch. Let's be more aggressive about trying to give extension
authors a hint about what testedwith should say.
2015-04-28 16:44:37 -04: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
Christian Ebert
add4536ffa keyword: use wvfs.rmtree to remove kwdemo directory
Pass repo.root explicitly as argument to indicate that removal of the temporary
repo is intentional in this case.
2015-04-18 15:39:26 +02:00
Siddharth Agarwal
ae273dc918 keyword: monkeypatch patch.diff more generically
This function doesn't need access to any of the args or kwargs, so make the
monkeypatching more robust. (In upcoming patches we'll introduce another
argument to patch.diff, and this function would break if it weren't for this
patch.)
2015-03-17 15:33:34 -07:00
Siddharth Agarwal
7383237886 keyword: rename kw_diff to kwdiff in keeping with Mercurial style rules
In an upcoming patch we'll change this function's signature. If the name is
kept the same, test-check-commit-hg.t complains.
2015-03-17 15:52:28 -07:00
Jordi Gutiérrez Hermoso
8eb132f5ea style: kill ersatz if-else ternary operators
Although Python supports `X = Y if COND else Z`, this was only
introduced in Python 2.5. Since we have to support Python 2.4, it was
a very common thing to write instead `X = COND and Y or Z`, which is a
bit obscure at a glance. It requires some intricate knowledge of
Python to understand how to parse these one-liners.

We change instead all of these one-liners to 4-liners. This was
executed with the following perlism:

    find -name "*.py" -exec perl -pi -e 's,(\s*)([\.\w]+) = \(?(\S+)\s+and\s+(\S*)\)?\s+or\s+(\S*)$,$1if $3:\n$1    $2 = $4\n$1else:\n$1    $2 = $5,' {} \;

I tweaked the following cases from the automatic Perl output:

    prev = (parents and parents[0]) or nullid
    port = (use_ssl and 443 or 80)
    cwd = (pats and repo.getcwd()) or ''
    rename = fctx and webutil.renamelink(fctx) or []
    ctx = fctx and fctx or ctx
    self.base = (mapfile and os.path.dirname(mapfile)) or ''

I also added some newlines wherever they seemd appropriate for readability

There are probably a few ersatz ternary operators still in the code
somewhere, lurking away from the power of a simple regex.
2015-03-13 17:00:06 -04:00
Laurent Charignon
b5de5559b7 record: move dorecord from record to cmdutil
Part of a serie of patches to move record from hgext to core
2015-03-10 17:14:33 -07:00
Angel Ezquerra
79698da278 localrepo: remove all external users of localrepo.wopener
This change touches every module in which repository.wopener was being used, and
changes it for the equivalent repository.wvfs.

It should now be possible to remove localrepo.wopener.
2015-01-11 01:51:52 +01:00
Angel Ezquerra
6e49f7def8 localrepo: remove all external users of localrepo.sopener
This change touches every module in which repository.sopener was being used, and
changes it for the equivalent repository.svfs.

It should now be possible to remove localrepo.sopener.
2015-01-11 00:25:54 +01:00
Angel Ezquerra
88cbab7845 localrepo: remove all external users of localrepo.opener
This change touches every module in which repository.opener was being used, and
changes it for the equivalent repository.vfs. This is meant to make it easier
to split the repository.vfs into several separate vfs.

It should now be possible to remove localrepo.opener.
2015-01-15 23:17:12 +01:00
Christian Ebert
798b4a0800 keyword: update copyright year 2015-01-03 11:12:44 +00:00
Christian Ebert
e083e1dece keyword: use vfs.reljoin and util.unlinkpath to remove kwdemo 2015-01-03 11:11:46 +00:00
Christian Ebert
0c25396920 keyword: handle resolve to either parent
Merged files are considered modified at commit time even if only 1 parent
differs. In this case we must use the change context of this parent for
expansion.

The issue went unnoticed for long because it is only apparent until the next
update to the merge revision - except in test-keyword where it was always
staring us in the face.
2014-12-21 13:02:59 +00:00
Martin von Zweigbergk
f5a6951636 keyword: use parent of working copy as base for status
Instead of calling repo[None].status(), use the more common form that
uses the parent of the working copy as the base:
repo['.'].status(). Note that the former defaults to comparing to
revision '.', while the latter defaults to revision None, so the
contexts being compared are the same.

It might seem like this would result in a reverse diff, but it turns
out that workingctx.status() incorrectly reverses the result. That bug
will be fixed in a later commit.
2014-10-23 13:17:37 -07:00
Martin von Zweigbergk
2565ab5473 keyword: access status fields by name rather than index 2014-10-03 10:05:54 -07:00
Christian Ebert
a93ce4c3e8 keyword: bump copyright year 2014-08-02 09:44:45 +01:00
Christian Ebert
5f45792045 keyword: really clean up kwdemo temp tree 2014-08-02 09:44:11 +01:00
Gregory Szorc
ef5fffe0f4 keyword: define inferrepo in command decorator 2014-05-04 22:32:15 -07:00
Gregory Szorc
edfe6d451c keyword: define optionalrepo in command decorator 2014-05-04 22:16:56 -07:00