From: Alex Rousskov Date: Tue, 29 Mar 2016 16:58:12 +0000 (-0600) Subject: Cleanup: Automatically remove duplicated #include lines. X-Git-Tag: SQUID_4_0_8~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0c2d21bbfa4d98c022e82ef82c46f8bb924cb8ad;p=thirdparty%2Fsquid.git Cleanup: Automatically remove duplicated #include lines. --- diff --git a/scripts/sort-includes.pl b/scripts/sort-includes.pl index 5c81e66d89..6252dd2e38 100755 --- a/scripts/sort-includes.pl +++ b/scripts/sort-includes.pl @@ -7,8 +7,6 @@ ## Please see the COPYING and CONTRIBUTORS files for details. ## -# AUTHOR: Francesco Chemolli -# # USAGE: sort-includes.pl filename.cc >filename.cc.sorted # # This tool helps to sort the #include directives in a c or c++ source file @@ -24,23 +22,34 @@ use strict; use warnings; -my @acc=(); #if empty, we're not accumulating + +my %Seen = (); # preprocessor #include lines, indexed by file name + while (<>) { - if (m!^#include "!) { - if (m!squid.h!) { - print; - } else { - push @acc,$_; + if (/^\s*#\s*include\s*"(.+?)"/) { + my $fname = $1; + # skip repeated file names that have identical #include lines + if (defined $Seen{$fname}) { + next if $Seen{$fname} eq $_; + warn("$ARGV:$.: Warning: inconsistent $fname #include lines:\n"); + warn(" $Seen{$fname}"); + warn(" $_"); + # fall through to preserve every unique #include line } + $Seen{$fname} = $_; } else { - &dump_acc; + &dumpSeen(); print; } } -&dump_acc; +&dumpSeen(); -sub dump_acc { - return unless @acc; - print sort {lc($a) cmp lc($b)} @acc; - @acc=(); +sub dumpSeen { + my $alwaysFirst = 'squid.h'; + if (defined $Seen{$alwaysFirst}) { + print $Seen{$alwaysFirst}; + delete $Seen{$alwaysFirst}; + } + print sort { lc($a) cmp lc($b) } values %Seen; + %Seen = (); } diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 507142eba5..d744cbfce4 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -20,7 +20,6 @@ #include "format/Token.h" #include "FwdState.h" #include "globals.h" -#include "globals.h" #include "http/Stream.h" #include "HttpHeaderTools.h" #include "HttpReply.h" diff --git a/src/log/access_log.cc b/src/log/access_log.cc index a3fc35a4b0..314ef5402d 100644 --- a/src/log/access_log.cc +++ b/src/log/access_log.cc @@ -17,8 +17,6 @@ #include "CachePeer.h" #include "err_detail_type.h" #include "errorpage.h" -#include "errorpage.h" -#include "errorpage.h" #include "format/Token.h" #include "globals.h" #include "hier_code.h" diff --git a/src/security/PeerOptions.cc b/src/security/PeerOptions.cc index 5f21437d3f..74c7a9673c 100644 --- a/src/security/PeerOptions.cc +++ b/src/security/PeerOptions.cc @@ -12,7 +12,6 @@ #include "fatal.h" #include "globals.h" #include "parser/Tokenizer.h" -#include "parser/Tokenizer.h" #include "Parsing.h" #include "security/PeerOptions.h" diff --git a/src/tests/testHttp1Parser.cc b/src/tests/testHttp1Parser.cc index b01e786fcc..446e409121 100644 --- a/src/tests/testHttp1Parser.cc +++ b/src/tests/testHttp1Parser.cc @@ -19,7 +19,6 @@ #include "MemBuf.h" #include "SquidConfig.h" #include "testHttp1Parser.h" -#include "testHttp1Parser.h" #include "unitTestMain.h" CPPUNIT_TEST_SUITE_REGISTRATION( testHttp1Parser );