Commit Graph

18190 Commits

Author SHA1 Message Date
Bryan O'Sullivan
287bd28acf atexit: switch to home-grown implementation 2017-04-11 14:54:12 -07:00
Bryan O'Sullivan
0c663fe04d ui: add special-purpose atexit functionality
In spite of its longstanding use, Python's built-in atexit code is
not suitable for Mercurial's purposes, for several reasons:

* Handlers run after application code has finished.

* Because of this, the code that runs handlers swallows exceptions
  (since there's no possible stacktrace to associate errors with).
  If we're lucky, we'll get something spat out to stderr (if stderr
  still works), which of course isn't any use in a big deployment
  where it's important that exceptions get logged and aggregated.

* Mercurial's current atexit handlers make unfortunate assumptions
  about process state (specifically stdio) that, coupled with the
  above problems, make it impossible to deal with certain categories
  of error (try "hg status > /dev/full" on a Linux box).

* In Python 3, the atexit implementation is completely hidden, so
  we can't hijack the platform's atexit code to run handlers at a
  time of our choosing.

As a result, here's a perfectly cromulent atexit-like implementation
over which we have control.  This lets us decide exactly when the
handlers run (after each request has completed), and control what
the process state is when that occurs (and afterwards).
2017-04-11 14:54:12 -07:00
Denis Laxalde
761577866a context: follow all branches in blockdescendants()
In the initial implementation of blockdescendants (and thus followlines(...,
descend=True) revset), only the first branch encountered in descending
direction was followed.

Update the algorithm so that all children of a revision ('x' in code) are
considered. Accordingly, we need to prevent a child revision to be yielded
multiple times when it gets visited through different path, so we skip 'i'
when this occurs. Finally, since we now consider all parents of a possible
child touching a given line range, we take care of yielding the child if it
has a diff in specified line range with at least one of its parent (same logic
as blockancestors()).
2017-04-14 08:55:18 +02:00
Jun Wu
dcf42da6e9 pager: set some environment variables if they're not set
Git did this already [1] [2]. We want this behavior too [3].

This provides a better default user experience (like, supporting colors) if
users have things like "PAGER=less" set, which is not uncommon.

The environment variables are provided by a method so extensions can
override them on demand.

[1]: 6a5ff7acb5/pager.c (L87)
[2]: 6a5ff7acb5/Makefile (L1545)
[3]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-March/094780.html
2017-04-13 08:27:19 -07:00
Augie Fackler
fe10e9b912 sshpeer: fix docstring typo 2017-04-13 14:48:18 -04:00
Augie Fackler
6278186d0b util: pass sysstrs to warnings.filterwarnings
Un-breaks the Python 3 build.
2017-04-13 13:12:49 -04:00
Pierre-Yves David
dc3a34b74e vfs: deprecate all old classes in scmutil
Now that all vfs class moved to the vfs module, we can deprecate the old one.
2017-04-03 14:21:38 +02:00
Pierre-Yves David
a185960897 util: add a way to issue deprecation warning without a UI object
Our current deprecation warning mechanism relies on ui object. They are case
where we cannot have access to the UI object. On a general basis we avoid using
the python mechanism for deprecation warning because up to Python 2.6 it is
exposing warning to unsuspecting user who cannot do anything to deal with them.

So we build a "safe" strategy to hide this warnings behind a flag in an
environment variable. The test runner set this flag so that tests show these
warning.  This will help us marker API as deprecated for extensions to update
their code.
2017-04-04 11:03:29 +02:00
Denis Laxalde
160d0b298e gitweb: plug followlines UI in filerevision view
Mostly copy CSS rules from style-paper.css into style-gitweb.css. The only
modification is addition of !important on "background-color" rule for
"pre.sourcelines > span.followlines-selected" selector as the background color
is otherwise overriden by "pre.sourcelines.stripes > :nth-child(4n+4)" rule.
2017-04-13 09:49:48 +02:00
Denis Laxalde
14cc343c76 gitweb: handle "patch" query parameter in filelog view
As for paper style, in d9b8811bed4a, we display "diff" data as an additional
row in the table of revision entries for the gitweb template.
Also, as these additional diff rows have a white background, they may be
confused with log entry rows ("age", "author", "description", "links") of even
parity (parity0 also have a white background). So we disable parity colors for
log entry rows when diff is displayed and fix the color to the
"dark" parity (i.e. parity1 #f6f6f0) so that it's always distinguishable from
2017-04-13 10:04:09 +02:00
Denis Laxalde
8806e20e50 gitweb: add information about "linerange" filtering in filelog view
As for paper style, in a58e79a03a6e, we display a "(following lines
<fromline>:<toline> <a href='...'>back to filelog</a>)" message alongside the
file name when "linerange" query parameter is present.
2017-04-13 09:59:58 +02:00
Gábor Stefanik
387861cc38 util: fix human-readable printing of negative byte counts
Apply the same human-readable printing rules to negative byte counts as to
positive ones. Fixes output of debugupgraderepo.
2017-04-10 18:16:30 +02:00
Gregory Szorc
6c7c4762ec show: implement underway view
This is the beginning of a wip/smartlog view. It is basically a manually
constructed (read: fast) revset function to collect "relevant"
changesets combined with a custom template and a graph displayer.
It obviously needs a lot of work.

I'd like to get *something* usable in 4.2 so `hg show` has some value
to end-users.

Let the bikeshedding begin.
2017-04-12 20:31:15 -07:00
Gregory Szorc
e9dd2f7a3f pycompat: import correct cookie module on Python 3
http.cookielib doesn't exist. http.cookiejar does and it contains the
symbols we need. This fixes test failures on Python 3.
2017-04-12 18:42:20 -07:00
Denis Laxalde
5544045959 hgweb: add a link to followlines in descending direction
We change the content of the followlines popup to display two links inviting
to follow the history of selected lines in ascending (as before) and
descending directions. The popup now renders as:

  follow history of lines <fromline>:<toline>:
  <a href=...>ascending</a> / <a href=...>descending</a>
2017-04-10 17:36:40 +02:00
Denis Laxalde
bd52f5d831 hgweb: handle a "descend" query parameter in filelog command
When this "descend" query parameter is present along with "linerange"
parameter, we get revisions following line range in descending order. The
parameter has no effect without "linerange".
2017-04-10 16:23:41 +02:00
Denis Laxalde
779e08447b revset: add a 'descend' argument to followlines to return descendants
This is useful to follow changes in a block of lines forward in the history
(for instance, when one wants to find out how a function evolved from a point
in history).

We added a 'descend' parameter to followlines(), which defaults to False. If
True, followlines() returns descendants of startrev.

Because context.blockdescendants() does not follow renames, these are not
followed by the revset either, so history will end when a rename occurs (as
can be seen in tests).
2017-01-16 09:24:47 +01:00
Denis Laxalde
d7409a0458 context: add a blockdescendants function
This is symmetrical with blockancestors() and yields descendants of a filectx
with changes in the given line range. The noticeable difference is that the
algorithm does not follow renames (probably because filelog.descendants() does
not), so we are missing branches with renames.
2017-04-10 15:11:36 +02:00
Gregory Szorc
ef4d6a1617 url: support auth.cookiesfile for adding cookies to HTTP requests
Mercurial can't currently send cookies as part of HTTP requests.
Some authentication systems use cookies. So, it seems like adding
support for sending cookies seems like a useful feature.

This patch implements support for reading cookies from a file
and automatically sending them as part of the request. We rely
on the "cookiejar" Python module to do the heavy lifting of
parsing cookies files. We currently only support the Mozilla
(really Netscape-era) cookie format. There is another format
supported by cookielib and we may want to consider using that,
especially since the Netscape cookie parser can't parse ports.
It wasn't immediately obvious to me what the format of the other
parser is, so I didn't know how to test it. I /think/ it might
be literal "Cookie" header values, but I'm not sure. If it is
more robust than the Netscape format, we may want to just
support it.
2017-03-09 22:40:52 -08:00
Gregory Szorc
bd7f2afe30 httpconnection: allow a global auth.cookiefile config entry
This foreshadows support for defining a cookies file.
2017-03-09 22:35:10 -08:00
Gregory Szorc
3c5a0a039c util: make cookielib module available
In preparation for supporting sending cookies on HTTP requests.
2017-03-09 21:35:21 -08:00
Pierre-Yves David
010d017cdd crecord: avoid setting non-existing SIGTSTP signal on windows (issue5512)
Windows do not have a SIGTSTP so we avoid setting the handler if the signal is
unknown.
2017-04-06 11:28:25 +02:00
Pierre-Yves David
5a12bd8592 crecord: ensure we reinstall the SIGTSTP handler
Previous, exceptions would prevent the reinstallation of the
signal.
2017-04-06 11:25:13 +02:00
Pierre-Yves David
6ab2d25fb5 crecord: avoid setting non-existing signal SIGWINCH on windows
Windows do not have a SIGWINCH so we avoid setting the handler if the signal is
unknown.
2017-04-06 11:25:33 +02:00
Pierre-Yves David
75f4f604c1 crecord: ensure we reinstall the SIGWINCH handler
Previous, exception in _main(...) would prevent the reinstallation of the
signal.
2017-03-26 15:06:09 +02:00
Pierre-Yves David
83f005a5e4 crecord: extract most of 'main' into a sub function
There are some setup and cleanup necessary around the main code, that
setup/cleanup code needs multiple adjustments so we extract the core code into
its own function first for clarity.
2017-03-26 15:05:12 +02:00
Yuya Nishihara
35d42be491 templater: add shorthand for building a dict like {"key": key}
Like field init shorthand of Rust. This is convenient for building a JSON
object from selected keywords.

This means dict() won't support Python-like dict(iterable) syntax because
it's ambiguous. Perhaps it could be implemented as 'mapdict(xs % (k, v))'.
2017-04-03 23:13:49 +09:00
Yuya Nishihara
d86057a7bc templater: find keyword name more thoroughly on filtering error
Before, it could spill an internal representation of compiled template such
as [(<function runsymbol at 0x....>, 'extras'), ...]. Show less cryptic
message if no symbol found.

New findsymbolicname() function will be also used by dict() constructor.
2017-04-08 23:33:32 +09:00
Yuya Nishihara
ada544b9a5 templater: add dict() constructor
It's troublesome to build JSON by template, so let's add programmatic way.
2017-04-03 22:54:06 +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
e70ac1c73a parser: preserve order of keyword arguments
This helps building dict(key1=value1, ...) in deterministic way.
2017-04-09 11:58:27 +09:00
Yuya Nishihara
33d96b70bc parser: extend buildargsdict() to support arbitrary number of **kwargs
Prepares for adding dict(key1=value1, ...) template function. More tests
will be added later.
2017-04-03 22:07:09 +09:00
Yuya Nishihara
2b723f40bc parser: verify excessive number of args excluding kwargs in buildargsdict()
This makes the next patch slightly simpler. We don't need to check the
excessive number of keyword arguments since unknown and duplicated kwargs
are rejected.
2017-04-08 20:07:37 +09:00
Pierre-Yves David
63f0ebdb7f upgrade: simplify the "origin" dispatch in dry run
We could compute the final set we need directly.
2017-04-11 00:03:11 +02:00
Pierre-Yves David
0befb32302 upgrade: use 'improvement' object for action too
This simplify multiple pieces of code. For now we restrict this upgrade to the
top level function to keep this patch simple.
2017-04-10 23:11:45 +02:00
Pierre-Yves David
8343e068f0 upgrade: implement equality for 'improvement' object
Through the code, we use a mix of 'improvement' object and string. Having a
single type would be simpler. For this we need the object to be comparable.
2017-04-10 23:10:03 +02:00
Pierre-Yves David
28e1ded0a7 upgrade: simplify some of the initial dispatch for dry run
Since we already have the list of deficiencies, we can use it directly.
2017-04-10 22:15:17 +02:00
Pierre-Yves David
917b0eb147 upgrade: simplify 'determineactions'
Since we only takes 'deficiencies', we can simplify the function and clarify its
arguments.
2017-04-07 18:39:27 +02:00
Pierre-Yves David
dbe4fb45ab upgrade: filter optimizations outside of 'determineactions'
This sounds like higher level logic to process arguments.

Moving it out of 'determineactions' will allow passing only deficiencies to the
function. Then, in a future changeset, we will remove  dispatch on "improvement
type" within the function. See next changeset for details.
2017-04-11 23:46:16 +02:00
Pierre-Yves David
74208899a2 upgrade: directly iterate over optimisations
Since we already have the list of optimisations independent from the
deficiencies, we can use it directly.

(we make a dual assignement in this changeset to simplify the next one)
2017-04-07 18:46:27 +02:00
Pierre-Yves David
a5369d6f5d upgrade: simplify optimisations validation
Since we fetch optimizations distinctly from the deficiencies, we can simplify
some code.
2017-04-10 21:01:06 +02:00
Pierre-Yves David
6e51b0fbf0 upgrade: split finding deficiencies from finding optimisations
Our ultimate goal is to make it easier to get a diagnostic of the repository
format. A first important and step for that is to separate part related to
repository format from the optimisation. We start by having two different
functions returning the two categories of possible "improvement".
2017-04-10 21:00:52 +02:00
Pierre-Yves David
a73976f4f4 upgrade: update the copyright statement 2017-04-11 22:07:40 +02:00
Pierre-Yves David
ef922b1da6 upgrade: update the header comment 2017-04-11 22:07:15 +02:00
Pierre-Yves David
f958f09136 upgrade: import 'localrepo' globally
The in-function imports mention a cycle that seems to no longer be relevant. As
a result, we just import it globally.
2017-04-11 22:01:13 +02:00
Matt Harbison
38d197a30d windows: add context manager support to mixedfilemodewrapper
I stumbled into this in the next patch.  The difference between getting a
context manager capable object or not from vfs classes was as subtle as adding a
'+' to the file mode.
2017-04-11 21:38:11 -04:00
Pierre-Yves David
a8ff8b5088 bundle2: move 'seek' and 'tell' methods off the unpackermixin class
These methods are unrelated to unpacking. They are used internally by the
'unbundlepart' class only. So me move them there as private methods.

In the same go, we clarify their internal role in the their docstring.
2017-04-09 19:09:07 +02:00
Yuya Nishihara
073239ae67 templater: port pad() to take keyword arguments
This is another example where keyword arguments can be actually useful.
2017-04-03 22:23:52 +09:00