Initial snapshot work.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 3 Feb 2009 06:53:29 +0000 (23:53 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 5 Feb 2009 06:49:15 +0000 (23:49 -0700)
chora/browse.php
chora/co.php
framework/Vcs/lib/Horde/Vcs.php
framework/Vcs/lib/Horde/Vcs/Git.php

index 5370ed2..10090f4 100644 (file)
@@ -21,9 +21,13 @@ Horde::addScriptFile('prototype.js', 'horde', true);
 Horde::addScriptFile('tables.js', 'horde', true);
 
 if ($atdir) {
+    $rev = $VC->hasFeature('snapshots')
+        ? Util::getFormData('rev')
+        : null;
+
     try {
         $atticFlags = (bool)$acts['sa'];
-        $dir = $VC->getDirObject($where, array('quicklog' => true, 'showattic' => $atticFlags));
+        $dir = $VC->getDirObject($where, array('quicklog' => true, 'rev' => $rev, 'showattic' => $atticFlags));
         $dir->applySort($acts['sbt'], $acts['ord']);
         $dirList = $dir->queryDirList();
         $fileList = $dir->queryFileList($atticFlags);
index dc32586..968ad62 100644 (file)
@@ -73,6 +73,10 @@ if (!$plain) {
         Horde::widget(Chora::url('annotate', $where, array('rev' => $r)), _("Annotate"), 'widget', '', '', _("_Annotate")),
         Horde::widget(Chora::url('co', $where, array('r' => $r, 'p' => 1)), _("Download"), 'widget', '', '', _("_Download"))
     );
+    if ($VC->hasFeature('snapshots')) {
+        $snapdir = dirname($file->queryPath());
+        $views[] = Horde::widget(Chora::url('browse', $snapdir == '.' ? '' : $snapdir, array('rev' => $r)), _("Snapshot"), 'widget', '', '', _("_Snapshot"));
+    }
     $extraLink = _("View:") . ' ' . implode(' | ', $views);
 
     $tags = Chora::getTags($log, $where);
index 829d808..5db4ded 100644 (file)
@@ -82,6 +82,15 @@ class Horde_Vcs
     protected $_branches = false;
 
     /**
+     * Does driver support snapshots?
+     *
+     * @var boolean
+     */
+    protected $_snapshots = false;
+
+    /**
+     * Current cache version.
+     *
      * @var integer
      */
     protected $_cacheVersion = 3;
@@ -144,6 +153,9 @@ class Horde_Vcs
         case 'patchsets':
             return $this->_patchsets;
 
+        case 'snapshots':
+            return $this->_snapshots;
+
         default:
             return false;
         }
@@ -449,6 +461,7 @@ class Horde_Vcs
      *
      * $opts:
      * 'quicklog' - (boolean)
+     * 'rev' - (string)
      * 'showAttic' - (boolean)
      */
     public function getDirObject($where, $opts = array())
index f8742a5..c78dbb0 100644 (file)
@@ -34,6 +34,13 @@ class Horde_Vcs_Git extends Horde_Vcs
     protected $_branches = true;
 
     /**
+     * Does driver support snapshots?
+     *
+     * @var boolean
+     */
+    protected $_snapshots = true;
+
+    /**
      * The available diff types.
      *
      * @var array
@@ -257,8 +264,7 @@ class Horde_Vcs_Directory_Git extends Horde_Vcs_Directory
     {
         parent::__construct($rep, $dn, $opts);
 
-        // @TODO For now, we're browsing master
-        $branch = 'master';
+        $branch = empty($opts['rev']) ? 'master' : $opts['rev'];
 
         // @TODO can use this to see if we have a valid cache of the tree at this revision
 
@@ -272,15 +278,16 @@ class Horde_Vcs_Directory_Git extends Horde_Vcs_Directory
 
         $cmd = $rep->getCommand() . ' ls-tree --full-name ' . escapeshellarg($branch) . ' ' . escapeshellarg($dir) . ' 2>&1';
 
-        $dir = popen($cmd, 'r');
-        if (!$dir) {
+        $stream = popen($cmd, 'r');
+        if (!$stream) {
             throw new Horde_Vcs_Exception('Failed to execute git ls-tree: ' . $cmd);
         }
 
         // Create two arrays - one of all the files, and the other of
         // all the dirs.
-        while (!feof($dir)) {
-            $line = chop(fgets($dir, 1024));
+        while (!feof($stream)) {
+            $line = chop(fgets($stream, 1024));
+            print "$line\n";
             if (!strlen($line)) {
                 continue;
             }
@@ -293,7 +300,7 @@ class Horde_Vcs_Directory_Git extends Horde_Vcs_Directory
             }
         }
 
-        pclose($dir);
+        pclose($stream);
     }
 
 }