Fix some caching logic, and store information we get from dependency objects once...
authorChuck Hagenbuch <chuck@horde.org>
Sat, 27 Nov 2010 04:24:49 +0000 (23:24 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Sun, 28 Nov 2010 02:08:02 +0000 (21:08 -0500)
framework/Vcs/lib/Horde/Vcs/Log.php
framework/Vcs/lib/Horde/Vcs/Log/Cvs.php
framework/Vcs/lib/Horde/Vcs/Log/Git.php

index 1390701..7d3e4c0 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Horde_Vcs log class.
+ * Horde_Vcs_Log class.
  *
  * Copyright 2008-2010 The Horde Project (http://www.horde.org/)
  *
@@ -21,7 +21,14 @@ abstract class Horde_Vcs_Log
     protected $_log;
     protected $_state;
     protected $_lines = '';
+    protected $_branch;
     protected $_branches = array();
+    protected $_symbolicBranches = array();
+
+    /**
+     * @var boolean
+     */
+    protected $_initialized;
 
     /**
      * Constructor.
@@ -33,6 +40,10 @@ abstract class Horde_Vcs_Log
 
     protected function _ensureInitialized()
     {
+        if (!$this->_initialized) {
+            $this->_init();
+            $this->_initialized = true;
+        }
     }
 
     /**
@@ -98,7 +109,7 @@ abstract class Horde_Vcs_Log
     public function queryBranch()
     {
         $this->_ensureInitialized();
-        return array();
+        return $this->_branch;
     }
 
     /**
@@ -129,17 +140,19 @@ abstract class Horde_Vcs_Log
     public function querySymbolicBranches()
     {
         $this->_ensureInitialized();
+        return $this->_symbolicBranches;
+    }
 
-        $symBranches = array();
+    protected function _setSymbolicBranches()
+    {
+        $this->_symbolicBranches = array();
         $branches = $this->_file->queryBranches();
 
         foreach ($this->_branches as $branch) {
             if (($key = array_search($branch, $branches)) !== false) {
-                $symBranches[$key] = $branch;
+                $this->_symbolicBranches[$key] = $branch;
             }
         }
-
-        return $symBranches;
     }
 
     /**
index 17aa849..2a96a1e 100644 (file)
@@ -20,11 +20,9 @@ class Horde_Vcs_Log_Cvs extends Horde_Vcs_Log
      */
     protected $_branch;
 
-    private $_initialized;
-
     protected function _init()
     {
-       $raw = $this->_file->getAccum();
+        $raw = $this->_file->getAccum();
 
         /* Initialise a simple state machine to parse the output of rlog */
         $state = 'init';
@@ -77,14 +75,14 @@ class Horde_Vcs_Log_Cvs extends Horde_Vcs_Log
         /* Assume the rest of the lines are the log message */
         $this->_log = implode("\n", $raw);
         $this->_tags = $this->_file->queryRevsym($this->_rev);
-    }
 
-    protected function _ensureInitialized()
-    {
-        if (!$this->_initialized) {
-            $this->_init();
-            $this->_initialized = true;
-        }
+        $this->_setSymbolicBranches();
+
+        $branches = $this->_file->queryBranches();
+        $key = array_keys($branches, $this->_rev);
+        $this->_branch = empty($key)
+            ? array_keys($branches, $this->_rep->strip($this->_rev, 1))
+            : $key;
     }
 
     /**
@@ -94,21 +92,4 @@ class Horde_Vcs_Log_Cvs extends Horde_Vcs_Log
     {
         $this->_branch = array($branch);
     }
-
-    /**
-     * TODO
-     */
-    public function queryBranch()
-    {
-        if (!empty($this->_branch)) {
-            return $this->_branch;
-        }
-
-        $branches = $this->_file->queryBranches();
-        $key = array_keys($branches, $this->_rev);
-        return empty($key)
-            ? array_keys($branches, $this->_rep->strip($this->_rev, 1))
-            : $key;
-    }
-
 }
\ No newline at end of file
index 64a478b..41718c9 100644 (file)
@@ -18,19 +18,6 @@ class Horde_Vcs_Log_Git extends Horde_Vcs_Log
      */
     protected $_parent = null;
 
-    /**
-     * @var boolean
-     */
-    private $_initialized;
-
-    protected function _ensureInitialized()
-    {
-        if (!$this->_initialized) {
-            $this->_init();
-            $this->_initialized = true;
-        }
-    }
-
     protected function _init()
     {
         /* Get diff statistics. */
@@ -134,6 +121,9 @@ class Horde_Vcs_Log_Git extends Horde_Vcs_Log
 
             $line = next($lines);
         }
+
+        $this->_setSymbolicBranches();
+        $this->_branch = $this->_file->queryBranch($this->_rev);
     }
 
     /**
@@ -148,17 +138,8 @@ class Horde_Vcs_Log_Git extends Horde_Vcs_Log
     /**
      * TODO
      */
-    public function queryBranch()
-    {
-        return $this->_file->queryBranch($this->_rev);
-    }
-
-    /**
-     * TODO
-     */
     public function queryParent()
     {
         return $this->_parent;
     }
-
 }
\ No newline at end of file