Move branch query code to Vcs library
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 22 Jan 2009 23:56:16 +0000 (16:56 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 22 Jan 2009 23:57:02 +0000 (16:57 -0700)
chora/browse.php
chora/co.php
chora/diff.php
chora/lib/Chora.php
framework/Vcs/lib/Horde/Vcs.php
framework/Vcs/lib/Horde/Vcs/Cvs.php
framework/Vcs/lib/Horde/Vcs/Git.php

index ce7b9ed..aaf2090 100644 (file)
@@ -147,7 +147,7 @@ foreach ($fl->symrev as $sm => $rv) {
 $selAllBranches = '';
 if ($VC->hasFeature('branches')) {
     foreach (array_keys($fl->branches) as $sym) {
-        $selAllBranches .= '<option value="' . $sym . '">' . $sym . '</option>';
+        $selAllBranches .= '<option value="' . $sym . '"' . ($sym == $onb ? ' selected="selected"' : '' ) . '>' . $sym . '</option>';
     }
 }
 
@@ -163,7 +163,7 @@ require CHORA_TEMPLATES . '/log/header.inc';
 $i = 0;
 foreach ($fl->logs as $lg) {
     $rev = $lg->queryRevision();
-    $branch_info = Chora::getBranch($fl, $rev);
+    $branch_info = $lg->queryBranch();
 
     $textUrl = Chora::url('co', $where, array('r' => $rev));
     $commitDate = Chora::formatDate($lg->queryDate());
index ecfe0ec..0d0efd1 100644 (file)
@@ -70,7 +70,7 @@ if (!$plain) {
                          Chora::url('co', $where, array('r' => $r, 'p' => 1)), _("Download"));
 
     $tags = Chora::getTags($log, $where);
-    $branch_info = Chora::getBranch($file, $r);
+    $branch_info = $log->queryBranch();
 
     $log_print = Chora::formatLogMessage($log->queryLog());
     $author = Chora::showAuthorName($log->queryAuthor(), true);
index 614890c..83ef8c0 100644 (file)
@@ -64,7 +64,7 @@ foreach ($VC->getRevisionRange($fl, $r1, $r2) as $val) {
             'rev' => $val,
             'msg' => Chora::formatLogMessage($clog->queryLog()),
             'author' => Chora::showAuthorName($clog->queryAuthor(), true),
-            'branchinfo' => Chora::getBranch($fl, $val),
+            'branchinfo' => $clog->queryBranch(),
             'date' => Chora::formatDate($clog->queryDate()),
             'tags' => Chora::getTags($clog, $where),
         );
index 0b40229..42d87c1 100644 (file)
@@ -580,32 +580,6 @@ class Chora
     }
 
     /**
-     * Return branch information for a given revision.
-     *
-     * @param Horde_Vcs_File $fl  The Horde_Vcs_File object.
-     * @param string $rev         The revision string.
-     *
-     * @return array  TODO
-     */
-    static public function getBranch($fl, $rev)
-    {
-        return $GLOBALS['VC']->hasFeature('branches')
-            ? array_keys($fl->branches, $rev)
-            : array();
-
-        /*
-        $rev_ob = $fl->rep->getRevisionObject();
-        $branchRev = $rev_ob->strip($rev, 1);
-        if (isset($fl->branches[$rev])) {
-            $branchName = $fl->branches[$rev];
-        } elseif (isset($fl->branches[$branchRev])) {
-            $branchName = $fl->branches[$branchRev];
-        }
-        return array($branchName, $branchRev);
-        */
-    }
-
-    /**
      * Return formatted date information.
      *
      * @param integer $date  Number of seconds since epoch we wish to display.
index 535a364..627fb6a 100644 (file)
@@ -945,6 +945,11 @@ class Horde_Vcs_Log
         return $this->log;
     }
 
+    public function queryBranch()
+    {
+        return array();
+    }
+
     public function queryChangedLines()
     {
         return isset($this->lines) ? $this->lines : '';
index b24efa2..18a8c27 100644 (file)
@@ -725,6 +725,18 @@ class Horde_Vcs_Log_Cvs extends Horde_Vcs_Log
             array();
     }
 
+    public function queryBranch()
+    {
+        $key = array_search($this->rev, $this->file->branches);
+        if ($key) {
+            return array($key);
+        }
+
+        $rev_ob = $this->file->rep->getRevisionObject();
+        $key = array_search($rev_ob->strip($this->rev, 1), $this->file->branches);
+        return $key ? array($key) : array();
+    }
+
 }
 
 /**
index 96d5f1a..6bbd14e 100644 (file)
@@ -463,9 +463,8 @@ class Horde_Vcs_File_Git extends Horde_Vcs_File
  * @author  Chuck Hagenbuch <chuck@horde.org>
  * @package Horde_Vcs
  */
-class Horde_Vcs_Log_Git extends Horde_Vcs_Log {
-
-    public $err;
+class Horde_Vcs_Log_Git extends Horde_Vcs_Log
+{
     public $files = array();
 
     public static function factory($file, $rev)
@@ -476,10 +475,9 @@ class Horde_Vcs_Log_Git extends Horde_Vcs_Log {
         $cacheVersion = 1;
         $cacheId = $file->rep->sourceroot() . '_r' . $rev . '_v' . $cacheVersion;
 
-        /* @TODO: No caching during dev */
-        if (0 &&
-            $file->rep->cache &&
+        if ($file->rep->cache &&
             // Individual revisions can be cached forever
+            // return array_keys(
             $file->rep->cache->exists($cacheId, 0)) {
             $logOb = unserialize($file->rep->cache->get($cacheId, 0));
             $logOb->setRepository($file->rep);
@@ -603,6 +601,14 @@ class Horde_Vcs_Log_Git extends Horde_Vcs_Log {
         return array();
     }
 
+    public function queryBranch()
+    {
+        $branches = $ret = array();
+        $command = $this->rep->getCommand() . ' branch --contains ' . escapeshellarg($this->rev) . ' 2>&1';
+        exec($command, $branches);
+        return array_map('trim', $branches, array_fill(0, count($branches), '* '));
+    }
+
 }
 
 /**