Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use strict;
- my $repos = shift @ARGV;
- my $txn = shift @ARGV;
- sub msg {
- my $msg = shift @_;
- die("MSG: $msg\n");
- }
- sub trim() {
- my $string = shift @_;
- $string =~ s/^\s+//;
- $string =~ s/\s+$//;
- return $string;
- }
- unless ( -d $repos ) { &msg("$repos is not a directory"); }
- my @changed_list = split(/\n/, `svnlook changed "$repos" -t$txn`);
- foreach my $file (@changed_list) {
- # We only want to check Updated, merGed, or Added files
- if ( 1 || $file =~ m/^(U|G|A)/ ) {
- # Strip off the first 4 characters of the output to get the real filename
- $file = substr $file, 4;
- # Ensure that it doesn't have any whitespace around it
- $file = &trim($file);
- # Finally ensure this is actually a PHP file
- if ( $file =~ m/\.(php|phtml|php3|php4|php5|inc)$/i ) {
- my @file_lines = split(/\n/, `svnlook cat "$repos" "$file" -t$txn`);
- # Cat the ouput from subversion and check it against php
- my @php_output = split(/\n/, `svnlook cat "$repos" "$file" -t$txn | php -l`);
- my $po_len = scalar @php_output;
- my $last_line = $php_output[$po_len-1];
- if ( $last_line =~ m/^Errors parsing/i ) {
- shift @php_output; # Shift off first newline
- pop @php_output; # Popoff the Errors parsing text
- &msg("Failed to checkin $file, PHP said: @php_output");
- }
- # Ensure the file doesn't have any hanging {'s
- my $line_number = 1;
- foreach my $line (@file_lines) {
- $line = &trim($line);
- if ( $line eq '{' ) {
- &msg("A starting brace { exists in file $file on line number $line_number.");
- }
- $line_number += 1;
- }
- }
- }
- }
- exit 0;
Add Comment
Please, Sign In to add comment