Index: commitlog.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/versioncontrol/commitlog/commitlog.module,v retrieving revision 1.26 diff -u -r1.26 commitlog.module --- commitlog.module 8 Nov 2007 02:58:36 -0000 1.26 +++ commitlog.module 7 Dec 2007 19:38:43 -0000 @@ -492,6 +492,7 @@ $variables['time'] = format_date($commit['date'], 'custom', 'H:i'); $variables['actions'] = theme('commitlog_commit_actions', $commit, $commit_actions, $format); + $variables['statistics'] = theme('commitlog_commit_statistics', $commit, versioncontrol_get_commit_statistics($commit), $format); $variables['message'] = theme('commitlog_commit_message', $commit, $format); $variables['branches'] = theme('commitlog_commit_branches', $commit, $format); @@ -511,6 +512,7 @@ '!name' => $variables['username'], '!time' => $variables['time'], )); + $output .= ' ('. $variables['statistics'] .')'; $output .= "\n"; // class "title" $output .= '
'. $variables['actions'] .'
'."\n"; @@ -652,6 +654,64 @@ return implode(', ', $branches); } +function commitlog_standard_deviation($total_x2, $total_x, $n) { + if($n == 0) { + return 0; + } + return sqrt($total_x2 / $n - pow($total_x / $n, 2)); +} + +function theme_commitlog_commit_statistics($commit, $commit_statistics, $format = 'html') { + $lines = array(); + + if ($format == 'html' && $commit_statistics['action_count'] > 1) { + // Add in standard deviation of lines added for HTML output when there is more than one action (and hence S.D. =/= 0) + $action_string = '!count'; + } + else { + $action_string = '!count'; + } + if ($commit_statistics['lines_added'] == 1) { + $action_string .= ' line added'; + } + else { + $action_string .= ' lines added'; + } + $lines[] = strtr($action_string, array( + '!count' => $commit_statistics['lines_added'], + '!sd' => commitlog_standard_deviation($commit_statistics['lines_added_squared'], $commit_statistics['lines_added'], $commit_statistics['action_count']), + )); + + if ($format == 'html' && $commit_statistics['action_count'] > 1) { + // Add in standard deviation of lines removed for HTML output when there is more than one action (and hence S.D. =/= 0) + $action_string = '!count'; + } + else { + $action_string = '!count'; + } + if ($commit_statistics['lines_removed'] == 1) { + $action_string .= ' line removed'; + } + else { + $action_string .= ' lines removed'; + } + $lines[] = strtr($action_string, array( + '!count' => $commit_statistics['lines_removed'], + '!sd' => commitlog_standard_deviation($commit_statistics['lines_removed_squared'], $commit_statistics['lines_removed'], $commit_statistics['action_count']), + )); + + if ($commit_statistics['action_count'] == 1) { + $action_string = '!count action'; + } + else { + $action_string = '!count actions'; + } + $lines[] = strtr($action_string, array( + '!count' => $commit_statistics['action_count'], + )); + + return implode(", ", $lines); +} function theme_commitlog_commit_actions($commit, $commit_actions, $format = 'html') { if (empty($commit_actions)) {