Index: versioncontrol.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/versioncontrol/versioncontrol.module,v retrieving revision 1.76 diff -u -r1.76 versioncontrol.module --- versioncontrol.module 9 Nov 2007 20:23:25 -0000 1.76 +++ versioncontrol.module 10 Dec 2007 16:28:12 -0000 @@ -2095,6 +2095,42 @@ } /** + * Retrieve general statistics about what happened in a single commit. For more granular + * details about what happened in a single commit, use versioncontrol_get_commit_actions. + * + * @param $commit + * The commit to retrieve statistics about + * + * @param $commit_actions + * The actions of the commit. Can be passed by the caller if the caller already has the actions, + * or can be left absent and they will be automatically obtained. + * + * @return + * A structured array containing general statistics about this commit. The array will consist + * of elements with the following keys: + * + * - 'lines_added': Total number of lines added during this commit + * - 'lines_removed': Total number of lines removed during this commit + * - 'action_count': Total number of actions within this commit + * - 'per_action_statistics': An array containing statistics on individual actions. Array keys are + * the current/new paths (just as with versioncontrol_get_commit_actions). The corresponding + * array values are again structured arrays and consist of elements with the following keys: + * + * - 'lines_added': Number of lines added in this action + * - 'lines_removed': Number of lines removed in this action + * + * These values are designed so that statistics from several commits can be combined, hence why totals + * are given rather than averages. A real-life example of such a result array can be found in the FakeVCS + * example module. + * + */ +function versioncontrol_get_commit_statistics($commit, $commit_actions = NULL) { + return _versioncontrol_call_backend( + $commit['repository']['vcs'], 'get_commit_statistics', array($commit, $commit_actions) + ); +} + +/** * Return the 'current item' of a commit action if there is one, * or the first (only) one of the 'source items' if the file has been deleted. * As this function is also being used within access checks, it also works Index: commitlog/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/commitlog.module 8 Nov 2007 02:58:36 -0000 1.26 +++ commitlog/commitlog.module 10 Dec 2007 16:28:13 -0000 @@ -490,8 +490,11 @@ $variables['id'] = theme('commitlog_commit_identifier', $commit, $format); $variables['repository_name'] = theme('commitlog_repository', $commit['repository'], $format); $variables['time'] = format_date($commit['date'], 'custom', 'H:i'); + + $statistics = versioncontrol_get_commit_statistics($commit, $commit_actions); $variables['actions'] = theme('commitlog_commit_actions', $commit, $commit_actions, $format); + $variables['statistics'] = theme('commitlog_commit_statistics', $commit, $statistics, $format); $variables['message'] = theme('commitlog_commit_message', $commit, $format); $variables['branches'] = theme('commitlog_commit_branches', $commit, $format); @@ -511,6 +514,7 @@ '!name' => $variables['username'], '!time' => $variables['time'], )); + $output .= ' ('. $variables['statistics'] .')'; $output .= "\n"; // class "title" $output .= '
'. $variables['actions'] .'
'."\n"; @@ -652,6 +656,14 @@ return implode(', ', $branches); } +function theme_commitlog_commit_statistics($commit, $commit_statistics, $format = 'html') { + $lines = array(); + + $lines[] = t('@line_count added', array('@line_count' => format_plural($commit_statistics['lines_added'], '1 line', '@count lines'))); + $lines[] = t('@line_count removed', array('@line_count' => format_plural($commit_statistics['lines_removed'], '1 line', '@count lines'))); + + return implode(", ", $lines); +} function theme_commitlog_commit_actions($commit, $commit_actions, $format = 'html') { if (empty($commit_actions)) { Index: versioncontrol_fakevcs/versioncontrol_fakevcs.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/versioncontrol/versioncontrol_fakevcs/versioncontrol_fakevcs.module,v retrieving revision 1.37 diff -u -r1.37 versioncontrol_fakevcs.module --- versioncontrol_fakevcs/versioncontrol_fakevcs.module 2 Nov 2007 13:39:12 -0000 1.37 +++ versioncontrol_fakevcs/versioncontrol_fakevcs.module 10 Dec 2007 16:28:14 -0000 @@ -389,6 +389,97 @@ } /** + * Implementation of [versioncontrol_backend]_get_commit_statistics(): + * Retrieve general statistics about what happened in a single commit. For more granular + * details about what happened in a single commit, use versioncontrol_get_commit_actions. + * + * @param $commit + * The commit to retrieve statistics about + * + * @return + * A structured array containing general statistics about this commit. The array will consist + * of elements with the following keys: + * + * - 'lines_added': Total number of lines added during this commit + * - 'lines_removed': Total number of lines removed during this commit + * - 'action_count': Total number of actions within this commit + * - 'per_action_statistics': An array containing statistics on individual actions. Array keys are + * the current/new paths (just as with versioncontrol_get_commit_actions). The corresponding + * array values are again structured arrays and consist of elements with the following keys: + * + * - 'lines_added': Number of lines added in this action + * - 'lines_removed': Number of lines removed in this action + */ +function versioncontrol_fakevcs_get_commit_statistics($commit, $commit_actions = NULL) { + // Assuming $commit is a single commit array that looks like this: + $commit = array( + // The commit id, a simple running number. Doesn't have any specific + // meaning, but is necessary for indexing and joining tables. + 'commit_id' => 2345, + // The repository that was affected by this commit. + 'repository' => $affected_repository, + // The time when the commit was executed, in Unix timestamp format. + 'date' => time(), + // User id of the committer's Drupal user account. + // 0 if no corresponding account exists. + 'uid' => $user->uid, + // The committer's username known to the repository itself. In most cases + // this will probably be the name of the committer's Unix user account. + 'username' => 'jpetso', + // The deepest-level directory in the repository that is common to + // all the changed items in this commit. + 'directory' => '/', + // The commit message, which is expected to span one or more lines. + 'message' => 'All kinds of demonstrative changes.', + // The revision identifier of the commit, in the VCS's proprietary format - + // running number, SHA-1 hash, or whatever. If there is no single revision + // identifier for the whole commit (which should only be the case for CVS) + // then the value for this key is set to NULL. + 'revision' => '404', // for this commit, let's assume this is an SVN repository + ); + + return array( + 'lines_added' => 30, // 15 + 5 + 7 + 3 + 'lines_removed' => 20, // 3 + 17 + 'action_count' => 8, + 'per_action_statistics' => array( + '/trunk/contributions/modules/versioncontrol/versioncontrol.module' => array( + 'lines_added' => 15, + 'lines_removed' => 0, + ), + '/trunk/contributions/modules/versioncontrol/versioncontrol.install' => array( + 'lines_added' => 5, + 'lines_removed' => 3, + ), + '/branches/sandbox/jpetso/versioncontrol-notes.txt' => array( + 'lines_added' => 0, + 'lines_removed' => 17, + ), + '/trunk/contributions/modules/versioncontrol/versioncontrol.info' => array( + 'lines_added' => 0, + 'lines_removed' => 0, + ), + '/trunk/contributions/modules/versioncontrol/README.txt' => array( + 'lines_added' => 7, + 'lines_removed' => 0, + ), + '/trunk/contributions/modules/versioncontrol/versioncontrol_fakevcs/versioncontrol_fakevcs.module' => array( + 'lines_added' => 0, + 'lines_removed' => 0, + ), + '/branches/5.x-1.x/contributions/modules/cvslog' => array( + 'lines_added' => 3, + 'lines_removed' => 0, + ), + '/trunk/contributions/modules/versioncontrol/versioncontrol_fakevcs' => array( + 'lines_added' => 0, + 'lines_removed' => 0, + ), + ), + ); +} + +/** * Implementation of [versioncontrol_backend]_get_directory_item(): * Retrieve the item of the deepest-level directory in the repository that is * common to all the changed/branched/tagged items in a commit, branch or