From 01bf7b3fe0d5fab0ae3965967acf70057da8e180 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 16 Jun 2009 02:28:20 -0600 Subject: [PATCH] Work re: navigation within an implicit branch Display of directory seems to be working well. Still needs more work at file level (main issue is that revision number needs to be passed to all links). --- chora/browsedir.php | 12 ++++++------ chora/co.php | 2 +- framework/Vcs/lib/Horde/Vcs/Git.php | 34 ++++++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/chora/browsedir.php b/chora/browsedir.php index 610ad512f..83e8149c5 100644 --- a/chora/browsedir.php +++ b/chora/browsedir.php @@ -37,7 +37,7 @@ $title = ($where == '') : sprintf(_("Source Directory of /%s"), $where); $extraLink = $VC->hasFeature('deleted') - ? Horde::widget(Chora::url('browsedir', $where . '/', array('sa' => ($acts['sa'] ? 0 : 1))), $acts['sa'] ? _("Hide Deleted Files") : _("Show Deleted Files"), 'widget', '', '', $acts['sa'] ? _("Hide _Deleted Files") : _("Show _Deleted Files")) + ? Horde::widget(Chora::url('browsedir', $where . '/', array('rev' => $rev, 'sa' => ($acts['sa'] ? 0 : 1))), $acts['sa'] ? _("Hide Deleted Files") : _("Show Deleted Files"), 'widget', '', '', $acts['sa'] ? _("Hide _Deleted Files") : _("Show _Deleted Files")) : ''; $umap = array( @@ -52,13 +52,13 @@ foreach ($umap as $key => $val) { if ($acts['sbt'] == $val) { $arg['ord'] = !$acts['ord']; } - $url[$key] = Chora::url('browsedir', $where . '/', $arg); + $url[$key] = Chora::url('browsedir', $where . '/', $arg, array('rev' => $rev)); } $branches = array(); if ($VC->hasFeature('branches')) { $branches = $dir->getBranches(); - if ($rev === null) { + if (is_null($rev)) { $rev = $dir->getDefaultBranch(); } } @@ -76,7 +76,7 @@ require CHORA_TEMPLATES . '/directory/header.inc'; /* Unless we're at the top, display the 'back' bar. */ if ($where != '') { - $url = Chora::url('browsedir', preg_replace('|[^/]+$|', '', $where)); + $url = Chora::url('browsedir', preg_replace('|[^/]+$|', '', $where), array('rev' => $rev)); require CHORA_TEMPLATES . '/directory/back.inc'; } @@ -87,7 +87,7 @@ if ($dirList) { if ($conf['hide_restricted'] && Chora::isRestricted($currentDir)) { continue; } - $url = Chora::url('browsedir', $where . '/' . $currentDir . '/'); + $url = Chora::url('browsedir', $where . '/' . $currentDir . '/', array('rev' => $rev)); $currDir = Horde_Text_Filter::filter($currentDir, 'space2html', array('charset' => NLS::getCharset(), 'encode' => true, 'encode_all' => true)); require CHORA_TEMPLATES . '/directory/dir.inc'; } @@ -116,7 +116,7 @@ if ($fileList) { $attic = $currFile->isDeleted(); $fileName = $where . ($attic ? '/' . 'Attic' : '') . '/' . $realname; $name = Horde_Text_Filter::filter($realname, 'space2html', array('charset' => NLS::getCharset(), 'encode' => true, 'encode_all' => true)); - $url = Chora::url('browsefile', $fileName); + $url = Chora::url('browsefile', $fileName, array('onb' => $rev)); $readableDate = Chora::readableTime($date); if ($log) { $shortLog = str_replace("\n", ' ', trim(substr($log, 0, $conf['options']['shortLogLength'] - 1))); diff --git a/chora/co.php b/chora/co.php index d54e26633..6d0495914 100644 --- a/chora/co.php +++ b/chora/co.php @@ -75,7 +75,7 @@ if (!$plain) { ); if ($VC->hasFeature('snapshots')) { $snapdir = dirname($file->queryPath()); - $views[] = Horde::widget(Chora::url('browsedir', $snapdir == '.' ? '' : $snapdir, array('rev' => $r)), _("Snapshot"), 'widget', '', '', _("_Snapshot")); + $views[] = Horde::widget(Chora::url('browsedir', $snapdir == '.' ? '' : $snapdir . '/', array('rev' => $r)), _("Snapshot"), 'widget', '', '', _("_Snapshot")); } $extraLink = _("View:") . ' ' . implode(' | ', $views); diff --git a/framework/Vcs/lib/Horde/Vcs/Git.php b/framework/Vcs/lib/Horde/Vcs/Git.php index 3721f26fd..4c5875b16 100644 --- a/framework/Vcs/lib/Horde/Vcs/Git.php +++ b/framework/Vcs/lib/Horde/Vcs/Git.php @@ -285,6 +285,9 @@ class Horde_Vcs_Git extends Horde_Vcs return substr($rev, 0, 7) . '[...]'; } + /** + * TODO + */ public function getBranchList() { if (!isset($this->_branchlist)) { @@ -312,6 +315,13 @@ class Horde_Vcs_Git extends Horde_Vcs class Horde_Vcs_Directory_Git extends Horde_Vcs_Directory { /** + * The current branch. + * + * @var string + */ + protected $_branch; + + /** * Create a Directory object to store information about the files in a * single directory in the repository. * @@ -325,7 +335,7 @@ class Horde_Vcs_Directory_Git extends Horde_Vcs_Directory { parent::__construct($rep, $dn, $opts); - $branch = empty($opts['rev']) ? 'master' : $opts['rev']; + $this->_branch = empty($opts['rev']) ? 'master' : $opts['rev']; // @TODO See if we have a valid cache of the tree at this revision @@ -337,7 +347,7 @@ class Horde_Vcs_Directory_Git extends Horde_Vcs_Directory $dir .= '/'; } - $cmd = $rep->getCommand() . ' ls-tree --full-name ' . escapeshellarg($branch) . ' ' . escapeshellarg($dir) . ' 2>&1'; + $cmd = $rep->getCommand() . ' ls-tree --full-name ' . escapeshellarg($this->_branch) . ' ' . escapeshellarg($dir) . ' 2>&1'; $stream = popen($cmd, 'r'); if (!$stream) { throw new Horde_Vcs_Exception('Failed to execute git ls-tree: ' . $cmd); @@ -356,7 +366,7 @@ class Horde_Vcs_Directory_Git extends Horde_Vcs_Directory if ($type == 'tree') { $this->_dirs[] = basename($file); } else { - $this->_files[] = $rep->getFileObject($file, array('branch' => $branch, 'quicklog' => !empty($opts['quicklog']))); + $this->_files[] = $rep->getFileObject($file, array('branch' => $this->_branch, 'quicklog' => !empty($opts['quicklog']))); } } @@ -368,7 +378,11 @@ class Horde_Vcs_Directory_Git extends Horde_Vcs_Directory */ public function getBranches() { - return array_keys($this->_rep->getBranchList()); + $blist = array_keys($this->_rep->getBranchList()); + if (!in_array($this->_branch, $blist)) { + $blist[] = $this->_branch; + } + return $blist; } /** @@ -442,7 +456,7 @@ class Horde_Vcs_File_Git extends Horde_Vcs_File /* Get the list of revisions. Need to get all revisions, not just * those on $this->_branch, for branch determination reasons. */ - foreach (array_keys($rep->getBranchList()) as $key) { + foreach (array_keys($this->queryBranches()) as $key) { $revs = array(); $cmd = $rep->getCommand() . ' rev-list ' . escapeshellarg($key) . ' -- ' . escapeshellarg($this->queryModulePath()) . ' 2>&1'; exec($cmd, $revs); @@ -540,7 +554,15 @@ class Horde_Vcs_File_Git extends Horde_Vcs_File */ public function queryBranches() { - return $this->_rep->getBranchList(); + /* If dealing with a branch that is not explicitly named (i.e. an + * implicit branch for a given tree-ish commit ID), we need to add + * that information to the branch list. */ + $revlist = $this->_rep->getBranchList(); + if (!empty($this->_branch) && + !in_array($this->_branch, $revlist)) { + $revlist[$this->_branch] = $this->_branch; + } + return $revlist; } /** -- 2.11.0