Added the ability to supply SVN revisions to check Mantis: 2691
git-svn-id: file:///srv/svn/scanner/trunk@6 a0501263-5b7a-4423-a8ba-1edf086583e7
This commit is contained in:
parent
2386113895
commit
af5fc8a017
1 changed files with 55 additions and 3 deletions
56
scanner.php
56
scanner.php
|
@ -17,7 +17,10 @@ $config = array(
|
||||||
'output_file' => 'php://stdout',
|
'output_file' => 'php://stdout',
|
||||||
'quiet' => false,
|
'quiet' => false,
|
||||||
);
|
);
|
||||||
$help = "Usage: {$argv[0]} [options] file|path [file|path ...]
|
$help = "Usage:
|
||||||
|
{$argv[0]} [options] file|path [file|path ...]
|
||||||
|
{$argv[0]} [options] -b base_path -r revision[,revision ...]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-b path Set the base path for the scan. Useful if you want
|
-b path Set the base path for the scan. Useful if you want
|
||||||
--base-path path to scan individual files in a code base that don't
|
--base-path path to scan individual files in a code base that don't
|
||||||
|
@ -39,6 +42,9 @@ Options:
|
||||||
-q Suppresses all progress output
|
-q Suppresses all progress output
|
||||||
--quiet
|
--quiet
|
||||||
|
|
||||||
|
-r Get files from a comma separated list of SVN revisions.
|
||||||
|
You must supply a base path first for this!
|
||||||
|
|
||||||
--svn Enables SVN integration
|
--svn Enables SVN integration
|
||||||
";
|
";
|
||||||
$faults = array();
|
$faults = array();
|
||||||
|
@ -53,7 +59,13 @@ class ScannerModule {
|
||||||
err( "Initializing " . get_class( $this ) . "...\n" );
|
err( "Initializing " . get_class( $this ) . "...\n" );
|
||||||
}
|
}
|
||||||
function fault( $object, $level, $reason = '' ) {
|
function fault( $object, $level, $reason = '' ) {
|
||||||
global $config, $faults;
|
global $config, $revisions, $faults;
|
||||||
|
if( count( $revisions ) > 0 && !in_array( $this->blame[$object['line']]['revision'], $revisions ) ) {
|
||||||
|
/* If files have been added using SVN revisions, filter out any faulty
|
||||||
|
changes that aren't a part of the requested changeset(s).
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$object['file'] = filename( $object['file'] );
|
$object['file'] = filename( $object['file'] );
|
||||||
$faults[] = $this->faults[] = array(
|
$faults[] = $this->faults[] = array(
|
||||||
'module' => get_class( $this ),
|
'module' => get_class( $this ),
|
||||||
|
@ -126,6 +138,7 @@ function err( $string ) {
|
||||||
|
|
||||||
|
|
||||||
// Handle application arguments
|
// Handle application arguments
|
||||||
|
$revisions = array();
|
||||||
$files = array();
|
$files = array();
|
||||||
$base_path = false;
|
$base_path = false;
|
||||||
for( $i = 1; $i < $argc; $i++ ) {
|
for( $i = 1; $i < $argc; $i++ ) {
|
||||||
|
@ -157,6 +170,43 @@ for( $i = 1; $i < $argc; $i++ ) {
|
||||||
case '--quiet':
|
case '--quiet':
|
||||||
$config['quiet'] = true;
|
$config['quiet'] = true;
|
||||||
break;
|
break;
|
||||||
|
case '-r':
|
||||||
|
$revs = explode( ',', $argv[++$i] );
|
||||||
|
if( $base_path === false ) {
|
||||||
|
die( "Set a base path before supplying SVN revisions\n" );
|
||||||
|
}
|
||||||
|
// First, find out what the full path is so we can trim it down to the relative one.
|
||||||
|
$xml = shell_exec( "svn info --xml $base_path" );
|
||||||
|
$parser = xml_parser_create();
|
||||||
|
xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 );
|
||||||
|
xml_parse_into_struct( $parser, $xml, $values, $index );
|
||||||
|
xml_parser_free( $parser );
|
||||||
|
foreach( $values as $value ) {
|
||||||
|
switch( $value['tag'] ) {
|
||||||
|
case 'URL':
|
||||||
|
$svn_url = $value['value'];
|
||||||
|
break;
|
||||||
|
case 'ROOT':
|
||||||
|
$svn_root = $value['value'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$svn_base = substr( $svn_url, strlen( $svn_root ) );
|
||||||
|
foreach( $revs as $rev ) {
|
||||||
|
$revisions[] = $rev = intval( $rev );
|
||||||
|
$xml = shell_exec( "svn log -v --xml -r $rev $base_path" );
|
||||||
|
$parser = xml_parser_create();
|
||||||
|
xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 );
|
||||||
|
xml_parse_into_struct( $parser, $xml, $values, $index );
|
||||||
|
xml_parser_free( $parser );
|
||||||
|
foreach( $values as $value ) {
|
||||||
|
if( $value['tag'] == 'PATH' ) {
|
||||||
|
$file = realpath( $base_path . substr( $value['value'], strlen( $svn_base ) ) );
|
||||||
|
if( !in_array( $file, $files ) ) {
|
||||||
|
$files[] = $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
case '--svn':
|
case '--svn':
|
||||||
$config['svn'] = true;
|
$config['svn'] = true;
|
||||||
break;
|
break;
|
||||||
|
@ -220,5 +270,7 @@ foreach( $files as $file ) {
|
||||||
}
|
}
|
||||||
err( "\n" );
|
err( "\n" );
|
||||||
$modules['output']->write( $config['output_file'] );
|
$modules['output']->write( $config['output_file'] );
|
||||||
|
|
||||||
|
sleep( 1 );
|
||||||
err( sprintf( "Found %d faults in %d files.\n", count( $faults ), count( $files ) ) );
|
err( sprintf( "Found %d faults in %d files.\n", count( $faults ), count( $files ) ) );
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in a new issue