#!/usr/bin/env php substr( $commit['hash'], 1, 8 ), 'subject' => $subject, 'bugs' => $bugs, ); } chdir( $gitDir ); return $gitLog; } /** * @param string $oldRev * @param string $newRev * @return array * @throws Exception */ function full_git_log_as_array( $oldRev, $newRev ) { $command = "git log --format=medium --cherry-pick --right-only --no-merges $oldRev..$newRev"; try { $output = capture_output( $command ); } catch( ExecException $e ) { throw new Exception( "Problem with command: $command\n" . "******** LIKELY CAUSE: you need to run 'git fetch --all' in a sub directory" ); } $history = array(); foreach( $output as $line ) { if( strpos( $line, 'commit ' ) === 0 ) { if( !empty( $commit ) ) { array_push( $history, $commit ); unset( $commit ); } $commit['hash'] = substr( $line, strlen( 'commit' ) ); continue; } elseif( strpos( $line, 'Author' ) === 0 || strpos( $line, 'Date' ) === 0 ) { continue; } else { if( isset( $commit['message'] ) ) { $commit['message'] .= "\n" . $line; } else { $commit['message'] = $line; } continue; } } return $history; } /** * filter_git_output - perform any extra functions needed prior to posting to * a wiki page (sanitization, making obvious removals, linking bugs, etc) * @param array $logoutput * @return string */ function filter_git_output( $logoutput ) { $retval = ''; if ( !$logoutput ) { return $retval; } $skipLines = array( 'Localisation updates from', 'COMMITMSG', // Fix for escaping fail leaving a commit summary of $COMMITMSG 'Add (\.gitreview and )?\.gitignore', 'Creating new WMF', 'Commit of various live hacks', // Our catchall patch for live hacky stuff 'Applied patches to new WMF', 'Bump .*? for deployment', ); foreach ( $logoutput as $record ) { foreach( $skipLines as $skip ) { if ( preg_match( '/' . $skip . '/i', $record['subject'] ) ) { continue 2; } } $retval .= '* '; if ( $record['bugs'] ) { $retval .= '(' . implode( ', ', $record['bugs'] ) . ') '; } $retval .= $record['subject']; // $retval .= " {{git|{$record['hash']}}}"; $retval .= "\n"; } return $retval; } /** * Main program flow * Get changes for mobile frontend * @param array $argv */ function main( $argv ) { list( $oldbranch, $newbranch ) = get_args( $argv ); print filter_git_output( useful_git_log( $oldbranch, $newbranch ) ); } main( $argv );