From 74943747520baba3b77267015caf2bfc79bfd00e Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Wed, 10 Aug 2011 06:08:14 -0500
Subject: [PATCH] Follow VersioncontrolOperationLabel entity introduction.

---
 includes/VersioncontrolGitBackend.php   |    1 +
 includes/VersioncontrolGitOperation.php |   16 +++++++++++-----
 versioncontrol_git.log.inc              |   16 +++++++++++-----
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/includes/VersioncontrolGitBackend.php b/includes/VersioncontrolGitBackend.php
index f6b26dd..fb4b4ea 100644
--- a/includes/VersioncontrolGitBackend.php
+++ b/includes/VersioncontrolGitBackend.php
@@ -8,6 +8,7 @@ class VersioncontrolGitBackend extends VersioncontrolBackend {
       'repo' => 'VersioncontrolGitRepository',
       'account' => 'VersioncontrolGitAccount',
       'operation' => 'VersioncontrolGitOperation',
+      'operation_label' => 'VersioncontrolGitOperationLabel',
       'item' => 'VersioncontrolGitItem',
     );
 
diff --git a/includes/VersioncontrolGitOperation.php b/includes/VersioncontrolGitOperation.php
index ae4f346..3f9de05 100644
--- a/includes/VersioncontrolGitOperation.php
+++ b/includes/VersioncontrolGitOperation.php
@@ -44,11 +44,17 @@ class VersioncontrolGitOperation extends VersioncontrolOperation {
    * Implementation of abstract method.
    */
   public function getSelectedLabel($target_item) {
-  // TODO: implement tag support here, tags>branch?
-  // better not, after looking it again current code is OK.
-  // just take the first branch, dunno what else we should do here...
-  // jpetso knows neither :P
-    return $this->labels[0];
+    // Use the first label on the list if possible.
+    if (count($this->labels) > 0) {
+      // Do not modify original.
+      $labels = $this->labels;
+      $operation_label = array_shift($labels);
+      return $operation_label->label;
+    }
+    return NULL;
   }
 
 }
+
+class VersioncontrolGitOperationLabel extends VersioncontrolOperationLabel {
+}
diff --git a/versioncontrol_git.log.inc b/versioncontrol_git.log.inc
index 334bcca..e921eb1 100644
--- a/versioncontrol_git.log.inc
+++ b/versioncontrol_git.log.inc
@@ -3,7 +3,6 @@
  * @file
  * Git backend for Version Control API - Provides Git commit information and
  * account management as a pluggable backend.
- * FIXME add an action to operation_labels
  *
  * Copyright 2008 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
  * Copyright 2009-2010 by Cornelius Riemenschneider ("CorniI", http://drupal.org/user/136353)
@@ -151,15 +150,22 @@ function _versioncontrol_git_log_exec($command) {
 function _versioncontrol_git_log_get_branches_of_commit($revision, $branch_label_list) {
   $exec = 'branch --no-color --contains ' . escapeshellarg($revision);
   $logs = _versioncontrol_git_log_exec($exec);
-  $branches = array();
+  $operation_labels = array();
   while (($line = next($logs)) !== FALSE) {
     $line = trim($line);
     if($line[0] == '*') {
       $line = substr($line, 2);
     }
-    $branches[] = $branch_label_list[$line];
+    $operation_label = new VersioncontrolGitOperationLabel();
+    $operation_label->build(array(
+      // 'vc_op_id' will be retrieved from operation object on insertNested.
+      'label' => $branch_label_list[$line],
+      // Git does not track label activity per commit, so use always modified.
+      'action' => VERSIONCONTROL_ACTION_MODIFIED,
+    ));
+    $operation_labels[] = $operation_label;
   }
-  return $branches;
+  return $operation_labels;
 }
 
 /**
@@ -368,7 +374,7 @@ function _versioncontrol_git_log_parse_and_insert_commit(VersioncontrolRepositor
   $op = new VersioncontrolGitOperation($repository->getBackend());
   $op->build($op_data);
   $op->labels = _versioncontrol_git_log_get_branches_of_commit($revision, $branch_label_list);
-  $op->insert(array('map users' => TRUE));
+  $op->insert(array('nested' => TRUE, 'map users' => TRUE));
 
   $item_action = $merge ? VERSIONCONTROL_ACTION_MERGED : VERSIONCONTROL_ACTION_MODIFIED;
   // build the data array to be used as default values for the item revision
-- 
1.7.5.4

