Commit Graph

23 Commits

Author SHA1 Message Date
Joel Brobecker
8de30044a4 .pre-commit-config.yaml: Update to black version 21.5b1
This commit updates the pre-commit hook to black version 21.5b1.
The hooks where then re-run on all files to update their formatting
to this new version of black.

Change-Id: Ib0866745ef8432cf93380a4d83fa23a479eb4a49
2021-06-15 05:52:32 -07:00
Joel Brobecker
a075b1653e reformat all the code using black
Change-Id: Idbc70777233ab2d40ab59765abb9cbbeeb88ec63
2021-04-18 14:59:01 +04:00
Joel Brobecker
e1ed1d1b3d hooks/utils.py: Allow parsing with Python-3 version of flake8
This commit replaces the litteral number "0664", which is no longer
valid syntax in Python 3.x, with "0o664", which is valid with both
Python 2.x and Python 3.x.

This is good preparation for the transition to Python 3.x, and
this also makes sure the current version of this module now passes
AdaCore's internal style checker.

Change-Id: I43ea77e894d8abbf8b36dfd40da2b8a4856489fd
2020-11-23 12:11:58 +01:00
Simon Marchi
a2909b2c8d Convert print statements to print function
In preparation for the transition to Python 3, convert to using the
print function.  The special import

    from __future__ import print_function

in Python 2.7 makes "print" become the function and not the statement.
In Python 3, it has no effect.  Once the transition is done and we
exclusively use Python 3, we can simply remove the imports.

The testsuite shows no regressions.
2020-11-22 19:29:38 -05:00
Joel Brobecker
07642e1591 Factorize code to call third-party hooks even more
This commit introduces a new class (ThirdPartyHook), which centralizes
the handling of third-party hooks (scripts that project set up via
the configuration file). Most of the code is simply a move of the code
from maybe_call_thirdparty_hook, with a couple of enhancements:
  - Ability to specify the directory from which to call the hook;
  - Handling of the situation when calling the hook itself fails.

We can already see the benefits of this in function style_check_files,
where the code now necessary to call the style_checker is both clearer
and more compact.

In the future, the intent is to push this class one step further to
allow users to specify hooks to be fetched from the repository, rather
than requiring that the hooks be installed (usually by an admin) on
the machine hosting the repository. The current class' API should
allow us to implement this in a way that's transparent to all users.

Change-Id: Ie8bf8accbbfd75a91b914628fad27d780532dac4
TN: T209-005
2020-07-19 19:38:40 -07:00
Joel Brobecker
05211f43ef fix reference name matching to perform full reference name matching
In other words, if you have a repository is configured with:

    [hooks]
        no-emails = refs/heads/master

The "hooks.no-emails" configuration should only apply to the master
branch, not any branch whose name happens to start with "master".

Incidentally, fixing this problem uncovered an error in the configuration
in the repository used in one of the testcases. This commit fixes that
error.

Change-Id: Ic3cdc56e4122fae65bbec792e12a002f2042b7e3
TN: T622-001
2020-06-21 18:00:38 -07:00
Joel Brobecker
55be81f225 Add support for hooks.update-hook configuration option
This option allows users to specify a script to be run at update time,
for each reference being updated. This script can then be used to perform
additional checks on top of the standard checks already provided by
our git-hooks.

Change-Id: Iff527f1c9c0ba516ea5181c5f8c066c5175ef0ee
TN: T209-001
2020-06-15 11:32:45 -07:00
Joel Brobecker
123dc3f7db fix "bare 'except'" pycodestyle error in emails.py and utils.py
Change-Id: I839ca83142d5a07d8e986c06656825aaad9822ea
2020-06-15 11:32:45 -07:00
Joel Brobecker
a235cfe862 utils.py: Remove import of "fcntl" (unused). 2014-12-14 11:23:38 -05:00
Joel Brobecker
d24228e75a Re-implement file locking using hard links instead of sockets.
Not sure why, but trying to create sockets on some machines triggered
an error, maybe because of insufficient privileges or unportable
socket usage. As a result, all pushes were systematically rejected,
with the hooks thinking that they had detected a concurrent push
request.

This patch re-implement the locking mechanism using a filesystem-based
approach (hard links).

For M903-031.
2013-12-31 11:21:29 +04:00
Joel Brobecker
51fc4cce82 Do not allow two update hooks requests to run at the same time.
For M903-031.
2013-12-30 16:05:40 +04:00
Joel Brobecker
e8c2e70f34 utils.py: Fix pep8 violoations 2013-12-26 15:13:20 +04:00
Joel Brobecker
27d43da046 warn: Better handling of empty prefix.
Make the space between the prefix and each list of the contents
of the warning completly explicit.  That way, if a caller wants
no prefix, the function does not generate a leading space on
every line printed.
2012-12-29 16:55:20 +04:00
Joel Brobecker
560836fcd5 Turn hooks.debug-level into an int. 2012-12-28 14:09:39 +04:00
Joel Brobecker
7f9a9298e9 Create errors.py and move InvalidUpdate there.
The fact that utils.py imports config.py makes it difficult for
config.py to access the InvalidUpdate exception.  So move this
exception to its own package, free of dependencies.

Preparation work for LC27-007.
2012-12-28 13:43:27 +04:00
Joel Brobecker
1561c7246c Rename hooks.debuglevel into hooks.debug-level.
For LC27-006.
2012-12-27 15:18:57 +04:00
Joel Brobecker
dfea31494c Add general support for git notes.
For LC24-001.
2012-12-24 12:02:33 +04:00
Joel Brobecker
55db2aa74c Introduce the post-receive hook.
This patch introduces the framework for a post-receive hook.
Currently, the hook only handles the creation of lightweight tags.
2012-06-25 12:49:57 -07:00
Joel Brobecker
3d8bf4fa57 utils.py:debug: Fix a couple of string (%) expansions
Found while working on L620-043.
2012-06-20 14:51:23 -07:00
Joel Brobecker
e348507001 Renames HOOKS_DEBUG_LEVEL into GIT_HOOKS_DEBUG_LEVEL. 2012-05-10 15:13:58 -07:00
Joel Brobecker
2a72796b7f Create a temporary scratch dir that we can use.
This temporary directory will be used later to checkout some files,
etc.
2012-05-10 15:13:54 -07:00
Joel Brobecker
29039afacc Allow different levels for debug traces.
For future additions to these scripts, there are some traces that
are only useful some times, and are otherwise a potential source
of a lot of noice (traces generated for each change in a given commit,
for instance).  For this purpose, we introduce the notion of debug
level.

To reflect this change, the name of the environment variable and
git config variable has been changed to HOOKS_DEBUG_LEVEL and
hooks.debuglevel accordingly.
2012-05-04 16:04:17 -07:00
Joel Brobecker
5810363c92 Partial implementation, with a testsuite infrastructure.
Very little is currently implemented, but this should be a good start.
2012-04-27 13:44:51 -07:00