From c9a4820abf2969ac182a0dd30438114481c72fe0 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 8 Mar 2011 09:54:55 -0800 Subject: [PATCH] Diffusion: basic file browse capability Summary: Very rough cut of file browsing. Not terribly useful yet, but it does cause file data to appear in the browser window. Test Plan: viewed a file from a git repo Reviewed By: jwilson Reviewers: aran, jwilson CC: jwilson Differential Revision: 64 --- src/__phutil_library_map__.php | 6 ++ .../browse/DiffusionBrowseController.php | 6 +- .../diffusion/controller/browse/__init__.php | 1 + .../file/DiffusionBrowseFileController.php | 64 +++++++++++++++++ .../diffusion/controller/file/__init__.php | 15 ++++ .../data/filecontent/DiffusionFileContent.php | 32 +++++++++ .../diffusion/data/filecontent/__init__.php | 10 +++ .../base/DiffusionFileContentQuery.php | 70 +++++++++++++++++++ .../query/filecontent/base/__init__.php | 12 ++++ .../git/DiffusionGitFileContentQuery.php | 42 +++++++++++ .../query/filecontent/git/__init__.php | 17 +++++ 11 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 src/applications/diffusion/controller/file/DiffusionBrowseFileController.php create mode 100644 src/applications/diffusion/controller/file/__init__.php create mode 100644 src/applications/diffusion/data/filecontent/DiffusionFileContent.php create mode 100644 src/applications/diffusion/data/filecontent/__init__.php create mode 100644 src/applications/diffusion/query/filecontent/base/DiffusionFileContentQuery.php create mode 100644 src/applications/diffusion/query/filecontent/base/__init__.php create mode 100644 src/applications/diffusion/query/filecontent/git/DiffusionGitFileContentQuery.php create mode 100644 src/applications/diffusion/query/filecontent/git/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 929cef998b..c401455052 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -143,10 +143,14 @@ phutil_register_library_map(array( 'DifferentialSubscribeController' => 'applications/differential/controller/subscribe', 'DifferentialUnitStatus' => 'applications/differential/constants/unitstatus', 'DiffusionBrowseController' => 'applications/diffusion/controller/browse', + 'DiffusionBrowseFileController' => 'applications/diffusion/controller/file', 'DiffusionBrowseQuery' => 'applications/diffusion/query/browse/base', 'DiffusionBrowseTableView' => 'applications/diffusion/view/browsetable', 'DiffusionController' => 'applications/diffusion/controller/base', + 'DiffusionFileContent' => 'applications/diffusion/data/filecontent', + 'DiffusionFileContentQuery' => 'applications/diffusion/query/filecontent/base', 'DiffusionGitBrowseQuery' => 'applications/diffusion/query/browse/git', + 'DiffusionGitFileContentQuery' => 'applications/diffusion/query/filecontent/git', 'DiffusionHomeController' => 'applications/diffusion/controller/home', 'DiffusionRepositoryPath' => 'applications/diffusion/data/repositorypath', 'Javelin' => 'infrastructure/javelin/api', @@ -428,9 +432,11 @@ phutil_register_library_map(array( 'DifferentialRevisionViewController' => 'DifferentialController', 'DifferentialSubscribeController' => 'DifferentialController', 'DiffusionBrowseController' => 'DiffusionController', + 'DiffusionBrowseFileController' => 'DiffusionController', 'DiffusionBrowseTableView' => 'AphrontView', 'DiffusionController' => 'PhabricatorController', 'DiffusionGitBrowseQuery' => 'DiffusionBrowseQuery', + 'DiffusionGitFileContentQuery' => 'DiffusionFileContentQuery', 'DiffusionHomeController' => 'DiffusionController', 'ManiphestController' => 'PhabricatorController', 'ManiphestDAO' => 'PhabricatorLiskDAO', diff --git a/src/applications/diffusion/controller/browse/DiffusionBrowseController.php b/src/applications/diffusion/controller/browse/DiffusionBrowseController.php index 389929a1e0..d24cfa29c6 100644 --- a/src/applications/diffusion/controller/browse/DiffusionBrowseController.php +++ b/src/applications/diffusion/controller/browse/DiffusionBrowseController.php @@ -66,7 +66,11 @@ class DiffusionBrowseController extends DiffusionController { $severity = AphrontErrorView::SEVERITY_WARNING; break; case DiffusionBrowseQuery::REASON_IS_FILE: - throw new Exception("TODO: implement this"); + $controller = new DiffusionBrowseFileController($this->getRequest()); + $controller->setRepository($repository); + $controller->setPath($this->path); + $controller->setCommit($this->commit); + return $this->delegateToController($controller); break; default: throw new Exception("Unknown failure reason!"); diff --git a/src/applications/diffusion/controller/browse/__init__.php b/src/applications/diffusion/controller/browse/__init__.php index faac6fe040..1ee1f7f36b 100644 --- a/src/applications/diffusion/controller/browse/__init__.php +++ b/src/applications/diffusion/controller/browse/__init__.php @@ -7,6 +7,7 @@ phutil_require_module('phabricator', 'applications/diffusion/controller/base'); +phutil_require_module('phabricator', 'applications/diffusion/controller/file'); phutil_require_module('phabricator', 'applications/diffusion/query/browse/base'); phutil_require_module('phabricator', 'applications/diffusion/view/browsetable'); phutil_require_module('phabricator', 'view/form/error'); diff --git a/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php new file mode 100644 index 0000000000..6a605b72c1 --- /dev/null +++ b/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php @@ -0,0 +1,64 @@ +repository = $repository; + } + + public function setCommit($commit) { + $this->commit = $commit; + return $this; + } + + public function setPath($path) { + $this->path = $path; + return $this; + } + + public function processRequest() { + $file_query = DiffusionFileContentQuery::newFromRepository( + $this->repository, + $this->path, + $this->commit); + $file_content = $file_query->loadFileContent(); + + $corpus = phutil_render_tag( + 'textarea', + array( + ), + phutil_escape_html($file_content->getCorpus())); + + // TODO: blame, color, line numbers, highlighting, etc etc + + return $this->buildStandardPageResponse( + $corpus, + array( + 'title' => 'Browse', + )); + } +} diff --git a/src/applications/diffusion/controller/file/__init__.php b/src/applications/diffusion/controller/file/__init__.php new file mode 100644 index 0000000000..cffe0092da --- /dev/null +++ b/src/applications/diffusion/controller/file/__init__.php @@ -0,0 +1,15 @@ +corpus = $corpus; + return $this; + } + + final public function getCorpus() { + return $this->corpus; + } + +} diff --git a/src/applications/diffusion/data/filecontent/__init__.php b/src/applications/diffusion/data/filecontent/__init__.php new file mode 100644 index 0000000000..a9917cc10c --- /dev/null +++ b/src/applications/diffusion/data/filecontent/__init__.php @@ -0,0 +1,10 @@ + + } + + final public static function newFromRepository( + PhabricatorRepository $repository, + $path = '/', + $commit = null) { + + switch ($repository->getVersionControlSystem()) { + case 'git': + $class = 'DiffusionGitFileContentQuery'; + break; + default: + throw new Exception("Unsupported VCS!"); + } + + PhutilSymbolLoader::loadClass($class); + $query = new $class(); + + $query->repository = $repository; + $query->path = $path; + $query->commit = $commit; + + return $query; + } + + final protected function getRepository() { + return $this->repository; + } + + final protected function getPath() { + return $this->path; + } + + final protected function getCommit() { + return $this->commit; + } + + + final public function loadFileContent() { + return $this->executeQuery(); + } + + abstract protected function executeQuery(); +} diff --git a/src/applications/diffusion/query/filecontent/base/__init__.php b/src/applications/diffusion/query/filecontent/base/__init__.php new file mode 100644 index 0000000000..78aec40d93 --- /dev/null +++ b/src/applications/diffusion/query/filecontent/base/__init__.php @@ -0,0 +1,12 @@ +getRepository(); + $path = $this->getPath(); + $commit = nonempty($this->getCommit(), 'HEAD'); + + $local_path = $repository->getDetail('local-path'); + $git = PhabricatorEnv::getEnvConfig('git.path'); + + list($corpus) = execx( + '(cd %s && %s cat-file blob %s:%s)', + $local_path, + $git, + $commit, + $path); + + $file_content = new DiffusionFileContent(); + $file_content->setCorpus($corpus); + + return $file_content; + } + +} diff --git a/src/applications/diffusion/query/filecontent/git/__init__.php b/src/applications/diffusion/query/filecontent/git/__init__.php new file mode 100644 index 0000000000..03cf4d9473 --- /dev/null +++ b/src/applications/diffusion/query/filecontent/git/__init__.php @@ -0,0 +1,17 @@ +