From 11ea93260a6deefe01f7122c73b559d50e0434a1 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 5 Apr 2011 20:49:31 -0700 Subject: [PATCH] Sync up UUIDs and create project configs. --- resources/sql/patches/019.arcprojects.sql | 17 +++ src/__phutil_library_map__.php | 4 + ...AphrontDefaultApplicationConfiguration.php | 2 + ...duitAPI_differential_creatediff_Method.php | 19 ++- .../differential/creatediff/__init__.php | 1 + .../changeset/DifferentialChangeset.php | 25 ++++ .../storage/changeset/__init__.php | 2 + .../storage/diff/DifferentialDiff.php | 3 +- .../HeraldDifferentialRevisionAdapter.php | 137 ++++++++++++------ .../herald/adapter/differential/__init__.php | 4 + .../test/HeraldTestConsoleController.php | 4 +- ...epositoryArcanistProjectEditController.php | 92 ++++++++++++ .../arcansistprojectedit/__init__.php | 21 +++ .../PhabricatorRepositoryListController.php | 47 +++++- .../repository/controller/list/__init__.php | 1 + .../PhabricatorRepositoryArcanistProject.php | 37 +++++ .../storage/arcanistproject/__init__.php | 13 ++ 17 files changed, 380 insertions(+), 49 deletions(-) create mode 100644 resources/sql/patches/019.arcprojects.sql create mode 100644 src/applications/repository/controller/arcansistprojectedit/PhabricatorRepositoryArcanistProjectEditController.php create mode 100644 src/applications/repository/controller/arcansistprojectedit/__init__.php create mode 100644 src/applications/repository/storage/arcanistproject/PhabricatorRepositoryArcanistProject.php create mode 100644 src/applications/repository/storage/arcanistproject/__init__.php diff --git a/resources/sql/patches/019.arcprojects.sql b/resources/sql/patches/019.arcprojects.sql new file mode 100644 index 0000000000..2f585a134a --- /dev/null +++ b/resources/sql/patches/019.arcprojects.sql @@ -0,0 +1,17 @@ +CREATE TABLE phabricator_repository.repository_arcanistproject ( + id int unsigned not null auto_increment primary key, + phid varchar(64) binary not null, + unique key(phid), + name varchar(255) not null, + unique key (name), + repositoryID int unsigned +); + +ALTER TABLE phabricator_repository.repository + ADD uuid varchar(64) binary; + +ALTER TABLE phabricator_differential.differential_diff + CHANGE arcanistProject arcanistProjectPHID varchar(64) binary; + +ALTER TABLE phabricator_differential.differential_diff + ADD repositoryUUID varchar(64) binary; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0834bbfd25..860271769b 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -354,6 +354,8 @@ phutil_register_library_map(array( 'PhabricatorRemarkupRuleDifferential' => 'infrastructure/markup/remarkup/markuprule/differential', 'PhabricatorRemarkupRuleManiphest' => 'infrastructure/markup/remarkup/markuprule/maniphest', 'PhabricatorRepository' => 'applications/repository/storage/repository', + 'PhabricatorRepositoryArcanistProject' => 'applications/repository/storage/arcanistproject', + 'PhabricatorRepositoryArcanistProjectEditController' => 'applications/repository/controller/arcansistprojectedit', 'PhabricatorRepositoryCommit' => 'applications/repository/storage/commit', 'PhabricatorRepositoryCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/base', 'PhabricatorRepositoryCommitData' => 'applications/repository/storage/commitdata', @@ -715,6 +717,8 @@ phutil_register_library_map(array( 'PhabricatorRemarkupRuleDifferential' => 'PhutilRemarkupRule', 'PhabricatorRemarkupRuleManiphest' => 'PhutilRemarkupRule', 'PhabricatorRepository' => 'PhabricatorRepositoryDAO', + 'PhabricatorRepositoryArcanistProject' => 'PhabricatorRepositoryDAO', + 'PhabricatorRepositoryArcanistProjectEditController' => 'PhabricatorRepositoryController', 'PhabricatorRepositoryCommit' => 'PhabricatorRepositoryDAO', 'PhabricatorRepositoryCommitChangeParserWorker' => 'PhabricatorRepositoryCommitParserWorker', 'PhabricatorRepositoryCommitData' => 'PhabricatorRepositoryDAO', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index fe6fbb202f..dd75e97589 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -166,6 +166,8 @@ class AphrontDefaultApplicationConfiguration 'edit/(?P\d+)/(?:(?P\w+)?/)?$' => 'PhabricatorRepositoryEditController', 'delete/(?P\d+)/$' => 'PhabricatorRepositoryDeleteController', + 'project/(?P\d+)/' => + 'PhabricatorRepositoryArcanistProjectEditController', ), '/search/' => array( diff --git a/src/applications/conduit/method/differential/creatediff/ConduitAPI_differential_creatediff_Method.php b/src/applications/conduit/method/differential/creatediff/ConduitAPI_differential_creatediff_Method.php index ccf09be6ab..077f245233 100644 --- a/src/applications/conduit/method/differential/creatediff/ConduitAPI_differential_creatediff_Method.php +++ b/src/applications/conduit/method/differential/creatediff/ConduitAPI_differential_creatediff_Method.php @@ -35,6 +35,7 @@ class ConduitAPI_differential_creatediff_Method extends ConduitAPIMethod { 'creationMethod' => 'optional string', 'authorPHID' => 'optional phid', 'arcanistProject' => 'optional string', + 'repositoryUUID' => 'optional string', 'lintStatus' => 'required enum', 'unitStatus' => @@ -83,7 +84,23 @@ class ConduitAPI_differential_creatediff_Method extends ConduitAPIMethod { $diff->setSourceControlBaseRevision( $request->getValue('sourceControlBaseRevision')); - $diff->setArcanistProject($request->getValue('arcanistProject')); + $project_name = $request->getValue('arcanistProject'); + $project_phid = null; + if ($project_name) { + $arcanist_project = id(new PhabricatorRepositoryArcanistProject()) + ->loadOneWhere( + 'name = %s', + $project_name); + if (!$arcanist_project) { + $arcanist_project = new PhabricatorRepositoryArcanistProject(); + $arcanist_project->setName($project_name); + $arcanist_project->save(); + } + $project_phid = $arcanist_project->getPHID(); + } + + $diff->setArcanistProjectPHID($project_phid); + $diff->setRepositoryUUID($request->getValue('repositoryUUID')); switch ($request->getValue('lintStatus')) { case 'skip': diff --git a/src/applications/conduit/method/differential/creatediff/__init__.php b/src/applications/conduit/method/differential/creatediff/__init__.php index 160deafd17..137408c743 100644 --- a/src/applications/conduit/method/differential/creatediff/__init__.php +++ b/src/applications/conduit/method/differential/creatediff/__init__.php @@ -14,6 +14,7 @@ phutil_require_module('phabricator', 'applications/differential/constants/revisi phutil_require_module('phabricator', 'applications/differential/constants/unitstatus'); phutil_require_module('phabricator', 'applications/differential/storage/diff'); phutil_require_module('phabricator', 'applications/differential/storage/revision'); +phutil_require_module('phabricator', 'applications/repository/storage/arcanistproject'); phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/differential/storage/changeset/DifferentialChangeset.php b/src/applications/differential/storage/changeset/DifferentialChangeset.php index 14c2bb8e8c..29f1b402ca 100644 --- a/src/applications/differential/storage/changeset/DifferentialChangeset.php +++ b/src/applications/differential/storage/changeset/DifferentialChangeset.php @@ -157,4 +157,29 @@ class DifferentialChangeset extends DifferentialDAO { return substr(md5($this->getFilename()), 0, 8); } + public function getAbsoluteRepositoryPath( + DifferentialDiff $diff, + PhabricatorRepository $repository) { + + $base = '/'; + if ($diff->getSourceControlPath()) { + $base = id(new PhutilURI($diff->getSourceControlPath()))->getPath(); + } + + $path = $this->getFileName(); + $path = rtrim($base, '/').'/'.ltrim($path, '/'); + + $vcs = $repository->getVersionControlSystem(); + if ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_SVN) { + $prefix = $repository->getDetail('remote-uri'); + $prefix = id(new PhutilURI($prefix))->getPath(); + if (!strncmp($path, $prefix, strlen($prefix))) { + $path = substr($path, strlen($prefix)); + } + $path = '/'.ltrim($path, '/'); + } + + return $path; + } + } diff --git a/src/applications/differential/storage/changeset/__init__.php b/src/applications/differential/storage/changeset/__init__.php index 3b8085af0a..da4cbf09ba 100644 --- a/src/applications/differential/storage/changeset/__init__.php +++ b/src/applications/differential/storage/changeset/__init__.php @@ -9,7 +9,9 @@ phutil_require_module('phabricator', 'applications/differential/constants/changetype'); phutil_require_module('phabricator', 'applications/differential/storage/base'); phutil_require_module('phabricator', 'applications/differential/storage/hunk'); +phutil_require_module('phabricator', 'applications/repository/constants/repositorytype'); +phutil_require_module('phutil', 'parser/uri'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/differential/storage/diff/DifferentialDiff.php b/src/applications/differential/storage/diff/DifferentialDiff.php index a76626cebc..8fbca6bb8f 100644 --- a/src/applications/differential/storage/diff/DifferentialDiff.php +++ b/src/applications/differential/storage/diff/DifferentialDiff.php @@ -36,8 +36,9 @@ class DifferentialDiff extends DifferentialDAO { protected $branch; protected $parentRevisionID; - protected $arcanistProject; + protected $arcanistProjectPHID; protected $creationMethod; + protected $repositoryUUID; protected $description; diff --git a/src/applications/herald/adapter/differential/HeraldDifferentialRevisionAdapter.php b/src/applications/herald/adapter/differential/HeraldDifferentialRevisionAdapter.php index 484b0ec2dd..318c9a5dbd 100644 --- a/src/applications/herald/adapter/differential/HeraldDifferentialRevisionAdapter.php +++ b/src/applications/herald/adapter/differential/HeraldDifferentialRevisionAdapter.php @@ -19,8 +19,7 @@ class HeraldDifferentialRevisionAdapter extends HeraldObjectAdapter { protected $revision; - protected $changesets; - protected $diff = null; + protected $diff; protected $explicitCCs; protected $explicitReviewers; @@ -30,14 +29,17 @@ class HeraldDifferentialRevisionAdapter extends HeraldObjectAdapter { protected $newCCs = array(); protected $remCCs = array(); - public function __construct(DifferentialRevision $revision) { + protected $repository; + protected $affectedPackages; + protected $changesets; + + public function __construct( + DifferentialRevision $revision, + DifferentialDiff $diff) { + $revision->loadRelationships(); $this->revision = $revision; - } - - public function setDiff(Diff $diff) { $this->diff = $diff; - return $this; } public function setExplicitCCs($explicit_ccs) { @@ -80,47 +82,103 @@ class HeraldDifferentialRevisionAdapter extends HeraldObjectAdapter { return HeraldContentTypeConfig::CONTENT_TYPE_DIFFERENTIAL; } + public function loadRepository() { + if ($this->repository === null) { + $diff = $this->diff; + + $repository = false; + + if ($diff->getRepositoryUUID()) { + $repository = id(new PhabricatorRepository())->loadOneWhere( + 'uuid = %s', + $diff->getRepositoryUUID()); + } + + if (!$repository && $diff->getArcanistProjectPHID()) { + $project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere( + 'phid = %s', + $diff->getArcanistProjectPHID()); + if ($project && $project->getRepositoryID()) { + $repository = id(new PhabricatorRepository())->load( + $project->getRepositoryID()); + } + } + + $this->repository = $repository; + } + return $this->repository; + } + protected function loadChangesets() { - if ($this->changesets) { - return $this->changesets; + if ($this->changesets === null) { + $this->changesets = $this->diff->loadChangesets(); } - $diff = $this->loadDiff(); - $changes = $diff->getChangesets(); - return ($this->changesets = $changes); + return $this->changesets; } - protected function loadDiff() { - if ($this->diff === null) { - $this->diff = $this->revision->getActiveDiff(); + protected function loadAffectedPaths() { + $changesets = $this->loadChangesets(); + + $paths = array(); + foreach ($changesets as $changeset) { + $paths[] = $this->getAbsoluteRepositoryPathForChangeset($changeset); } - return $this->diff; + return $paths; } - protected function getContentDictionary() { - $changes = $this->loadChangesets(); + protected function getAbsoluteRepositoryPathForChangeset( + DifferentialChangeset $changeset) { + + $repository = $this->loadRepository(); + if (!$repository) { + return '/'.ltrim($changeset->getFilename(), '/'); + } + + $diff = $this->diff; + + return $changeset->getAbsoluteRepositoryPath($diff, $repository); + } + + protected function loadContentDictionary() { + $changesets = $this->loadChangesets(); $hunks = array(); - if ($changes) { - $hunks = id(new DifferentialHunk())->loadAllwhere( + if ($changesets) { + $hunks = id(new DifferentialHunk())->loadAllWhere( 'changesetID in (%Ld)', - mpull($changes, 'getID')); + mpull($changesets, 'getID')); } $dict = array(); $hunks = mgroup($hunks, 'getChangesetID'); - $changes = mpull($changes, null, 'getID'); - foreach ($changes as $id => $change) { - $filename = $change->getFilename(); + $changesets = mpull($changesets, null, 'getID'); + foreach ($changesets as $id => $changeset) { + $path = $this->getAbsoluteRepositoryPathForChangeset($changeset); $content = array(); foreach (idx($hunks, $id, array()) as $hunk) { $content[] = $hunk->makeChanges(); } - $dict[$filename] = implode("\n", $content); + $dict[$path] = implode("\n", $content); } return $dict; } + public function loadAffectedPackages() { + if ($this->affectedPackages === null) { + $this->affectedPackages = array(); + + $repository = $this->loadRepository(); + if ($repository) { + $packages = PhabricatorOwnersPackage::loadAffectedPackages( + $repository, + $this->loadAffectedPaths()); + $this->affectedPackages = $packages; + } + } + return $this->affectedPackages; + } + public function getHeraldField($field) { switch ($field) { case HeraldFieldConfig::FIELD_TITLE: @@ -134,8 +192,7 @@ class HeraldDifferentialRevisionAdapter extends HeraldObjectAdapter { return $this->revision->getAuthorPHID(); break; case HeraldFieldConfig::FIELD_DIFF_FILE: - $changes = $this->loadChangesets(); - return array_values(mpull($changes, 'getFilename')); + return $this->loadAffectedPaths(); case HeraldFieldConfig::FIELD_CC: if (isset($this->explicitCCs)) { return array_keys($this->explicitCCs); @@ -148,31 +205,21 @@ class HeraldDifferentialRevisionAdapter extends HeraldObjectAdapter { } else { return $this->revision->getReviewers(); } -/* TODO case HeraldFieldConfig::FIELD_REPOSITORY: - $id = $this->revision->getRepositoryID(); - if (!$id) { - return null; - } - require_module_lazy('intern/repository'); - $repository = RepositoryRef::getByID($id); + $repository = $this->loadRepository(); if (!$repository) { return null; } - return $repository->getFBID(); -*/ + return $repository->getPHID(); case HeraldFieldConfig::FIELD_DIFF_CONTENT: - return $this->getContentDictionary(); -/* TODO + return $this->loadContentDictionary(); case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE: - return mpull( - DiffOwners::getPackages($this->loadDiff()), - 'getFBID'); -*/ -/* TODO + $packages = $this->loadAffectedPackages(); + return mpull($packages, 'getPHID'); case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE_OWNER: - return DiffOwners::getOwners($this->loadDiff()); -*/ + $packages = $this->loadAffectedPackages(); + $owners = PhabricatorOwnersOwner::loadAllForPackages($packages); + return mpull($owners, 'getUserPHID'); default: throw new Exception("Invalid field '{$field}'."); } diff --git a/src/applications/herald/adapter/differential/__init__.php b/src/applications/herald/adapter/differential/__init__.php index 432d8502fd..38f91094fb 100644 --- a/src/applications/herald/adapter/differential/__init__.php +++ b/src/applications/herald/adapter/differential/__init__.php @@ -13,6 +13,10 @@ phutil_require_module('phabricator', 'applications/herald/config/contenttype'); phutil_require_module('phabricator', 'applications/herald/config/field'); phutil_require_module('phabricator', 'applications/herald/engine/effect'); phutil_require_module('phabricator', 'applications/herald/storage/transcript/apply'); +phutil_require_module('phabricator', 'applications/owners/storage/owner'); +phutil_require_module('phabricator', 'applications/owners/storage/package'); +phutil_require_module('phabricator', 'applications/repository/storage/arcanistproject'); +phutil_require_module('phabricator', 'applications/repository/storage/repository'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/herald/controller/test/HeraldTestConsoleController.php b/src/applications/herald/controller/test/HeraldTestConsoleController.php index 591d89704a..a62395c723 100644 --- a/src/applications/herald/controller/test/HeraldTestConsoleController.php +++ b/src/applications/herald/controller/test/HeraldTestConsoleController.php @@ -69,7 +69,9 @@ class HeraldTestConsoleController extends HeraldController { if (!$errors) { if ($object instanceof DifferentialRevision) { - $adapter = new HeraldDifferentialRevisionAdapter($object); + $adapter = new HeraldDifferentialRevisionAdapter( + $object, + $object->loadActiveDiff()); } else if ($object instanceof PhabricatorRepositoryCommit) { $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( 'commitID = %d', diff --git a/src/applications/repository/controller/arcansistprojectedit/PhabricatorRepositoryArcanistProjectEditController.php b/src/applications/repository/controller/arcansistprojectedit/PhabricatorRepositoryArcanistProjectEditController.php new file mode 100644 index 0000000000..6f961178fb --- /dev/null +++ b/src/applications/repository/controller/arcansistprojectedit/PhabricatorRepositoryArcanistProjectEditController.php @@ -0,0 +1,92 @@ +id = $data['id']; + } + + public function processRequest() { + + $request = $this->getRequest(); + $user = $request->getUser(); + + $project = id(new PhabricatorRepositoryArcanistProject())->load($this->id); + if (!$project) { + return new Aphront404Response(); + } + + $repositories = id(new PhabricatorRepository())->loadAll(); + $repos = array( + 0 => 'None', + ); + foreach ($repositories as $repository) { + $callsign = $repository->getCallsign(); + $name = $repository->getname(); + $repos[$repository->getID()] = "r{$callsign} ({$name})"; + } + + if ($request->isFormPost()) { + $repo_id = $request->getInt('repository', 0); + if (isset($repos[$repo_id])) { + $project->setRepositoryID($repo_id); + $project->save(); + + return id(new AphrontRedirectResponse()) + ->setURI('/repository/'); + } + } + + $form = id(new AphrontFormView()) + ->setUser($user) + ->appendChild( + id(new AphrontFormStaticControl()) + ->setLabel('Name') + ->setValue($project->getName())) + ->appendChild( + id(new AphrontFormStaticControl()) + ->setLabel('PHID') + ->setValue($project->getPHID())) + ->appendChild( + id(new AphrontFormSelectControl()) + ->setLabel('Repository') + ->setOptions($repos) + ->setName('repository') + ->setValue($project->getRepositoryID())) + ->appendChild( + id(new AphrontFormSubmitControl()) + ->addCancelButton('/repository/') + ->setValue('Save')); + + $panel = new AphrontPanelView(); + $panel->setWidth(AphrontPanelView::WIDTH_FORM); + $panel->setHeader('Edit Arcanist Project'); + $panel->appendChild($form); + + return $this->buildStandardPageResponse( + $panel, + array( + 'title' => 'Edit Project', + )); + } + +} diff --git a/src/applications/repository/controller/arcansistprojectedit/__init__.php b/src/applications/repository/controller/arcansistprojectedit/__init__.php new file mode 100644 index 0000000000..473e95a921 --- /dev/null +++ b/src/applications/repository/controller/arcansistprojectedit/__init__.php @@ -0,0 +1,21 @@ +setCreateButton('Create New Repository', '/repository/create/'); $panel->appendChild($table); + $projects = id(new PhabricatorRepositoryArcanistProject())->loadAll(); + + $rows = array(); + foreach ($projects as $project) { + $repo = idx($repos, $project->getRepositoryID()); + if ($repo) { + $repo_name = phutil_escape_html($repo->getName()); + } else { + $repo_name = '-'; + } + + $rows[] = array( + phutil_escape_html($project->getName()), + $repo_name, + phutil_render_tag( + 'a', + array( + 'href' => '/repository/project/'.$project->getID().'/', + 'class' => 'button grey small', + ), + 'Edit'), + ); + } + + $project_table = new AphrontTableView($rows); + $project_table->setHeaders( + array( + 'Project ID', + 'Repository', + '', + )); + $project_table->setColumnClasses( + array( + '', + 'wide', + 'action', + )); + + $project_panel = new AphrontPanelView(); + $project_panel->setHeader('Arcanist Projects'); + $project_panel->appendChild($project_table); + return $this->buildStandardPageResponse( - $panel, + array( + $panel, + $project_panel, + ), array( 'title' => 'Repository List', )); diff --git a/src/applications/repository/controller/list/__init__.php b/src/applications/repository/controller/list/__init__.php index ab241e5d4b..8f06e0887e 100644 --- a/src/applications/repository/controller/list/__init__.php +++ b/src/applications/repository/controller/list/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'applications/repository/constants/repositorytype'); phutil_require_module('phabricator', 'applications/repository/controller/base'); +phutil_require_module('phabricator', 'applications/repository/storage/arcanistproject'); phutil_require_module('phabricator', 'applications/repository/storage/repository'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/layout/panel'); diff --git a/src/applications/repository/storage/arcanistproject/PhabricatorRepositoryArcanistProject.php b/src/applications/repository/storage/arcanistproject/PhabricatorRepositoryArcanistProject.php new file mode 100644 index 0000000000..e1c9523c57 --- /dev/null +++ b/src/applications/repository/storage/arcanistproject/PhabricatorRepositoryArcanistProject.php @@ -0,0 +1,37 @@ + true, + self::CONFIG_TIMESTAMPS => false, + ) + parent::getConfiguration(); + } + + public function generatePHID() { + return PhabricatorPHID::generateNewPHID('APRJ'); + } + +} diff --git a/src/applications/repository/storage/arcanistproject/__init__.php b/src/applications/repository/storage/arcanistproject/__init__.php new file mode 100644 index 0000000000..1503f2ab0d --- /dev/null +++ b/src/applications/repository/storage/arcanistproject/__init__.php @@ -0,0 +1,13 @@ +