summaryrefslogtreecommitdiff
path: root/solenv/clang-format/reformat-formatted-files
blob: 04b0adde8e4e96f841f97830773fd3e5ffbf3e77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/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/.

# Reformat files which are not blacklisted. This is interesting if the
# clang-format version or config changes.
# -n allows just listing the formatted files.

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

my $clang_format = ClangFormat::find();
my $src = ClangFormat::get_extension_regex();
my $blacklist_names = ClangFormat::get_blacklist();
my @filenames = ();
my $dry_run = 0;

# Get a list of files.
open (FILES, "git ls-files |") ||  die "Cannot run git ls-files.";
while (my $filename = <FILES>)
{
    chomp $filename;
    if ($filename =~ /\.($src)$/ and !exists($blacklist_names->{$filename}))
    {
        push @filenames, $filename;
    }
}

if ($#ARGV ge 0 && $ARGV[0] eq "-n")
{
    $dry_run = 1;
}

foreach my $filename (@filenames)
{
    my $command = $clang_format . " -i " . $filename;
    print($filename . "\n");
    if (!$dry_run)
    {
        system($command);
    }
}

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