View Issue Details

IDProjectCategoryView StatusLast Update
0007331mantisbtotherpublic2010-09-19 03:11
Reporterjba-mono Assigned Todhx  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionwon't fix 
Summary0007331: Make Source Control Regex's work better with $g_bug_link_tag
Description

Hi guys,

I just noticed a confusing behaviour of mantis when used with Source Control integration.

It has to do with having multiple issues fixed on the one line, but doesn't depend on it.

Anyhow, core/checkin.php uses the regex $g_source_control_regexp to detect issue numbers for fixed issues, but when rendring issue notes and comments it uses $g_bug_link_tag to detect issues (and mark them up with html links). This is a confusing behaviour.

Wouldn't it be better if we used the same (regex) logic that identifies issue's in commit logs to identify (and mark up) issues in issue text, notes and history?

Am relating this to 0007330, since multiple comma-separated issue matching is a tricky one. If we can get 0007330 to work nicer it would make sense to then use that code to mark up the text in an issue for issue numbers with URLs.

TagsNo tags attached.
Attached Files
string_process_bug_link.txt (1,249 bytes)   
	function string_process_bug_link( $p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false ) {
		$t_tag = config_get( 'bug_link_tag' );
		# bail if the link tag is blank
		if ( '' == $t_tag ) {
			return $p_string;
		}

		$t_commit_regexp = config_get( 'source_control_regexp' );
		$t_issue_number_regexp = config_get( 'source_control_issue_number_regexp' );

		$t_comment = '';
		$t_issues = array();
		$t_fixed_issues = array();

		$t_lines = split(chr(10), $p_string);
		foreach ($t_lines as $t_line) {
			if ( preg_match_all( $t_commit_regexp, $t_line, $t_matches ) ) {		
				# now extract all the issue numbers
				$t_issue_full_text = $t_matches[0][0];
				if ( preg_match_all( $t_issue_number_regexp, $t_issue_full_text, $t_matches ) ) {				
					for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
						$t_issues[] = $t_matches[0][$i];
						if ( $p_include_anchor ) {
							$t_line = str_replace($t_matches[0][$i], string_get_bug_view_link( $t_matches[0][$i], null, $p_detail_info, $p_fqdn ), $t_line);
						} else {
							$t_line = str_replace($t_matches[0][$i], string_get_bug_view_url_with_fqdn( $t_bug_id, null ), $t_line);
						}
					}
				}
			}
			$t_comment .= $t_line.chr(10);
		}

		return $t_comment;
	}
string_process_bug_link.txt (1,249 bytes)   
new_string_process_bug_link.txt (1,085 bytes)   
	function string_process_bug_link( $p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false ) {
		$t_commit_regexp = config_get( 'source_control_regexp' );
		$t_issue_number_regexp = config_get( 'source_control_issue_number_regexp' );

		$t_comment = '';
		$t_matches = array();
		$t_lines = array();

		$t_lines = split(chr(10), $p_string);
		foreach ($t_lines as $t_line) {
			if ( preg_match_all( $t_commit_regexp, $t_line, $t_matches ) ) {
				$t_issue_full_text = $t_matches[0][0];
				if ( preg_match_all( $t_issue_number_regexp, $t_issue_full_text, $t_matches ) ) {
					for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
						$t_bug_id  = $t_matches[0][$i];
						if ( !$p_include_anchor ) {
							$t_line = str_replace($t_bug_id , string_get_bug_view_url_with_fqdn( $t_bug_id , null ), $t_line);
						} elseif(bug_exists( $t_bug_id  ))  {
							$t_line = str_replace($t_bug_id , string_get_bug_view_link( $t_bug_id , null, $p_detail_info, $p_fqdn ), $t_line);
						}
					}
				}
			}
			$t_comment .= $t_line.chr(10);
		}

		return $t_comment;
	}

Relationships

related to 0007330 closeddhx Make Source Control Regex's work better for comma separated issue messages 
related to 0011732 closeddhx Remove built-in source code integration support 

Activities

jba-mono

jba-mono

2006-08-03 22:57

reporter   ~0013186

Looks like issue reporter's can't update issue relationships. Can someone update the relationship when they get round to triaging this issue. Thanks

psylem

psylem

2008-01-10 23:00

reporter   ~0016632

Thanks for the code from issue 0007330, that worked well for TortoiseSVN integration. I don't know why your fix wasn't taken on board in the main release. Did you ever come up with a work around for this issue?

I've had a look at the function string_process_bug_link in string_api.php. That's some hardcore regular expression action going on. I'd have to delete it and start from scratch if I was going to fix this issue. I'd like to see that code replaced with a function call to a common function which as you said is used in both checkin.php as well as string_api.php (probably just using the code you have produced).

I find the use of the preg_match_all function very confusing but the original author states that he thinks it's easier to understand....
http://mantisbt.cvs.sourceforge.net/mantisbt/mantisbt/core/string_api.php?revision=1.20&view=markup

A few neat lines of code is a lot easier to understand and later to maintain than a long regular expression string, so I think I'll bin it and try to adapt your code into a function.

dhx

dhx

2010-03-31 04:15

reporter   ~0024952

Won't fix as this old source code integration support is being dropped in favour of using a more modern plugin approach with the SourceIntegration plugin.

Refer to 0011732 for more details and feedback.