Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/LibreOffice/solenv/clang-format/   (Office von Apache Version 25.8.3.2©)  Datei vom 5.10.2025 mit Größe 2 kB image not shown  

Quelle  check-last-commit   Sprache: JAVA

 
#!/usr/bin/env perl
This file is part of the LibreOffice project.
#
This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Checks the style of the files changed in the last commit, for CI purposes.

use strict;
use warnings;
use lib "solenv/clang-format";
use ClangFormat;

my $commit = 0;
my $commit_id = 'HEAD';

sub check_style()
{
    if ( ! -e ".git" )
    {
        # Can't diff when this is not a git checkout.
        return;
    }

    my $src = ClangFormat::get_extension_regex();
    my @good_names = ();
    my @bad_names = ();
    my $excluded_list_names = ClangFormat::get_excludelist();
    my $clang_format = ClangFormat::find();
    my $parent = $commit + 1;

    # Get a list of non-deleted changed files.
    # Explicitly use the low-level 'git diff-tree' (rather than plain 'git
    # diff') so we get the new, but not the old files for renames and/or
    # copies.
    open (FILES, "git diff-tree -r --diff-filter=AM --name-only ${commit_id}~${parent} ${commit_id}~${commit} |") ||  die "Cannot run git diff.";
    while (my $filename = <FILES>)
    {
        chomp $filename;
        if ($filename =~ /\.($src)$/ and !exists($excluded_list_names->{$filename}))
        {
            if (! -x $clang_format)
            {
                my $version = ClangFormat::get_wanted_version();

                print("solenv/clang-format/check-last-commit: ");
                print("ERROR: no clang-format ${version} was found.\n\n");

                exit(1);
            }
            if (ClangFormat::check_style($clang_format, $filename))
            {
                push @good_names, $filename;
            }
            else
            {
                push @bad_names, $filename;
            }
        }
    }

    # Enforce style.
    if (scalar @bad_names)
    {
        print("\nERROR: The above differences were found between the code to commit \n");
        print("and the clang-format rules. Tips:\n");
        print("\n- You may run '/opt/lo/bin/clang-format -i ' to fix up style automatically.\n");
        print("- See solenv/clang-format/README on where to get the required version of clang-format binaries.\n");
        print("- If you renamed an excluded file, update solenv/clang-format/excludelist accordingly to keep it excluded.\n");
        print("\nsolenv/clang-format/check-last-commit: KO\n");
        exit(1);
    }
    else
    {
        print("solenv/clang-format/check-last-commit: checked the following files:\n");
        print(join("\n", @good_names));
        print("\nsolenv/clang-format/check-last-commit: OK\n");
    }
}

if (scalar(@ARGV) == 1)
{
    if (($ARGV[0] !~ /^[0-9]+$/) || (scalar($ARGV[0]) >= 8))
    {
        $commit_id = $ARGV[0];
    }
    else
    {
        $commit = $ARGV[0];
    }
}

check_style();

exit(0);

# vim: set shiftwidth=4 softtabstop=4 expandtab:

Messung V0.5
C=97 H=92 G=94

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.