2011-03-08 23:29:02 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DiffusionRequest {
|
|
|
|
|
|
|
|
protected $callsign;
|
|
|
|
protected $path;
|
|
|
|
protected $line;
|
|
|
|
protected $commit;
|
|
|
|
protected $branch;
|
|
|
|
|
|
|
|
protected $repository;
|
2011-03-14 04:12:17 +01:00
|
|
|
protected $repositoryCommit;
|
|
|
|
protected $repositoryCommitData;
|
2011-05-18 16:44:53 +02:00
|
|
|
protected $stableCommitName;
|
2011-03-08 23:29:02 +01:00
|
|
|
|
|
|
|
final private function __construct() {
|
|
|
|
// <private>
|
|
|
|
}
|
|
|
|
|
|
|
|
final public static function newFromAphrontRequestDictionary(array $data) {
|
|
|
|
|
|
|
|
$vcs = null;
|
|
|
|
$repository = null;
|
|
|
|
$callsign = idx($data, 'callsign');
|
|
|
|
if ($callsign) {
|
|
|
|
$repository = id(new PhabricatorRepository())->loadOneWhere(
|
|
|
|
'callsign = %s',
|
|
|
|
$callsign);
|
|
|
|
if (!$repository) {
|
|
|
|
throw new Exception("No such repository '{$callsign}'.");
|
|
|
|
}
|
|
|
|
$vcs = $repository->getVersionControlSystem();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($vcs) {
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
|
|
|
$class = 'DiffusionGitRequest';
|
|
|
|
break;
|
2011-03-23 03:34:47 +01:00
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
|
|
|
$class = 'DiffusionSvnRequest';
|
|
|
|
break;
|
Basic support for Mercurial in Diffusion
Summary: Change import script plus almost all the view stuff. Still some rough
edges but this seems to mostly work. Blame is currently unsupported but I think
everything else works properly.
Test Plan:
Imported the hg repository itself. It doesn't immediately seem completely
broken. Here are some screens:
https://secure.phabricator.com/file/view/PHID-FILE-1438b71cc7c4a2eb4569/
https://secure.phabricator.com/file/view/PHID-FILE-3cec4f72f39e7de2d041/
https://secure.phabricator.com/file/view/PHID-FILE-2ea4883f160e8e5098f9/
https://secure.phabricator.com/file/view/PHID-FILE-35f751a36ebf65399ade/
All the parsers were able to churn through it without errors.
Ran the new "reparse.php" script in various one-commit and repository modes.
Browsed/imported some git repos for good measure.
NOTE: The hg repository is only 15,000 commits and around 1,000 files.
Performance is okay but hg doesn't provide performant, native APIs to get some
data efficiently so we have to do some dumb stuff. If some of these interfaces
are cripplingly slow or whatever, let me know and we can start bundling some
Mercurial extensions with Arcanist.
Reviewers: Makinde, jungejason, nh, tuomaspelkonen, aran
Reviewed By: Makinde
CC: aran, Makinde, epriestley
Differential Revision: 960
2011-09-26 20:07:38 +02:00
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
|
|
|
$class = 'DiffusionMercurialRequest';
|
|
|
|
break;
|
2011-03-08 23:29:02 +01:00
|
|
|
default:
|
|
|
|
$class = 'DiffusionRequest';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$object = new $class();
|
|
|
|
|
|
|
|
$object->callsign = $callsign;
|
|
|
|
$object->repository = $repository;
|
|
|
|
$object->line = idx($data, 'line');
|
|
|
|
$object->commit = idx($data, 'commit');
|
|
|
|
$object->path = idx($data, 'path');
|
|
|
|
|
2011-04-04 04:20:47 +02:00
|
|
|
$object->initializeFromAphrontRequestDictionary($data);
|
2011-03-08 23:29:02 +01:00
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
|
2011-04-04 04:20:47 +02:00
|
|
|
protected function initializeFromAphrontRequestDictionary(array $data) {
|
2011-03-08 23:29:02 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function parsePath($path) {
|
|
|
|
$this->path = $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRepository() {
|
|
|
|
return $this->repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCallsign() {
|
|
|
|
return $this->callsign;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPath() {
|
|
|
|
return $this->path;
|
|
|
|
}
|
|
|
|
|
2011-03-26 08:14:04 +01:00
|
|
|
public function getUriPath() {
|
|
|
|
return '/diffusion/'.$this->getCallsign().'/browse/'.$this->path;
|
|
|
|
}
|
|
|
|
|
2011-03-08 23:29:02 +01:00
|
|
|
public function getLine() {
|
|
|
|
return $this->line;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommit() {
|
|
|
|
return $this->commit;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBranch() {
|
|
|
|
return $this->branch;
|
|
|
|
}
|
|
|
|
|
2011-03-14 04:12:17 +01:00
|
|
|
public function loadCommit() {
|
|
|
|
if (empty($this->repositoryCommit)) {
|
|
|
|
$repository = $this->getRepository();
|
|
|
|
|
|
|
|
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
|
|
|
|
'repositoryID = %d AND commitIdentifier = %s',
|
|
|
|
$repository->getID(),
|
|
|
|
$this->getCommit());
|
|
|
|
$this->repositoryCommit = $commit;
|
|
|
|
}
|
|
|
|
return $this->repositoryCommit;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function loadCommitData() {
|
|
|
|
if (empty($this->repositoryCommitData)) {
|
|
|
|
$commit = $this->loadCommit();
|
|
|
|
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
|
|
|
|
'commitID = %d',
|
|
|
|
$commit->getID());
|
2011-03-19 22:38:50 +01:00
|
|
|
if (!$data) {
|
|
|
|
$data = new PhabricatorRepositoryCommitData();
|
|
|
|
$data->setCommitMessage('(This commit has not fully parsed yet.)');
|
|
|
|
}
|
2011-03-14 04:12:17 +01:00
|
|
|
$this->repositoryCommitData = $data;
|
|
|
|
}
|
|
|
|
return $this->repositoryCommitData;
|
|
|
|
}
|
|
|
|
|
2011-05-18 16:44:53 +02:00
|
|
|
/**
|
|
|
|
* Retrieve a stable, permanent commit name. This returns a non-symbolic
|
|
|
|
* identifier for the current commit: e.g., a specific commit hash in git
|
|
|
|
* (NOT a symbolic name like "origin/master") or a specific revision number
|
|
|
|
* in SVN (NOT a symbolic name like "HEAD").
|
|
|
|
*
|
|
|
|
* @return string Stable commit name, like a git hash or SVN revision. Not
|
|
|
|
* a symbolic commit reference.
|
|
|
|
*/
|
|
|
|
public function getStableCommitName() {
|
|
|
|
return $this->stableCommitName;
|
|
|
|
}
|
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
final public function getRawCommit() {
|
|
|
|
return $this->commit;
|
|
|
|
}
|
|
|
|
|
2011-04-03 02:11:51 +02:00
|
|
|
public function setCommit($commit) {
|
|
|
|
$this->commit = $commit;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
public function getCommitURIComponent($commit) {
|
|
|
|
return $commit;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBranchURIComponent($branch) {
|
|
|
|
return $branch;
|
|
|
|
}
|
|
|
|
|
2011-03-08 23:29:02 +01:00
|
|
|
}
|