Commit Graph

32 Commits

Author SHA1 Message Date
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
Jun Wu
d487d6ed63 blackbox: do not assume self._bb{vfs,repo,fp} are set in blackboxui.__init__
It's possible for the blackboxui code to do a "del self._bbvfs", then ui.copy()
or similar attempt will fail. It will also fail when constructing a blackboxui
from a non-blackbox ui.
This patch fixes the issue by not assuming any _bb* attr is set.
2016-03-15 10:36:02 +00:00
timeless
57b0b61ecb blackbox: guard against recursion from dirty check 2016-03-08 20:34:59 +00:00
timeless
6944befadd blackbox: optionally log event source 2016-02-11 19:38:26 +00:00
timeless
3046e843ec blackbox: remove hexfn
It was introduced as copy+paste code, but was never necessary.
2016-03-01 10:45:47 +00:00
timeless
8ffb77cabf blackbox: rewrite dirty documentation noting it is expensive 2016-03-01 10:43:52 +00:00
timeless
8b93438cc2 blackbox: properly replace ui class
Without this, anyone creating a ui object using: uimod.ui()
skips the blackbox.

Also, anyone doing ui.copy() skipped the blackbox.

Unfortunately, the ui object lifestyle is a bit messy,
the first one that's created is never actually initialized
with subclasses, instead pieces of the subclass are adopted
into the primal ui object. In order to handle this, a
_partialinit method will be called to ensure that the
blackboxui is properly initialized.
2016-02-03 04:54:40 +00:00
timeless
ecdcbad06b blackbox: store the blackbox ui object instead of the log file
Without this, the last logged entry didn't have access to
the repository, and thus couldn't report its version
(and especially that an add or similar dirtied it).

A side-effect is that one repo leaks until process exit...
2016-02-03 17:05:04 +00:00
timeless
236079f621 blackbox: log dirty state
If blackbox.dirty = True, use `+` to indicate dirty repositories.
2016-02-09 15:44:13 +00:00
timeless
1cee322d64 blackbox: log working directory version
Without this, while you could see the list of commands run,
it wasn't possible to identify what they were doing, because commads
could rely on revsets (including remote input which varies over time).
2016-02-09 19:16:06 +00:00
timeless
0100803916 blackbox: rename fp variable 2016-02-08 03:37:26 +00:00
timeless
63a361d33c blackbox: avoid creating multiple file handles for a single log
There are multiple ui objects in Mercurial that can relate to a repository,
before this change, each one would have its own file pointer, which
results in unfortunate logging behavior.

Also, any log rotation results would be bad because only the
active blackboxui object's file pointer would be refreshed.

Note that this does not prevent two long running hg commands for the same
repository from causing problems.
2016-02-03 15:41:31 +00:00
Gregory Szorc
7670e7605d blackbox: use absolute_import 2016-02-09 17:30:38 -08:00
timeless
3502e556ef util: enable getpid to be replaced
This will enable tests to write stable process ids.
2016-02-03 09:11:22 +00:00
timeless
0541bdf700 blackbox: refactor use of vfs as _bbvfs 2016-02-08 00:47:36 +00:00
timeless
6eaedecd28 blackbox: flush output file descriptor
Without this, when there are multiple ui views, each blackbox
will have its own file handle, and the logging will be in
a really bad order.

Also, because of the way blackbox works, it never closes its
file handles, which means the last output before exit is
often lost.
2016-02-03 15:18:29 +00:00
Durham Goode
bdd9abd3d3 blackbox: add pid to output
This adds the process id to the line header for the blackbox output. This is
useful for distinguishing processes when using the blackbox on a server and many
processes are writing to the blackbox at once.
2015-09-07 11:31:44 -07:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07: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
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
Durham Goode
7689f31a9c blackbox: fix blackbox causing exceptions in tests
In the tests some scripts call reposetup with the base ui instead of the
one the extensions have modified.  This causes an exception in
blackbox.reposetup since it expected a method to be there. So I just
check for it first. This only happened when the blackbox extension
was enabled during tests.
2013-05-22 17:38:24 -07:00
Takumi IINO
97e34bea4f blackbox: fix literal block syntax 2013-05-09 11:37:20 +09:00
Bryan O'Sullivan
228c308a0d blackbox: automatically rotate log files
If enabled, log rotation prevents the amount of space used by the
blackbox log from growing without bound. This becomes important in
cases where there are a lot of busy repositories managed by humans
and automation on many machines.

In large deployments, we cannot reasonably track all the repos where
blackbox logs need to be managed, so it is safer to have blackbox
manage its own logs than to move responsibility to an external tool
such as logrotate.

This change adds two configuration keys:

* blackbox.maxsize is the maximum allowable size of the current log

* blackbox.maxfiles is the number of log files to maintain
2013-04-18 16:17:59 -07:00
Bryan O'Sullivan
eed131db97 blackbox: fix a case of name capture 2013-04-18 12:55:58 -07:00
Bryan O'Sullivan
e905def78f blackbox: defer opening a log file until needed (issue3869)
Previously, we opened the log file when creating a repo object. This
was inefficient (not all repo creation is going to result in a need to
log something), but more importantly it broke subrepo updates when used
on NFS.

* perform an update in the master repo that triggers a subrepo clone

* empty subrepo already exists, and has an open, empty blackbox.log file
  due to it being opened eagerly/prematurely

* hg decides to blow away the skeletal subrepo (see use of shutil.rmtree
  in subrepo._get)

* we crash, due to NFS treating a delete of an open file as really a
  rename to a hidden ".nfs" file

Now that we open the blackbox log file on demand, no file exists at the
time the empty subrepo is deleted, so the above problem does not occur.
2013-03-26 16:27:51 -07:00
Bryan O'Sullivan
15ac9d5048 blackbox: account for another source of errors 2013-03-22 10:56:55 -07:00
Bryan O'Sullivan
ec76ade165 blackbox: use util.getuser for portability
On Windows, our implementation is more robust than Python's version.
2013-03-20 13:40:06 -07:00
Bryan O'Sullivan
c6e69fe607 blackbox: prevent failed I/O from causing hg to abort
Instead, we simply print a warning message if opening the blackbox log
file fails, or if writing to it fails.
2013-03-20 13:40:05 -07:00
Bryan O'Sullivan
9b64f1d6bd blackbox: fix copyright 2013-02-13 10:54:52 -08:00
Bryan O'Sullivan
55a5166e90 blackbox: fix a failing pyflakes test 2013-02-12 16:02:35 -08:00
Durham Goode
cf493e6ded blackbox: adds a 'blackbox' command for viewing recent logs
Adds a 'hg blackbox' command for viewing the latest entries in the blackbox log.
By default it shows the last 10 entries, but -l allows the user to specify.
2013-02-09 09:09:46 -08:00
Durham Goode
4add84adea blackbox: adds a blackbox extension
Adds a blackbox extension that listens to ui.log() and writes the messages to
.hg/blackbox.log. Future commits will use ui.log() to log commands, unhandled
exceptions, incoming changes, and hooks.  The extension defaults to logging
everything, but can be configured via blackbox.track to only log certain events.
Log lines are of the format:  "date time user> message"

Example log line:
2013/02/09 08:35:19 durham> 1 incoming changes - new heads: d84ced58aaa
2013-02-12 14:08:33 -08:00