? xcvs
Index: versioncontrol_cvs.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/versioncontrol_cvs/versioncontrol_cvs.module,v
retrieving revision 1.25
diff -u -r1.25 versioncontrol_cvs.module
--- versioncontrol_cvs.module	10 Nov 2007 00:32:25 -0000	1.25
+++ versioncontrol_cvs.module	7 Dec 2007 17:33:16 -0000
@@ -129,13 +129,17 @@
 function versioncontrol_cvs_get_commit_actions($commit) {
   $actions = array();
   $result = db_query('SELECT item_revision_id, action, type, path,
-                             revision, source_revision
+                             revision, lines_added, lines_removed, source_revision
                       FROM {versioncontrol_cvs_item_revisions}
                       WHERE commit_id = %d', $commit['commit_id']);
 
   while ($item_revision = db_fetch_object($result)) {
     $action = array(
       'action' => $item_revision->action,
+      'cvs_specific' => array(
+        'lines_added' => $item_revision->lines_added,
+        'lines_removed' => $item_revision->lines_removed,
+      ),
     );
 
     if ($item_revision->action != VERSIONCONTROL_ACTION_DELETED) {
@@ -170,6 +174,54 @@
 }
 
 /**
+ * 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_added_squared': Total of (number of lines added per action) squared, during this commit.
+ *        Useful for calculating the standard deviation.
+ *   - 'lines_removed': Total number of lines removed during this commit
+ *   - 'lines_removed_squared': Total of (number of lines removed per action) squared, during this commit.
+ *        Useful for calculating the standard deviation.
+ *   - 'action_count': Total number of actions within this commit
+ */
+function versioncontrol_cvs_get_commit_statistics($commit) {
+  $commit_actions = versioncontrol_cvs_get_commit_actions($commit);
+  
+  $total_lines_added = 0;
+  $total_lines_added_squared = 0;
+  $total_lines_removed = 0;
+  $total_lines_removed_squared = 0;
+  $total_num_actions = 0;
+  
+  foreach ($commit_actions as $path => $action) {
+    $total_num_actions++;
+    $added = $action['cvs_specific']['lines_added'];
+    $total_lines_added += $added;
+    $total_lines_added_squared += $added * $added;
+    $removed = $action['cvs_specific']['lines_removed'];
+    $total_lines_removed += $removed;
+    $total_lines_removed_squared += $removed * $removed;
+  }
+  
+  return array(
+    'lines_added' => $total_lines_added,
+    'lines_added_squared' => $total_lines_added_squared,
+    'lines_removed' => $total_lines_removed,
+    'lines_removed_squared' => $total_lines_removed_squared,
+    'action_count' => $total_num_actions,
+  );
+ }
+
+/**
  * 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
