Commit Graph

54 Commits

Author SHA1 Message Date
Joel Brobecker
fe8c5b5009 Add support for new config option: hooks.max-filepath-length
Note that, as part of the implementation, this commit introduces
a couple of calls to Git for each commit meant to retrieve the entire
list of files in a given commit. Luckily, one of these two calls
was already part of another check (filename collisions), and
the result of that call is cached in a CommitInfo object, so
the delta is only one extra Git call. Some performance measurements
seem to indicate that this is a fast-enough operation that users
should not notice the difference in performance, even for repositories
with a very large number of files [1]. If real-life usage proves
this assessment wrong, however, we'll revisit the documented behavior
so as to allow the use of a cheaper approach (e.g perform the check
on all modified files, rather than just the new ones).

[1]: Tested for instance on the GCC repository, which has more than
     87,000 files in total; the first call took roughly 100ms, and
     the next ones took about 60-70ms.

Change-Id: If0eea2c4990a945a3006cdd74d7a9aca2fc770d9
TN: T811-015
2020-09-11 10:47:51 -07:00
Joel Brobecker
3df0ef1658 CommitInfo.all_files: New method
This commit enhances the CommitInfo class by adding a new method that
returns the list of all files in the repository for the given commit.
This factorizes some code which already exists, and allows for the
result to be cached in this object for reuse, something we intend
to do on a followup commit. In the meantime, this commit should be
a nop in practice.

Change-Id: I3f9328dd9e89f8d82ad2ad6fdac69b5e2fbc0992
TN: T811-015
2020-09-02 17:28:28 -07:00
Joel Brobecker
111da4bad3 Add support for new config option: hooks.no-rh-character-range-check
Change-Id: Ic64b5b0f9007605bd339402b93689a944fd13485
TN: T829-004
2020-08-30 09:23:10 -07: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
ff8d81cb4a compute each commit's revlog once and then cache it
This is preparatory work for being to pass a certain amount of data
to user-defined hooks. The intent of this change is to limit the number
of times we compute that information to at most once.

Generally speaking, the main part of this change consists in adding
the following new methods to class CommitInfo:
  - raw_revlog;
  - raw_revlog_lines; and

The rest of this change is mostly adjustments to the code that needs
to access commits' rev logs to get them from a shared CommitInfo object
rather than from a play revision (SHA1).

Additionally, the function is_revert_commit in git.py, which took
a commit revision as a paramenter and needed a call to "git log"
to get the commit's body, has been replaced by a new method in
class CommitInfo. An alternative approach might have been to
keep the function, and change its parameter to be a CommitInfo object.
But it seemed more natural to make this a method of the CommitInfo
class instead, so this is what this change does.

Change-Id: Ia4bf23f24226d1e9eddafc61afd37db37f0f5287
TN: T209-005
2020-07-12 17:24:39 -07:00
Thomas Quinot
56f3ed28a7 Minor error message rewording 2020-06-15 11:32:45 -07:00
Joel Brobecker
7644236b43 show correct location when identifying non-ISO-8859-15 characters in rev log
There was a bug when returning an error message indicating that
the revision contains non-ISO-8859-15, that would always show
the first line has having the unwanted character, even when
that characters was actually on a different line.

And while at it, I improved the error message to include the line
number as well. Just in case showing the text itself is either not
sufficient or just not as efficient.

Credit for finding the bug: Thomas Quinot (thank you!).

Followup on QB25-001.
2018-01-10 15:41:06 +04:00
Joel Brobecker
24ebc361d6 Add support for hooks.style-checker-config-file config
For QC13-022.
2017-12-13 17:35:05 +04:00
Joel Brobecker
0ce5aa8f51 reject commits with non-ISO-8859-15 characters.
For QB25-001.
2017-12-13 15:39:06 +04:00
Joel Brobecker
d79d7b0e66 Require TNs to be on word boundaries to be accepted.
For QB25-001.
2017-12-13 15:38:58 +04:00
Joel Brobecker
3fed778872 rename check_commit and check_files to style_check_{commit,files}
This makes it clear what this functions are meant to do.
2017-08-04 16:06:47 -07:00
Joel Brobecker
407bcd597e remove support for the word "minor" as substitute for a TN
Users are now invited to use "no-tn-check" exclusively for that.

For Q728-031.
2017-07-28 16:24:55 -07:00
Joel Brobecker
7cedde9495 Only call style_checker once per commit (or group of commits)
This is a performance enhancement which reduces the number of calls
to style_checker to, at most, once per commit. For repositories which
are configured to combine the commits for style-checking, the
style_checker should only be called once at most.

