From c82cab35e286e5fa12b35b34e295346370cee924 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 8 Mar 2011 17:31:44 -0800 Subject: [PATCH] Diffusion: rough cut of history view Summary: Very very rough approximation of history view. I left out all the log parsing stuff for now since we should be able to just look it up in a Repository table and I think that'll be a bit faster, although we can muck around and see. Test Plan: Looked at history of a path Reviewed By: jwilson Reviewers: aran, jwilson CC: epriestley, jwilson Differential Revision: 66 --- src/__phutil_library_map__.php | 8 +++ ...AphrontDefaultApplicationConfiguration.php | 18 +++-- .../controller/base/DiffusionController.php | 12 ++++ .../diffusion/controller/base/__init__.php | 1 + .../browse/DiffusionBrowseController.php | 5 -- .../diffusion/controller/browse/__init__.php | 1 - .../file/DiffusionBrowseFileController.php | 7 -- .../history/DiffusionHistoryController.php | 51 ++++++++++++++ .../diffusion/controller/history/__init__.php | 15 +++++ .../data/pathchange/DiffusionPathChange.php | 33 ++++++++++ .../diffusion/data/pathchange/__init__.php | 10 +++ .../history/base/DiffusionHistoryQuery.php | 57 ++++++++++++++++ .../diffusion/query/history/base/__init__.php | 12 ++++ .../history/git/DiffusionGitHistoryQuery.php | 66 +++++++++++++++++++ .../diffusion/query/history/git/__init__.php | 15 +++++ .../request/git/DiffusionGitRequest.php | 1 + .../browsetable/DiffusionBrowseTableView.php | 1 + .../DiffusionHistoryTableView.php | 51 ++++++++++++++ .../diffusion/view/historytable/__init__.php | 15 +++++ 19 files changed, 361 insertions(+), 18 deletions(-) create mode 100644 src/applications/diffusion/controller/history/DiffusionHistoryController.php create mode 100644 src/applications/diffusion/controller/history/__init__.php create mode 100644 src/applications/diffusion/data/pathchange/DiffusionPathChange.php create mode 100644 src/applications/diffusion/data/pathchange/__init__.php create mode 100644 src/applications/diffusion/query/history/base/DiffusionHistoryQuery.php create mode 100644 src/applications/diffusion/query/history/base/__init__.php create mode 100644 src/applications/diffusion/query/history/git/DiffusionGitHistoryQuery.php create mode 100644 src/applications/diffusion/query/history/git/__init__.php create mode 100644 src/applications/diffusion/view/historytable/DiffusionHistoryTableView.php create mode 100644 src/applications/diffusion/view/historytable/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6573b1230c..1d9cba1c31 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -151,8 +151,13 @@ phutil_register_library_map(array( 'DiffusionFileContentQuery' => 'applications/diffusion/query/filecontent/base', 'DiffusionGitBrowseQuery' => 'applications/diffusion/query/browse/git', 'DiffusionGitFileContentQuery' => 'applications/diffusion/query/filecontent/git', + 'DiffusionGitHistoryQuery' => 'applications/diffusion/query/history/git', 'DiffusionGitRequest' => 'applications/diffusion/request/git', + 'DiffusionHistoryController' => 'applications/diffusion/controller/history', + 'DiffusionHistoryQuery' => 'applications/diffusion/query/history/base', + 'DiffusionHistoryTableView' => 'applications/diffusion/view/historytable', 'DiffusionHomeController' => 'applications/diffusion/controller/home', + 'DiffusionPathChange' => 'applications/diffusion/data/pathchange', 'DiffusionRepositoryPath' => 'applications/diffusion/data/repositorypath', 'DiffusionRequest' => 'applications/diffusion/request/base', 'Javelin' => 'infrastructure/javelin/api', @@ -439,7 +444,10 @@ phutil_register_library_map(array( 'DiffusionController' => 'PhabricatorController', 'DiffusionGitBrowseQuery' => 'DiffusionBrowseQuery', 'DiffusionGitFileContentQuery' => 'DiffusionFileContentQuery', + 'DiffusionGitHistoryQuery' => 'DiffusionHistoryQuery', 'DiffusionGitRequest' => 'DiffusionRequest', + 'DiffusionHistoryController' => 'DiffusionController', + 'DiffusionHistoryTableView' => 'AphrontView', 'DiffusionHomeController' => 'DiffusionController', 'ManiphestController' => 'PhabricatorController', 'ManiphestDAO' => 'PhabricatorLiskDAO', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index cc2ac4d24b..9b6e8ef523 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -185,11 +185,19 @@ class AphrontDefaultApplicationConfiguration '/diffusion/' => array( '$' => 'DiffusionHomeController', - '(?P[A-Z]+)/browse/'. - '(?P.*?)'. - '(?:[;](?P[a-z0-9]+))?'. - '(?:[$](?P\d+))?$' - => 'DiffusionBrowseController', + '(?P[A-Z]+)' => array( + '/history/'. + '(?P.*?)'. + '(?:[;](?P[a-z0-9]+))?'. + '$' + => 'DiffusionHistoryController', + '/browse/'. + '(?P.*?)'. + '(?:[;](?P[a-z0-9]+))?'. + '(?:[$](?P\d+))?'. + '$' + => 'DiffusionBrowseController', + ), ), ); diff --git a/src/applications/diffusion/controller/base/DiffusionController.php b/src/applications/diffusion/controller/base/DiffusionController.php index 3e07b1230b..5f6bc85bdb 100644 --- a/src/applications/diffusion/controller/base/DiffusionController.php +++ b/src/applications/diffusion/controller/base/DiffusionController.php @@ -18,6 +18,18 @@ abstract class DiffusionController extends PhabricatorController { + protected $diffusionRequest; + + public function willProcessRequest(array $data) { + $this->diffusionRequest = DiffusionRequest::newFromAphrontRequestDictionary( + $data); + } + + public function setDiffusionRequest(DiffusionRequest $request) { + $this->diffusionRequest = $request; + return $this; + } + public function buildStandardPageResponse($view, array $data) { $page = $this->buildStandardPageView(); diff --git a/src/applications/diffusion/controller/base/__init__.php b/src/applications/diffusion/controller/base/__init__.php index cf7b058332..c68cb98500 100644 --- a/src/applications/diffusion/controller/base/__init__.php +++ b/src/applications/diffusion/controller/base/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'aphront/response/webpage'); phutil_require_module('phabricator', 'applications/base/controller/base'); +phutil_require_module('phabricator', 'applications/diffusion/request/base'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/diffusion/controller/browse/DiffusionBrowseController.php b/src/applications/diffusion/controller/browse/DiffusionBrowseController.php index 4111071053..5d1af4babd 100644 --- a/src/applications/diffusion/controller/browse/DiffusionBrowseController.php +++ b/src/applications/diffusion/controller/browse/DiffusionBrowseController.php @@ -18,11 +18,6 @@ class DiffusionBrowseController extends DiffusionController { - public function willProcessRequest(array $data) { - $this->diffusionRequest = DiffusionRequest::newFromAphrontRequestDictionary( - $data); - } - public function processRequest() { $drequest = $this->diffusionRequest; diff --git a/src/applications/diffusion/controller/browse/__init__.php b/src/applications/diffusion/controller/browse/__init__.php index 39dd2990e2..afb636203c 100644 --- a/src/applications/diffusion/controller/browse/__init__.php +++ b/src/applications/diffusion/controller/browse/__init__.php @@ -9,7 +9,6 @@ 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/request/base'); phutil_require_module('phabricator', 'applications/diffusion/view/browsetable'); phutil_require_module('phabricator', 'view/form/error'); phutil_require_module('phabricator', 'view/layout/panel'); diff --git a/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php index 87f79b7803..7dec1a0bae 100644 --- a/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php +++ b/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php @@ -18,13 +18,6 @@ class DiffusionBrowseFileController extends DiffusionController { - private $diffusionRequest; - - public function setDiffusionRequest(DiffusionRequest $request) { - $this->diffusionRequest = $request; - return $this; - } - public function processRequest() { $file_query = DiffusionFileContentQuery::newFromDiffusionRequest( $this->diffusionRequest); diff --git a/src/applications/diffusion/controller/history/DiffusionHistoryController.php b/src/applications/diffusion/controller/history/DiffusionHistoryController.php new file mode 100644 index 0000000000..3f5ee68690 --- /dev/null +++ b/src/applications/diffusion/controller/history/DiffusionHistoryController.php @@ -0,0 +1,51 @@ +diffusionRequest; + + $history_query = DiffusionHistoryQuery::newFromDiffusionRequest( + $drequest); + + $history = $history_query->loadHistory(); + + $content = array(); + + $history_table = new DiffusionHistoryTableView(); + $history_table->setDiffusionRequest($drequest); + $history_table->setHistory($history); + + $history_panel = new AphrontPanelView(); + $history_panel->setHeader($drequest->getPath()); + $history_panel->appendChild($history_table); + + $content[] = $history_panel; + + // TODO: Crumbs + // TODO: Side nav + + return $this->buildStandardPageResponse( + $content, + array( + 'title' => 'history', + )); + } + +} diff --git a/src/applications/diffusion/controller/history/__init__.php b/src/applications/diffusion/controller/history/__init__.php new file mode 100644 index 0000000000..21bf7ac13f --- /dev/null +++ b/src/applications/diffusion/controller/history/__init__.php @@ -0,0 +1,15 @@ +commit = $commit; + return $this; + } + + final public function getCommit() { + return $this->commit; + } + + +} diff --git a/src/applications/diffusion/data/pathchange/__init__.php b/src/applications/diffusion/data/pathchange/__init__.php new file mode 100644 index 0000000000..1e0dcbd347 --- /dev/null +++ b/src/applications/diffusion/data/pathchange/__init__.php @@ -0,0 +1,10 @@ + + } + + final public static function newFromDiffusionRequest( + DiffusionRequest $request) { + + $repository = $request->getRepository(); + + switch ($repository->getVersionControlSystem()) { + case 'git': + $class = 'DiffusionGitHistoryQuery'; + break; + default: + throw new Exception("Unsupported VCS!"); + } + + PhutilSymbolLoader::loadClass($class); + $query = new $class(); + + $query->request = $request; + + return $query; + } + + final protected function getRequest() { + return $this->request; + } + + final public function loadHistory() { + return $this->executeQuery(); + } + + abstract protected function executeQuery(); +} diff --git a/src/applications/diffusion/query/history/base/__init__.php b/src/applications/diffusion/query/history/base/__init__.php new file mode 100644 index 0000000000..df26090017 --- /dev/null +++ b/src/applications/diffusion/query/history/base/__init__.php @@ -0,0 +1,12 @@ +getRequest(); + + $repository = $drequest->getRepository(); + $path = $drequest->getPath(); + $commit = $drequest->getCommit(); + + $local_path = $repository->getDetail('local-path'); + $git = $drequest->getPathToGitBinary(); + + list($stdout) = execx( + '(cd %s && %s log '. + '-n %d '. + '--skip=%d '. + '-M '. + '-C '. + '-B '. + '--find-copies-harder '. + '--raw '. + '-t '. + '--abbrev=40 '. + '--pretty=format:%%x1c%%H%%x1d '. + '%s -- %s)', + $local_path, + $git, + $limit = 100, + $offset = 0, + $commit, + $path); + + $commits = explode("\x1c", $stdout); + array_shift($commits); // \x1c character is first, remove empty record + + $history = array(); + foreach ($commits as $commit) { + list($hash, $raw) = explode("\x1d", $commit); + + $item = new DiffusionPathChange(); + $item->setCommit($hash); + $history[] = $item; + } + + return $history; + } + +} diff --git a/src/applications/diffusion/query/history/git/__init__.php b/src/applications/diffusion/query/history/git/__init__.php new file mode 100644 index 0000000000..c2a505f6df --- /dev/null +++ b/src/applications/diffusion/query/history/git/__init__.php @@ -0,0 +1,15 @@ +getBranch(); + execx( '(cd %s && %s rev-parse --verify %s)', $local_path, diff --git a/src/applications/diffusion/view/browsetable/DiffusionBrowseTableView.php b/src/applications/diffusion/view/browsetable/DiffusionBrowseTableView.php index 3ae2eda93a..389ac421af 100644 --- a/src/applications/diffusion/view/browsetable/DiffusionBrowseTableView.php +++ b/src/applications/diffusion/view/browsetable/DiffusionBrowseTableView.php @@ -19,6 +19,7 @@ final class DiffusionBrowseTableView extends AphrontView { private $request; + private $paths; public function setDiffusionRequest(DiffusionRequest $request) { $this->request = $request; diff --git a/src/applications/diffusion/view/historytable/DiffusionHistoryTableView.php b/src/applications/diffusion/view/historytable/DiffusionHistoryTableView.php new file mode 100644 index 0000000000..3f05c6d7ce --- /dev/null +++ b/src/applications/diffusion/view/historytable/DiffusionHistoryTableView.php @@ -0,0 +1,51 @@ +request = $request; + return $this; + } + + public function setHistory(array $history) { + $this->history = $history; + return $this; + } + + public function render() { + $rows = array(); + foreach ($this->history as $history) { + $rows[] = array( + phutil_escape_html($history->getCommit()), // TODO: link + // TODO: etc etc + ); + } + + $view = new AphrontTableView($rows); + $view->setHeaders( + array( + 'Commit', + )); + return $view->render(); + } + +} diff --git a/src/applications/diffusion/view/historytable/__init__.php b/src/applications/diffusion/view/historytable/__init__.php new file mode 100644 index 0000000000..e53ae0b476 --- /dev/null +++ b/src/applications/diffusion/view/historytable/__init__.php @@ -0,0 +1,15 @@ +