Guest User

Untitled

a guest
Jan 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4.  
  5. my $repos = shift @ARGV;
  6. my $txn = shift @ARGV;
  7.  
  8. sub msg {
  9. my $msg = shift @_;
  10. die("MSG: $msg\n");
  11. }
  12.  
  13. sub trim() {
  14. my $string = shift @_;
  15. $string =~ s/^\s+//;
  16. $string =~ s/\s+$//;
  17. return $string;
  18. }
  19.  
  20. unless ( -d $repos ) { &msg("$repos is not a directory"); }
  21.  
  22. my @changed_list = split(/\n/, `svnlook changed "$repos" -t$txn`);
  23.  
  24. foreach my $file (@changed_list) {
  25. # We only want to check Updated, merGed, or Added files
  26. if ( 1 || $file =~ m/^(U|G|A)/ ) {
  27. # Strip off the first 4 characters of the output to get the real filename
  28. $file = substr $file, 4;
  29.  
  30. # Ensure that it doesn't have any whitespace around it
  31. $file = &trim($file);
  32.  
  33. # Finally ensure this is actually a PHP file
  34. if ( $file =~ m/\.(php|phtml|php3|php4|php5|inc)$/i ) {
  35. my @file_lines = split(/\n/, `svnlook cat "$repos" "$file" -t$txn`);
  36.  
  37. # Cat the ouput from subversion and check it against php
  38. my @php_output = split(/\n/, `svnlook cat "$repos" "$file" -t$txn | php -l`);
  39. my $po_len = scalar @php_output;
  40.  
  41. my $last_line = $php_output[$po_len-1];
  42. if ( $last_line =~ m/^Errors parsing/i ) {
  43. shift @php_output; # Shift off first newline
  44. pop @php_output; # Popoff the Errors parsing text
  45. &msg("Failed to checkin $file, PHP said: @php_output");
  46. }
  47.  
  48. # Ensure the file doesn't have any hanging {'s
  49. my $line_number = 1;
  50. foreach my $line (@file_lines) {
  51. $line = &trim($line);
  52. if ( $line eq '{' ) {
  53. &msg("A starting brace { exists in file $file on line number $line_number.");
  54. }
  55. $line_number += 1;
  56. }
  57. }
  58. }
  59. }
  60.  
  61. exit 0;
Add Comment
Please, Sign In to add comment