@@ -117,17 +117,21 @@ public function precommit( ) {
117117 }
118118
119119 public function commit ( $ p_repo , $ p_data ) {
120+ # Handle branch names with '+' character
121+ $ p_data = str_replace ('_plus_ ' , '+ ' , $ p_data );
122+
120123 # The -d option from curl requires you to encode your own data.
121124 # Once it reaches here it is decoded. Hence we split by a space
122125 # were as the curl command uses a '+' character instead.
123126 # i.e. DATA=`echo $INPUT | sed -e 's/ /+/g'`
124127 list ( , $ t_commit_id , $ t_branch ) = explode (' ' , $ p_data );
125- list ( , , $ t_branch ) = explode ('/ ' , $ t_branch );
128+ list ( , , $ t_branch ) = explode ('/ ' , $ t_branch , 3 );
129+
126130 # master_branch contains comma-separated list of branches
127131 $ t_branches = explode (', ' , $ p_repo ->info ['master_branch ' ]);
128- if (!in_array ($ t_branch , $ t_branches ))
132+ if (!in_array (' * ' , $ t_branches ) and ! in_array ( $ t_branch , $ t_branches ))
129133 {
130- return ;
134+ return ;
131135 }
132136
133137 return $ this ->import_commits ($ p_repo , null , $ t_commit_id , $ t_branch );
@@ -218,11 +222,14 @@ private function import_commits( $p_repo, $p_uri_base, $p_commit_ids, $p_branch=
218222
219223 echo "Retrieving $ t_commit_id ... " ;
220224
221- $ t_commit_url = $ this ->uri_base ( $ p_repo ) . 'a=commit;h= ' . $ t_commit_id ;
225+ # Handle branch names with '+' character
226+ $ t_fixed_id = str_replace ('+ ' , '%2B ' , $ t_commit_id );
227+ $ t_commit_url = $ this ->uri_base ( $ p_repo ) . 'a=commit;h= ' . $ t_fixed_id ;
222228 $ t_input = url_get ( $ t_commit_url );
223229
224230 if ( false === $ t_input ) {
225231 echo "failed. \n" ;
232+ echo "$ t_commit_url \n" ; # DEBUG
226233 continue ;
227234 }
228235
@@ -232,6 +239,7 @@ private function import_commits( $p_repo, $p_uri_base, $p_commit_ids, $p_branch=
232239 }
233240
234241 $ s_parents = array_merge ( $ s_parents , $ t_commit_parents );
242+ $ s_counter += 1 ;
235243 }
236244
237245 $ s_counter = 0 ;
@@ -274,37 +282,34 @@ private function commit_changeset( $p_repo, $p_input, $p_branch='' ) {
274282 if ( !SourceChangeset::exists ( $ p_repo ->id , $ t_commit ['revision ' ] ) ) {
275283
276284 # Parse for commit data
277- preg_match ( '#<tr><td>author</td><td>(?:<a[^>]*>)?([^<>]*)(?:</a>)? *(?:<a[^>]*>)?<([^<>]*)>(?:</a>)?</td>(?:<[^<>]*>\s*)*?</tr>\n<tr><td></td><td><span class="datetime">\w*, (\d* \w* \d* \d*:\d*:\d*)# ' , $ t_gitweb_data , $ t_matches );
285+ preg_match ( '#authored by ([^"]*).*?authored by ([^"]*).*?>([^<]*\d*:\d*:\d*[^(<]*) '
286+ . '.*?committed by ([^"]*).*?committed by ([^"]*).*?page_body">(.*?)</div># ' ,
287+ $ t_gitweb_data , $ t_matches );
278288 $ t_commit ['author ' ] = $ t_matches [1 ];
279289 $ t_commit ['author_email ' ] = $ t_matches [2 ];
280290 $ t_commit ['date ' ] = date ( 'Y-m-d H:i:s ' , strtotime ( $ t_matches [3 ] ) );
281-
282- if ( preg_match ( '#<tr><td>committer</td><td>(?:<a[^>]*>)?([^<>]*)(?:</a>)? *(?:<a[^>]*>)?<([^<>]*)>(?:</a>)?</td>(?:<[^<>]*>\s*)*?</tr># ' , $ t_gitweb_data , $ t_matches ) ) {
283- $ t_commit ['committer ' ] = $ t_matches [1 ];
284- $ t_commit ['committer_email ' ] = $ t_matches [2 ];
285- }
291+ $ t_commit ['committer ' ] = $ t_matches [4 ];
292+ $ t_commit ['committer_email ' ] = $ t_matches [5 ];
293+ $ t_commit ['message ' ] = trim ( str_replace ( '<br/> ' , PHP_EOL , $ t_matches [6 ] ) );
286294
287295 $ t_parents = array ();
288- if ( preg_match_all ( '#<tr><td> parent</td><td class="sha1"><a [^< >]*>([a-f0-9 ]*)</a></td> # ' , $ t_gitweb_data , $ t_matches ) ) {
296+ if ( preg_match_all ( '#parent</td><td class="sha1"><[^ >]*h=([0-9a-f ]*)# ' , $ t_gitweb_data , $ t_matches ) ) {
289297 foreach ( $ t_matches [1 ] as $ t_match ) {
290298 $ t_parents [] = $ t_commit ['parent ' ] = $ t_match ;
291299 }
292300 }
293301
294- preg_match ( '#<div class="page_body">\n(.*)\n</div># ' , $ t_gitweb_data , $ t_matches );
295- $ t_commit ['message ' ] = trim ( str_replace ( '<br/> ' , PHP_EOL , $ t_matches [1 ] ) );
296-
297302 # Strip ref links and signoff spans from commit message
298- $ t_commit ['message ' ] = preg_replace ( array (
299- '@<a[^>]*>([^<]*)<\/a>@ ' ,
300- '@<span[^>]*>([^<]*<[^>]*>[^<]*)<\/span>@ ' , #finds <span..>signed-off by <email></span>
301- ), '$1 ' , $ t_commit ['message ' ] );
303+ $ t_commit ['message ' ] = preg_replace ( array ( '#<a[^>]*>([^<]*)</a># ' , '#<span[^>]*>(.*?)</span># ' ),
304+ '$1 ' , $ t_commit ['message ' ] );
305+
306+ # Prepend a # sign to mantis number
307+ $ t_commit ['message ' ] = preg_replace ( '#(mantis)\s+(\d+)#i ' , '$1 #$2 ' ,$ t_commit ['message ' ] );
302308
303309 # Parse for changed file data
304310 $ t_commit ['files ' ] = array ();
305311
306- preg_match_all ( '#<tr class="(?:light|dark)">\n<td><a class="list" href="[^"]*;h=(\w+);[^"]*">([^<>]+)</a></td> ' .
307- '\n<td>(?:<span class="file_status (\w+)">[^<>]*</span>)?</td># ' ,
312+ preg_match_all ( '#class="list".*?h=(\w*)[^>]*>([^<]*)</a>(?:(?:</td><td><span class="file_status|[^%]*%) (\w*))?# ' ,
308313 $ t_gitweb_files , $ t_matches , PREG_SET_ORDER );
309314
310315 foreach ( $ t_matches as $ t_file_matches ) {
@@ -313,10 +318,12 @@ private function commit_changeset( $p_repo, $p_input, $p_branch='' ) {
313318 $ t_file ['revision ' ] = $ t_file_matches [1 ];
314319
315320 if ( isset ( $ t_file_matches [3 ] ) ) {
316- if ( 'new ' == $ t_file_matches [3 ] ) {
321+ if ( $ t_file_matches [ 3 ] == 'new ' or $ t_file_matches [3 ] == ' moved ' ) {
317322 $ t_file ['action ' ] = 'add ' ;
318- } else if ( 'deleted ' == $ t_file_matches [3 ] ) {
323+ } else if ( $ t_file_matches [ 3 ] == 'deleted ' or $ t_file_matches [3 ] == ' similarity ' ) {
319324 $ t_file ['action ' ] = 'rm ' ;
325+ } else {
326+ $ t_file ['action ' ] = 'mod ' ;
320327 }
321328 } else {
322329 $ t_file ['action ' ] = 'mod ' ;
0 commit comments