From b684d89eefa6098ad885fa29328bfe09724fdcdd Mon Sep 17 00:00:00 2001 From: Zane Shelley Date: Mon, 2 Mar 2020 19:52:17 -0600 Subject: [PATCH] Minor fixes to addCopyright and pre-commit hooks Fixes: - Undefined variable warning when a prolog has no copyright years. - Literal variable name used instead of variable value. - Unnecessary error exit when error (file not found) is a valid scenario. - pre-commit hooks not ran on files that have been renamed. Change-Id: I69ab4db934b38a44b0ac46730556c01a649fa827 Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/92649 Tested-by: Jenkins Server Tested-by: Jenkins OP Build CI Reviewed-by: Benjamen G Tyner Reviewed-by: Caleb N Palmer Reviewed-by: Brian J Stegmiller Reviewed-by: Zane C Shelley Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/92850 Tested-by: Jenkins OP HW Tested-by: FSP CI Jenkins --- src/build/tools/addCopyright | 28 +++++----------------------- src/build/tools/pre-commit-actions | 4 ++-- src/build/tools/pre-commit-prologs | 4 ++-- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/build/tools/addCopyright b/src/build/tools/addCopyright index 79c4eb30924..c963254c3c6 100755 --- a/src/build/tools/addCopyright +++ b/src/build/tools/addCopyright @@ -693,37 +693,19 @@ sub createYearString($) my ( $filename ) = @_; # The list of years starts with the years in the current prolog and the - # current release year. - my @years = (); - - # Get size of array @CopyRightYears - my $size = @CopyRightYears; - if ( $size < 2 ) ## If less than 2 then date entry has only a year mentioned - { - @years = @CopyRightYears; - # add current year if not already in list - if ( ($years[0] ne $ReleaseYear) ) - { - push @years, $ReleaseYear ; - } - } - else - { - @years = ( @CopyRightYears, $ReleaseYear ); - } + # current release year. Note that duplicates will be stripped later. + my @years = ( @CopyRightYears, $ReleaseYear ); ## Make a call to git to find the earliest commit date of the file ## new files will not have a log, so the "git log" call above will ## return nothing. ## Push any year we find onto the @years array - my $cmd = 'git log -n1 -- $filename | grep "Date" '; + my $cmd = "git log -n1 -- $filename | grep 'Date' "; ## print "run $cmd\n"; my @logstrings = split( " ", `$cmd` ); - if ( $? ) { die "ERROR $? : Could not run $cmd $!\n"; } - - if ( scalar(@logstrings) >= 5 ) + if ( not $? and (5 <= scalar @logstrings) ) { - push @years, $logstrings[5] ; + push @years, $logstrings[5]; } # Get a unique list of years and sort the list. diff --git a/src/build/tools/pre-commit-actions b/src/build/tools/pre-commit-actions index a914663d240..7675c9b07a3 100755 --- a/src/build/tools/pre-commit-actions +++ b/src/build/tools/pre-commit-actions @@ -6,7 +6,7 @@ # # OpenPOWER HostBoot Project # -# Contributors Listed Below - COPYRIGHT 2015,2018 +# Contributors Listed Below - COPYRIGHT 2015,2020 # [+] International Business Machines Corp. # # @@ -32,7 +32,7 @@ my $xmlSortingScript = "applyTargetingStyle"; ## Make up a list of all staged files ( --cached --name-only ) ## Filter for only Added or Modified ( --diff-filter=AM ) -chomp( my @fileList = `git diff --cached --name-only --diff-filter=AM` ); +chomp( my @fileList = `git diff --cached --name-only --diff-filter=AMR` ); if ( @fileList ) diff --git a/src/build/tools/pre-commit-prologs b/src/build/tools/pre-commit-prologs index a64e4d17696..21283c0d508 100755 --- a/src/build/tools/pre-commit-prologs +++ b/src/build/tools/pre-commit-prologs @@ -6,7 +6,7 @@ # # OpenPOWER HostBoot Project # -# Contributors Listed Below - COPYRIGHT 2011,2016 +# Contributors Listed Below - COPYRIGHT 2011,2020 # [+] International Business Machines Corp. # # @@ -30,7 +30,7 @@ my $script = "addCopyright"; ## Make up a list of all staged files ( --cached --name-only ) ## Filter for only Added or Modified ( --diff-filter=AM ) -chomp( my @fileList = `git diff --cached --name-only --diff-filter=AM` ); +chomp( my @fileList = `git diff --cached --name-only --diff-filter=AMR` ); if ( @fileList ) {