View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0009774 | mantisbt | integration | public | 2008-11-03 15:48 | 2010-04-23 23:22 |
Reporter | mmcloughlin | Assigned To | jreese | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | suspended | ||
Product Version | 1.2.0a2 | ||||
Target Version | 1.3.0-beta.1 | ||||
Summary | 0009774: Source control integration: Issue references in log messages not found if split over multiple lines | ||||
Description | scripts/checkin.php is responsible for processing source control log messages to find references to issues. By default these references are of the form "issue 5", or "fixed issue 2", or similar as defined by source_control_regexp and source-control_fixed_regexp. These references will be missed by scripts/checkin.php if they span multiple lines. For an example see Steps To Reproduce. The problem is partly with the default choice of regular expression, and partly with the fact that scripts/checkin.php parses STDIN on a line-by-line basis. I attach a patch against SVN trunk revision 5752. | ||||
Steps To Reproduce | In the shell $ cd <mantis directory>/scripts | ||||
Tags | patch | ||||
Attached Files | source-control-log-newline.patch (2,228 bytes)
Index: scripts/checkin.php =================================================================== --- scripts/checkin.php (revision 5752) +++ scripts/checkin.php (working copy) @@ -38,32 +38,26 @@ exit( 1 ); } -if( !defined( "STDIN" ) ) { - define( "STDIN", fopen( 'php://stdin', 'r' ) ); -} - # Detect references to issues + concat all lines to have the comment log. $t_commit_regexp = config_get( 'source_control_regexp' ); $t_commit_fixed_regexp = config_get( 'source_control_fixed_regexp' ); -$t_comment = ''; +$t_comment = file_get_contents('php://stdin'); $t_issues = array(); $t_fixed_issues = array(); -while(( $t_line = fgets( STDIN, 1024 ) ) ) { - $t_comment .= $t_line; - if( preg_match_all( $t_commit_regexp, $t_line, $t_matches ) ) { - for( $i = 0;$i < count( $t_matches[0] );++$i ) { - $t_issues[] = $t_matches[1][$i]; - } - } - if( preg_match_all( $t_commit_fixed_regexp, $t_line, $t_matches ) ) { - for( $i = 0;$i < count( $t_matches[0] );++$i ) { - $t_fixed_issues[] = $t_matches[1][$i]; - } - } +if( preg_match_all( $t_commit_regexp, $t_comment, $t_matches ) ) { + for( $i = 0;$i < count( $t_matches[0] );++$i ) { + $t_issues[] = $t_matches[1][$i]; + } } +if( preg_match_all( $t_commit_fixed_regexp, $t_comment, $t_matches ) ) { + for( $i = 0;$i < count( $t_matches[0] );++$i ) { + $t_fixed_issues[] = $t_matches[1][$i]; + } +} + # If no issues found, then no work to do. if(( count( $t_issues ) == 0 ) && ( count( $t_fixed_issues ) == 0 ) ) { echo "Comment does not reference any issues.\n"; Index: config_defaults_inc.php =================================================================== --- config_defaults_inc.php (revision 5752) +++ config_defaults_inc.php (working copy) @@ -1294,7 +1294,7 @@ # Regular expression used to detect issue ids within checkin comments. # see preg_match_all() documentation at # http://www.php.net/manual/en/function.preg-match-all.php - $g_source_control_regexp = "/\bissue [#]{0,1}(\d+)\b/i"; + $g_source_control_regexp = "/\bissue\s+#?(\d+)\b/i"; # Regular expression used to detect the fact that an issue is fixed and extracts # its issue id. If there is a match to this regular expression, then the issue 0001-proposed-fix-for-issue-9774.patch (2,054 bytes)
diff --git a/config_defaults_inc.php b/config_defaults_inc.php index c90c501..21341a6 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -1294,7 +1294,7 @@ # Regular expression used to detect issue ids within checkin comments. # see preg_match_all() documentation at # http://www.php.net/manual/en/function.preg-match-all.php - $g_source_control_regexp = "/\bissue [#]{0,1}(\d+)\b/i"; + $g_source_control_regexp = "/\bissue[ \r\n]{0,1}[#]{0,1}(\d+)\b/i"; # Regular expression used to detect the fact that an issue is fixed and extracts # its issue id. If there is a match to this regular expression, then the issue diff --git a/scripts/checkin.php b/scripts/checkin.php index 0a5ebd0..682e42e 100644 --- a/scripts/checkin.php +++ b/scripts/checkin.php @@ -38,29 +38,23 @@ if( is_blank( $t_username ) || ( user_get_id_by_name( $t_username ) === false ) exit( 1 ); } -if( !defined( "STDIN" ) ) { - define( "STDIN", fopen( 'php://stdin', 'r' ) ); -} - # Detect references to issues + concat all lines to have the comment log. $t_commit_regexp = config_get( 'source_control_regexp' ); $t_commit_fixed_regexp = config_get( 'source_control_fixed_regexp' ); -$t_comment = ''; +$t_comment = file_get_contents("php://stdin"); $t_issues = array(); $t_fixed_issues = array(); -while(( $t_line = fgets( STDIN, 1024 ) ) ) { - $t_comment .= $t_line; - if( preg_match_all( $t_commit_regexp, $t_line, $t_matches ) ) { - for( $i = 0;$i < count( $t_matches[0] );++$i ) { - $t_issues[] = $t_matches[1][$i]; - } + +if( preg_match_all( $t_commit_regexp, $t_comment, $t_matches ) ) { + for( $i = 0;$i < count( $t_matches[0] );++$i ) { + $t_issues[] = $t_matches[1][$i]; } +} - if( preg_match_all( $t_commit_fixed_regexp, $t_line, $t_matches ) ) { - for( $i = 0;$i < count( $t_matches[0] );++$i ) { - $t_fixed_issues[] = $t_matches[1][$i]; - } +if( preg_match_all( $t_commit_fixed_regexp, $t_comment, $t_matches ) ) { + for( $i = 0;$i < count( $t_matches[0] );++$i ) { + $t_fixed_issues[] = $t_matches[1][$i]; } } | ||||