2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # Checks the style of the files changed in the last commit, for CI purposes.
12 use lib
"solenv/clang-format";
16 my $commit_id = 'HEAD';
22 # Can't diff when this is not a git checkout.
26 my $src = ClangFormat
::get_extension_regex
();
29 my $blacklist_names = ClangFormat
::get_blacklist
();
30 my $clang_format = ClangFormat
::find
();
31 my $parent = $commit + 1;
33 # Get a list of non-deleted changed files.
34 # Explicitly use the low-level 'git diff-tree' (rather than plain 'git
35 # diff') so we get the new, but not the old files for renames and/or
37 open (FILES
, "git diff-tree -r --diff-filter=AM --name-only ${commit_id}~${parent} ${commit_id}~${commit} |") || die "Cannot run git diff.";
38 while (my $filename = <FILES
>)
41 if ($filename =~ /\.($src)$/ and !exists($blacklist_names->{$filename}))
43 if (! -x
$clang_format)
45 my $version = ClangFormat
::get_wanted_version
();
47 print("solenv/clang-format/check-last-commit: ");
48 print("ERROR: no clang-format ${version} was found.\n\n");
52 if (ClangFormat
::check_style
($clang_format, $filename))
54 push @good_names, $filename;
58 push @bad_names, $filename;
64 if (scalar @bad_names)
66 print("\nERROR: The above differences were found between the code to commit \n");
67 print("and the clang-format rules. Tips:\n");
68 print("\n- You may run '/opt/lo/bin/clang-format -i <problematic file>' to fix up style automatically.\n");
69 print("- See solenv/clang-format/README on where to get the required version of clang-format binaries.\n");
70 print("- If you renamed a blacklisted file, update solenv/clang-format/blacklist accordingly to keep it blacklisted.\n");
71 print("\nsolenv/clang-format/check-last-commit: KO\n");
76 print("solenv/clang-format/check-last-commit: checked the following files:\n");
77 print(join("\n", @good_names));
78 print("\nsolenv/clang-format/check-last-commit: OK\n");
82 if (scalar(@ARGV) == 1)
84 if (($ARGV[0] !~ /^[0-9]+$/) || (scalar($ARGV[0]) >= 8))
86 $commit_id = $ARGV[0];
98 # vim: set shiftwidth=4 softtabstop=4 expandtab: