From 8a69d029776a9b84c25b49969e87c9181f9d58f6 Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Sun, 26 Jun 2011 23:05:03 -0500
Subject: [PATCH] Issue #1054436: Store commit date and authoring date.

- Schema change on {versioncontrol_operations} to use two fields for the
  dates.
- Change operation class data members accordingly.
- Change views definition for operation dates.
- Change a little how the versioncontrol_handler_field_operation_date
  views field handler work in order to support the handling of both
  author_date and comitter_date.
- Change default views definitions on commitlog module to follow the new
  views fields, author_date and committer_date.
---
 .../commitlog_global_commits.view.php              |   16 ++++----
 .../commitlog_individual_commit.view.php           |   16 ++++----
 .../commitlog_repository_commits.view.php          |   16 ++++----
 .../default_views/commitlog_user_commits.view.php  |   16 ++++----
 includes/VersioncontrolOperation.php               |   14 +++++--
 ...versioncontrol_handler_field_operation_date.inc |    9 +----
 includes/views/versioncontrol.views.inc            |   33 ++++++++++++++-
 versioncontrol.install                             |   42 ++++++++++++++++++-
 8 files changed, 112 insertions(+), 50 deletions(-)

diff --git a/commitlog/includes/views/default_views/commitlog_global_commits.view.php b/commitlog/includes/views/default_views/commitlog_global_commits.view.php
index 743162a..f22f0d7 100644
--- a/commitlog/includes/views/default_views/commitlog_global_commits.view.php
+++ b/commitlog/includes/views/default_views/commitlog_global_commits.view.php
@@ -75,8 +75,8 @@ $handler->override_option('fields', array(
     'field' => 'vc_op_id',
     'relationship' => 'none',
   ),
-  'date' => array(
-    'label' => 'Date',
+  'author_date' => array(
+    'label' => 'Author date',
     'alter' => array(
       'alter_text' => 0,
       'text' => '',
@@ -102,9 +102,9 @@ $handler->override_option('fields', array(
     'custom_date_format' => 'F j, Y G:i',
     'link' => 1,
     'exclude' => 1,
-    'id' => 'date',
+    'id' => 'author_date',
     'table' => 'versioncontrol_operations',
-    'field' => 'date',
+    'field' => 'author_date',
     'relationship' => 'none',
   ),
   'labels' => array(
@@ -169,7 +169,7 @@ $handler->override_option('fields', array(
     'label' => '',
     'alter' => array(
       'text' => '<div class="commit-global">
-  <h3>[date]</h3>
+  <h3>[author_date]</h3>
   <div class="commit-info">Commit <strong>[revision]</strong> on <strong>[labels]</strong></div>
   <div class="attribtution">[attribution]</div>
 </div>',
@@ -290,12 +290,12 @@ $handler->override_option('fields', array(
   ),
 ));
 $handler->override_option('sorts', array(
-  'date' => array(
+  'author_date' => array(
     'order' => 'DESC',
     'granularity' => 'second',
-    'id' => 'date',
+    'id' => 'author_date',
     'table' => 'versioncontrol_operations',
-    'field' => 'date',
+    'field' => 'author_date',
     'relationship' => 'none',
   ),
 ));
diff --git a/commitlog/includes/views/default_views/commitlog_individual_commit.view.php b/commitlog/includes/views/default_views/commitlog_individual_commit.view.php
index dcd830f..aa46a74 100644
--- a/commitlog/includes/views/default_views/commitlog_individual_commit.view.php
+++ b/commitlog/includes/views/default_views/commitlog_individual_commit.view.php
@@ -75,8 +75,8 @@ $handler->override_option('fields', array(
     'field' => 'vc_op_id',
     'relationship' => 'none',
   ),
-  'date' => array(
-    'label' => 'Date',
+  'author_date' => array(
+    'label' => 'Author date',
     'alter' => array(
       'alter_text' => 0,
       'text' => '',
@@ -101,9 +101,9 @@ $handler->override_option('fields', array(
     'date_format' => 'custom',
     'custom_date_format' => 'F j, Y G:i',
     'exclude' => 1,
-    'id' => 'date',
+    'id' => 'author_date',
     'table' => 'versioncontrol_operations',
-    'field' => 'date',
+    'field' => 'author_date',
     'relationship' => 'none',
   ),
   'labels' => array(
@@ -168,7 +168,7 @@ $handler->override_option('fields', array(
     'label' => '',
     'alter' => array(
       'text' => '<div class="commit-global">
-  <h3>[date]</h3>
+  <h3>[author_date]</h3>
   <div class="commit-info">Commit <strong>[revision]</strong> on <strong>[labels]</strong></div>
   <div class="attribtution">[attribution]</div>
 </div>',
@@ -289,12 +289,12 @@ $handler->override_option('fields', array(
   ),
 ));
 $handler->override_option('sorts', array(
-  'date' => array(
+  'author_date' => array(
     'order' => 'DESC',
     'granularity' => 'second',
-    'id' => 'date',
+    'id' => 'author_date',
     'table' => 'versioncontrol_operations',
-    'field' => 'date',
+    'field' => 'author_date',
     'relationship' => 'none',
   ),
 ));
diff --git a/commitlog/includes/views/default_views/commitlog_repository_commits.view.php b/commitlog/includes/views/default_views/commitlog_repository_commits.view.php
index 59e53d3..26bf362 100644
--- a/commitlog/includes/views/default_views/commitlog_repository_commits.view.php
+++ b/commitlog/includes/views/default_views/commitlog_repository_commits.view.php
@@ -75,8 +75,8 @@ $handler->override_option('fields', array(
     'field' => 'vc_op_id',
     'relationship' => 'none',
   ),
-  'date' => array(
-    'label' => 'Date',
+  'author_date' => array(
+    'label' => 'Author date',
     'alter' => array(
       'alter_text' => 0,
       'text' => '',
@@ -102,9 +102,9 @@ $handler->override_option('fields', array(
     'custom_date_format' => 'F j, Y G:i',
     'link' => 1,
     'exclude' => 1,
-    'id' => 'date',
+    'id' => 'author_date',
     'table' => 'versioncontrol_operations',
-    'field' => 'date',
+    'field' => 'author_date',
     'relationship' => 'none',
   ),
   'labels' => array(
@@ -169,7 +169,7 @@ $handler->override_option('fields', array(
     'label' => '',
     'alter' => array(
       'text' => '<div class="commit-global">
-  <h3>[date]</h3>
+  <h3>[author_date]</h3>
   <div class="commit-info">Commit <strong>[revision]</strong> on <strong>[labels]</strong></div>
   <div class="attribtution">[attribution]</div>
 </div>',
@@ -290,12 +290,12 @@ $handler->override_option('fields', array(
   ),
 ));
 $handler->override_option('sorts', array(
-  'date' => array(
+  'author_date' => array(
     'order' => 'DESC',
     'granularity' => 'second',
-    'id' => 'date',
+    'id' => 'author_date',
     'table' => 'versioncontrol_operations',
-    'field' => 'date',
+    'field' => 'author_date',
     'relationship' => 'none',
   ),
 ));
diff --git a/commitlog/includes/views/default_views/commitlog_user_commits.view.php b/commitlog/includes/views/default_views/commitlog_user_commits.view.php
index ff403d7..6285306 100644
--- a/commitlog/includes/views/default_views/commitlog_user_commits.view.php
+++ b/commitlog/includes/views/default_views/commitlog_user_commits.view.php
@@ -75,8 +75,8 @@ $handler->override_option('fields', array(
     'field' => 'vc_op_id',
     'relationship' => 'none',
   ),
-  'date' => array(
-    'label' => 'Date',
+  'author_date' => array(
+    'label' => 'Author date',
     'alter' => array(
       'alter_text' => 0,
       'text' => '',
@@ -102,9 +102,9 @@ $handler->override_option('fields', array(
     'custom_date_format' => 'F j, Y G:i',
     'link' => 1,
     'exclude' => 1,
-    'id' => 'date',
+    'id' => 'author_date',
     'table' => 'versioncontrol_operations',
-    'field' => 'date',
+    'field' => 'author_date',
     'relationship' => 'none',
   ),
   'labels' => array(
@@ -169,7 +169,7 @@ $handler->override_option('fields', array(
     'label' => '',
     'alter' => array(
       'text' => '<div class="commit-global">
-  <h3>[date]</h3>
+  <h3>[author_date]</h3>
   <div class="commit-info">Commit <strong>[revision]</strong> on <strong>[labels]</strong></div>
   <div class="attribtution">[attribution]</div>
 </div>',
@@ -290,12 +290,12 @@ $handler->override_option('fields', array(
   ),
 ));
 $handler->override_option('sorts', array(
-  'date' => array(
+  'author_date' => array(
     'order' => 'DESC',
     'granularity' => 'second',
-    'id' => 'date',
+    'id' => 'author_date',
     'table' => 'versioncontrol_operations',
-    'field' => 'date',
+    'field' => 'author_date',
     'relationship' => 'none',
   ),
 ));
diff --git a/includes/VersioncontrolOperation.php b/includes/VersioncontrolOperation.php
index 90f67f7..1e75a11 100644
--- a/includes/VersioncontrolOperation.php
+++ b/includes/VersioncontrolOperation.php
@@ -22,13 +22,19 @@ abstract class VersioncontrolOperation extends VersioncontrolEntity {
 
   /**
    * The time when the operation was performed, given as
-   * Unix timestamp. (For commits, this is the time when the revision
-   * was committed, whereas for branch/tag operations it is the time
-   * when the files were branched or tagged.)
+   * Unix timestamp.
    *
    * @var timestamp
    */
-  public $date;
+  public $author_date;
+
+  /**
+   * The time when the operation was added to the repository, given as
+   * Unix timestamp.
+   *
+   * @var timestamp
+   */
+  public $committer_date;
 
   /**
    * The VCS specific repository-wide revision identifier,
diff --git a/includes/views/handlers/versioncontrol_handler_field_operation_date.inc b/includes/views/handlers/versioncontrol_handler_field_operation_date.inc
index fc8217d..81d21ff 100644
--- a/includes/views/handlers/versioncontrol_handler_field_operation_date.inc
+++ b/includes/views/handlers/versioncontrol_handler_field_operation_date.inc
@@ -3,13 +3,6 @@
  * A handler to provide date for operation with optional link to operation.
  */
 class versioncontrol_handler_field_operation_date extends views_handler_field_date {
-  function construct() {
-    parent::construct();
-    $this->additional_fields['revision'] = 'revision';
-    $this->additional_fields['date'] = 'date';
-    $this->additional_fields['repo_id'] = 'repo_id';
-  }
-
   function option_definition() {
     $options = parent::option_definition();
 
@@ -34,7 +27,7 @@ class versioncontrol_handler_field_operation_date extends views_handler_field_da
   }
 
   function render($values) {
-    $this->field_alias = $this->aliases['date'];
+    $this->field_alias = $this->aliases['date_value'];
     if (!$this->options['link']) {
       return parent::render($values);
     }
diff --git a/includes/views/versioncontrol.views.inc b/includes/views/versioncontrol.views.inc
index 9b0886f..0cfe2e7 100755
--- a/includes/views/versioncontrol.views.inc
+++ b/includes/views/versioncontrol.views.inc
@@ -181,12 +181,39 @@ function versioncontrol_views_data() {
       'handler' => 'versioncontrol_handler_filter_operation_type',
     ),
   );
-  $data['versioncontrol_operations']['date'] = array(
-    'title'    => t('Date'),
-    'help'     => t('The date of the operation'),
+  $data['versioncontrol_operations']['author_date'] = array(
+    'title'    => t('Author date'),
+    'help'     => t('The date when the operation was originally done.'),
     'field'    => array(
       'handler' => 'versioncontrol_handler_field_operation_date',
       'click sortable' => TRUE,
+      'additional fields' => array(
+        'date_value' => array('table' => 'versioncontrol_operations', 'field' => 'author_date'),
+        'revision',
+        'repo_id',
+      ),
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_date',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_date',
+    ),
+  );
+  $data['versioncontrol_operations']['committer_date'] = array(
+    'title'    => t('Committer date'),
+    'help'     => t('The date when the operation was added to the repository.'),
+    'field'    => array(
+      'handler' => 'versioncontrol_handler_field_operation_date',
+      'click sortable' => TRUE,
+      'additional fields' => array(
+        'date_value' => array('table' => 'versioncontrol_operations', 'field' => 'committer_date'),
+        'revision',
+        'repo_id',
+      ),
     ),
     'sort' => array(
       'handler' => 'views_handler_sort_date',
diff --git a/versioncontrol.install b/versioncontrol.install
index a0fe4d0..3593d97 100644
--- a/versioncontrol.install
+++ b/versioncontrol.install
@@ -38,8 +38,15 @@ function versioncontrol_schema() {
         'not null' => TRUE,
         'default' => 0,
       ),
-      'date' => array(
-        'description' => 'Date/time when the operation was executed, as Unix timestamp.',
+      'author_date' => array(
+        'description' => 'Date/time when the operation was created, as Unix timestamp.',
+        'type' => 'int',
+        'size' => 'big',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'committer_date' => array(
+        'description' => 'Date/time when the operation was added to the repository, as Unix timestamp.',
         'type' => 'int',
         'size' => 'big',
         'not null' => TRUE,
@@ -92,7 +99,8 @@ function versioncontrol_schema() {
     'indexes' => array(
       'type' => array('type'),
       'repo_id' => array('repo_id'),
-      'date' => array('date'),
+      'author_date' => array('author_date'),
+      'committer_date' => array('committer_date'),
       'author' => array('author'),
       'author_uid' => array('author_uid'),
       'committer' => array('committer'),
@@ -1209,3 +1217,31 @@ function versioncontrol_update_6316() {
   db_add_index($ret, 'versioncontrol_item_revisions','vc_op_id', array('vc_op_id'));
   return $ret;
 }
+
+/**
+ * Use two fields to handle operation dates.
+ */
+function versioncontrol_update_6317() {
+  $ret = array();
+  $author_date_spec = array(
+    'description' => 'Date/time when the operation was created, as Unix timestamp.',
+    'type' => 'int',
+    'size' => 'big',
+    'not null' => TRUE,
+    'default' => 0,
+  );
+  $committer_date_spec = array(
+    'description' => 'Date/time when the operation was added to the repository, as Unix timestamp.',
+    'type' => 'int',
+    'size' => 'big',
+    'not null' => TRUE,
+    'default' => 0,
+  );
+  $committer_date_index_spec = array('indexes' => array('committer_date' => array('committer_date')));
+  $author_date_index_spec = array('indexes' => array('author_date' => array('author_date')));
+  db_add_field($ret, 'versioncontrol_operations', 'committer_date', $committer_date_spec, $committer_date_index_spec);
+  db_query('UPDATE {versioncontrol_operations} vco SET vco.committer_date = vco.date');
+  db_drop_index($ret, 'versioncontrol_operations', 'date');
+  db_change_field($ret, 'versioncontrol_operations', 'date', 'author_date', $author_date_spec, $author_date_index_spec);
+  return $ret;
+}
-- 
1.7.5.3