In terms of performance gains, the new approach increases
the performance by a factor of about 5 to 8 (measured using
a set of 10, 100, 1000 and 4500 files, the latter being the typical
commit in the GDB repository when adjusting the copyright year in
all GDB sources).

Roughly speaking, on an Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz,
style-checking 4,500 text files, for which no check is actually
performed, took 31 seconds instead of 226 seconds. Using 4,500 Ada
files, for which we actually run the GNAT compiler and perform some
rulific checks, the new approach took 61 seconds instead of 230
seconds. The relative gain in the Ada case may appear to decrease
with the number of files to check, but 61 secs instead of 230 secs
is the difference between completing before the gerrit timeout
(around 2 minutes) or being aborted by the gerrit timeout.

For Q530-009.
2017-07-05 09:11:02 -07:00
Joel Brobecker
e4fa3fd38b pre_commit_checks: pass the filename via stdin rather than the command line
This is preparation work towards calling the style checker only once
for an entire commit, rather than once per file.

This commit also adds a new testcase, allowing the code coverage to
remain at 100%.

For Q530-009.
2017-07-05 09:10:59 -07:00
Joel Brobecker
8333edae90 simplify module name in call to style_checker
Thanks to the transition to the new style checker, we can now
call it directly with the module name, without having to fake
the SVN path to that module.

Part of NA17-007.
2017-05-18 09:34:28 -07:00
Joel Brobecker
168de73a97 transition default style checker to style_checker
For NA17-007.
2017-05-18 09:34:27 -07:00
Joel Brobecker
048462bc05 do not require '(' and ')' around no-rh-check or no-precommit-check
The team felt that requiring the extra '(' and ')' around the keywords
we can use in revision logs aren't really all that necessary, so
this patch makes it all consistent within the git-hooks, but
the svn hooks as well.

This patch also adjusts the two corresponding tests
(M424-008__no_rh_check_keyword, and P426-035__no_precommit_check_in_rh)
to verify that the relaxed requirement is actually relaxed.

Part of OA23-034.
2017-03-17 14:25:55 -07:00
Joel Brobecker
e70a745ab5 Handle filenames with special characters properly
For Q224-008.
2017-02-27 08:54:09 +01:00
Joel Brobecker
fc190d2022 relax "(no-tn-check)" marker, allowing "no-tn-check" instead
For PB01-006.
2016-11-01 07:43:21 -07:00
Joel Brobecker
ce9783c42e fix PEP8 (formatting) issues in pre_commit_checks.py 2016-11-01 07:43:10 -07:00
Joel Brobecker
9a7944833e Improve performance handling no-precommit-check .gitattributes.
For a commit for which there are 4,500 files being modified and
for which all files have the no-precommit-check attribute set,
this reduces the amount of time it takes for the update hook
to process that commit from 20-25 seconds down to less than a second.

For P531-036.
2016-06-07 09:27:27 -07:00
Joel Brobecker
959892681a remove syslog when style-check disabled by .gitattributes entry
Before this patch, we were generating one syslog entry for each
and every file that had the no-precommit-check attribute set -
meaning no style violation cvs_check. This not only generated
a lot of syslog entries, but also generated them for situations
that are not error situations. Since it is easy to determine
that information at any time in time, having that syslog trace
is really not necessary.

For P524-001.
2016-06-07 09:27:21 -07:00
Joel Brobecker
2ed2ae2212 Add support for '(no-precommit-check)' keyword in revision log
This commit enhances the hooks to recognize the '(no-precommit-check)'
keyword in commit revision logs, and when found, disable the precommit
checks.

For P426-035.
2016-04-26 06:55:07 -07:00
Joel Brobecker
768ab4e1d5 cannot push non-merge commit on branch where merge commits are rejected.
Trying to push a simple non-merge commit on a branch for which
hooks.reject-merge-commits matches fails, with the hooks rejecting
the update saying that merge commits are not allowed.

This is due to an obvious bug in reject_commit_if_merge which
tests the number of parents of a commit and causes an error
if the number of parents is at least 1. But the correct test
is for the number of parents to be at least 2 (that's the definition
of a merge commit).

Fixes NC27-001.
2014-12-27 13:21:04 +04:00
Joel Brobecker
af9f6eb000 Add support for new hooks.reject-merge-commits config variable.
For NC21-003.
2014-12-21 11:01:32 -05:00