diff --git a/SourceGitweb/SourceGitweb.php b/SourceGitweb/SourceGitweb.php index eeb7ec2..6c20d08 100644 --- a/SourceGitweb/SourceGitweb.php +++ b/SourceGitweb/SourceGitweb.php @@ -117,17 +117,21 @@ } public function commit( $p_repo, $p_data ) { + # Handle branch names with '+' character + $p_data = str_replace('_plus_', '+', $p_data); + # The -d option from curl requires you to encode your own data. # Once it reaches here it is decoded. Hence we split by a space # were as the curl command uses a '+' character instead. # i.e. DATA=`echo $INPUT | sed -e 's/ /+/g'` list ( , $t_commit_id, $t_branch) = explode(' ', $p_data); - list ( , , $t_branch) = explode('/', $t_branch); + list ( , , $t_branch) = explode('/', $t_branch, 3); + # master_branch contains comma-separated list of branches $t_branches = explode(',', $p_repo->info['master_branch']); - if (!in_array($t_branch, $t_branches)) + if (!in_array('*', $t_branches) and !in_array($t_branch, $t_branches)) { - return; + return; } return $this->import_commits($p_repo, null, $t_commit_id, $t_branch); @@ -218,11 +222,14 @@ echo "Retrieving $t_commit_id ... "; - $t_commit_url = $this->uri_base( $p_repo ) . 'a=commit;h=' . $t_commit_id; + # Handle branch names with '+' character + $t_fixed_id = str_replace('+', '%2B', $t_commit_id); + $t_commit_url = $this->uri_base( $p_repo ) . 'a=commit;h=' . $t_fixed_id; $t_input = url_get( $t_commit_url ); if ( false === $t_input ) { echo "failed.\n"; + echo "$t_commit_url\n"; # DEBUG continue; } @@ -232,6 +239,7 @@ } $s_parents = array_merge( $s_parents, $t_commit_parents ); + $s_counter += 1; } $s_counter = 0; @@ -274,37 +282,34 @@ if ( !SourceChangeset::exists( $p_repo->id, $t_commit['revision'] ) ) { # Parse for commit data - preg_match( '#author(?:]*>)?([^<>]*)(?:)? *(?:]*>)?<([^<>]*)>(?:)?(?:<[^<>]*>\s*)*?\n\w*, (\d* \w* \d* \d*:\d*:\d*)#', $t_gitweb_data, $t_matches ); + preg_match( '#authored by ([^"]*).*?authored by ([^"]*).*?>([^<]*\d*:\d*:\d*[^(<]*)' + . '.*?committed by ([^"]*).*?committed by ([^"]*).*?page_body">(.*?)#', + $t_gitweb_data, $t_matches ); $t_commit['author'] = $t_matches[1]; $t_commit['author_email'] = $t_matches[2]; $t_commit['date'] = date( 'Y-m-d H:i:s', strtotime( $t_matches[3] ) ); - - if( preg_match( '#committer(?:]*>)?([^<>]*)(?:)? *(?:]*>)?<([^<>]*)>(?:)?(?:<[^<>]*>\s*)*?#', $t_gitweb_data, $t_matches ) ) { - $t_commit['committer'] = $t_matches[1]; - $t_commit['committer_email'] = $t_matches[2]; - } + $t_commit['committer'] = $t_matches[4]; + $t_commit['committer_email'] = $t_matches[5]; + $t_commit['message'] = trim( str_replace( '
', PHP_EOL, $t_matches[6] ) ); $t_parents = array(); - if( preg_match_all( '#parent]*>([a-f0-9]*)#', $t_gitweb_data, $t_matches ) ) { + if ( preg_match_all( '#parent<[^>]*h=([0-9a-f]*)#', $t_gitweb_data, $t_matches ) ) { foreach( $t_matches[1] as $t_match ) { $t_parents[] = $t_commit['parent'] = $t_match; } } - preg_match( '#
\n(.*)\n
#', $t_gitweb_data, $t_matches ); - $t_commit['message'] = trim( str_replace( '
', PHP_EOL, $t_matches[1] ) ); - # Strip ref links and signoff spans from commit message - $t_commit['message'] = preg_replace( array( - '@]*>([^<]*)<\/a>@', - '@]*>([^<]*<[^>]*>[^<]*)<\/span>@', #finds signed-off by
- ), '$1', $t_commit['message'] ); + $t_commit['message'] = preg_replace( array( '#]*>([^<]*)#', '#]*>(.*?)#' ), + '$1', $t_commit['message'] ); + + # Prepend a # sign to mantis number + $t_commit['message'] = preg_replace( '#(mantis)\s+(\d+)#i', '$1 #$2',$t_commit['message'] ); # Parse for changed file data $t_commit['files'] = array(); - preg_match_all( '#\n([^<>]+)'. - '\n(?:[^<>]*)?#', + preg_match_all( '#class="list".*?h=(\w*)[^>]*>([^<]*)(?:(?: