Commit Graph

51 Commits

Author SHA1 Message Date
Jun Wu
c55a3b0058 blackbox: move _openlogfile to a separate method
This removes several `stat` syscalls for accessing `_bbvfs` and makes `ui`
object cleaner.

Differential Revision: https://phab.mercurial-scm.org/D769
2017-09-21 11:10:20 -07:00
Jun Wu
a18c4e0d85 blackbox: do not prevent 'chg init' from working
Previously, blackbox always appends to blackbox.log and creates the
directory for that file on demand. That could be an issue if:

  1. chg starts from `$REPO` directory, so `ui._bbrepo` is set.
  2. `rm -rf $REPO`.
  3. `chg init $REPO`, blackbox writes something and `init` will fail
     because `$REPO` directory is non-empty.

This patch fixes that by verifying whether vfs exists before re-using it.

Differential Revision: https://phab.mercurial-scm.org/D768
2017-09-21 11:03:37 -07:00
Jun Wu
042b7a7361 blackbox: set lastui even if ui.log is not called (issue5518)
`lastui` decides where (where is the `.hg`) to use if the current `ui`
object does not have a `_bbrepo` associated. Previously it only gets set in
`ui.log`, which means unless a `ui` with repo associated calls `log` with
tracked event, blackbox does not know where to write its log. This patch
makes `reposetup` set `lastui` so it so we could log some more events (see
test changes).

Differential Revision: https://phab.mercurial-scm.org/D655
2017-09-18 16:01:03 -07:00
Jun Wu
941088675f blackbox: unindent a try block
The try block is no longer necessary.

Differential Revision: https://phab.mercurial-scm.org/D654
2017-09-06 21:23:38 -07:00
Jun Wu
332711dbe5 blackbox: simplify ui states
It seems cleaner to just remove `_partialinit`, `copy`, `__init__`. This
patch makes it so by using `getattr` in `log` so those fields do not need to
be existed.

Differential Revision: https://phab.mercurial-scm.org/D652
2017-09-18 15:56:08 -07:00
Jun Wu
6192c1e941 blackbox: remove _bbvfs state
`_bbvfs` is redundant because it could be calcualted from `_bbrepo`.

Differential Revision: https://phab.mercurial-scm.org/D651
2017-09-06 21:12:27 -07:00
Jun Wu
0b73011081 blackbox: do not cache file objects
Having the blackbox file objects cached in `ui._bbfp` could in theory be
troublesome if multiple processes (ex. chg servers) have file objects
referring to a same file. (Although I spent some time and failed to build a
convincing test case)

This patch makes blackbox re-open the file every time to make the situation
better. Ideally we also need proper locking.

The caching logic traces back to the commit introducing blackbox
(18242716a). That commit does not have details about why caching is
necessary.  Consider the fact that blackbox logs are not many, it seems fine
to remove the fp cache to be more confident.

Differential Revision: https://phab.mercurial-scm.org/D650
2017-09-06 21:08:59 -07:00
Jun Wu
38ee36031d blackbox: inline _bbwrite
There is no need to make it a separate method. This makes the next change
easier to read.

Differential Revision: https://phab.mercurial-scm.org/D649
2017-09-06 20:54:53 -07:00
Jun Wu
a97d2d42cb blackbox: fix rotation with chg
The added test will show:

  $ $PYTHON showsize.py .hg/blackbox*
  .hg/blackbox.log: < 500
  .hg/blackbox.log.1: < 500
  .hg/blackbox.log.2: < 500
  .hg/blackbox.log.3: < 500
  .hg/blackbox.log.4: < 500
  .hg/blackbox.log.5: >= 500

with previous code.

The issue is caused by blackbox caching file objects *by path*, and the
rotation size check could run on a wrong file object (i.e. it should check
"blackbox.log", but `filehandles["blackbox.log"]` contains a file object
that has been renamed to "blackbox.log.5").

This patch removes the "filehandlers" global cache added by 39bd7b0c79fe to
solve the issue.

I think the original patch was trying to make different ui objects use a same
file object if their blackbox.log path is the same. In theory it could also
be problematic in the rotation case. Anyway, that should become unnecessary
after D650.

Differential Revision: https://phab.mercurial-scm.org/D648
2017-09-06 19:27:30 -07:00
Boris Feld
c9fe43d98b repovfs: add a ward to check if locks are properly taken
When the appropriate developer warnings are enabled, We wrap 'repo.vfs.audit' to
check for locks when accessing file in '.hg' for writing. Another changeset will
add a 'ward' for the store vfs (svfs).

This check system has caught a handful of locking issues that have been fixed
in previous series (mostly in 4.0). I expect another batch to be caught in third
party extensions.

We introduce two real exceptions from extensions 'blackbox.log' (because a lot of
read-only operations add entry to it), and 'last-email.txt' (because 'hg email'
is currently a read only operation and there is value to keep it this way).

In addition we are currently allowing bisect to operate outside of the lock
because the current code is a bit hard to get properly locked for now. Multiple
clean up have been made but there is still a couple of them to do and the freeze
is coming.
2017-07-11 12:38:17 +02:00
Matt Harbison
fd53ff6bf6 blackbox: simplify the dirty check
Same idea (and possibly incorrect behavior) as the previous commit.
2017-07-09 00:23:03 -04:00
Pierre-Yves David
dd58f467f2 configitems: register the 'blackbox.logsource' config 2017-06-30 03:28:18 +02:00
Pierre-Yves David
e633829f37 configitems: register the 'blackbox.dirty' config 2017-06-30 03:28:11 +02:00
Pierre-Yves David
69222bbf87 blackbox: use a human readable version of the default
Now that the default value is also converted we can use a human readable version
for it. This will be useful if we start to automatically display the default
config value in various place.
2017-06-18 20:49:08 +02:00
Pierre-Yves David
050ba47e1c configitems: register 'blackbox.maxsize' as an example of 'configbytes'
This exercise the default value handling in 'configbytes'.
2017-06-17 13:21:06 +02:00
Pierre-Yves David
85f9bed0b5 blackbox: minor code reordering
The version declaration should come first in my opinion. This will help gather
the command table with the config table.
2017-06-17 13:41:28 +02:00
Boris Feld
44d2fb42d7 devel: update blackbox to use default-date
Blackbox now obeys the 'devel.default-date' option. As a side effect we can
delete the mock for blackblox related tests.
2017-05-16 18:36:08 +02: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
Pulkit Goyal
b69219d4a1 py3: use %d to format integers into bytestrings 2017-05-05 01:41:54 +05:30
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