From 6df98d0af862bd4d46a949a34acf51b71b3dcf10 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 2 Feb 2009 23:53:29 -0700 Subject: [PATCH] Initial snapshot work. --- chora/browse.php | 6 +++++- chora/co.php | 4 ++++ framework/Vcs/lib/Horde/Vcs.php | 13 +++++++++++++ framework/Vcs/lib/Horde/Vcs/Git.php | 21 ++++++++++++++------- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/chora/browse.php b/chora/browse.php index 5370ed2e6..10090f46a 100644 --- a/chora/browse.php +++ b/chora/browse.php @@ -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); diff --git a/chora/co.php b/chora/co.php index dc325861b..968ad62ee 100644 --- a/chora/co.php +++ b/chora/co.php @@ -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); diff --git a/framework/Vcs/lib/Horde/Vcs.php b/framework/Vcs/lib/Horde/Vcs.php index 829d80896..5db4dedc5 100644 --- a/framework/Vcs/lib/Horde/Vcs.php +++ b/framework/Vcs/lib/Horde/Vcs.php @@ -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()) diff --git a/framework/Vcs/lib/Horde/Vcs/Git.php b/framework/Vcs/lib/Horde/Vcs/Git.php index f8742a592..c78dbb067 100644 --- a/framework/Vcs/lib/Horde/Vcs/Git.php +++ b/framework/Vcs/lib/Horde/Vcs/Git.php @@ -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); } } -- 2.11.0