Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/diffusion/controller/change/DiffusionChangeController.php b/src/applications/diffusion/controller/change/DiffusionChangeController.php
index 5d73afcab7..1f9a836eb5 100644
--- a/src/applications/diffusion/controller/change/DiffusionChangeController.php
+++ b/src/applications/diffusion/controller/change/DiffusionChangeController.php
@@ -1,60 +1,59 @@
<?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 DiffusionChangeController extends DiffusionController {
public function processRequest() {
$drequest = $this->diffusionRequest;
$content = array();
- $content[] = $this->buildCrumbs(
- array(
- 'branch' => true,
- 'path' => true,
- 'view' => 'change',
- ));
-
-
$diff_query = DiffusionDiffQuery::newFromDiffusionRequest($drequest);
$changeset = $diff_query->loadChangeset();
$changeset_view = new DifferentialChangesetListView();
$changeset_view->setChangesets(array($changeset));
$changeset_view->setRenderURI(
'/diffusion/'.$drequest->getRepository()->getCallsign().'/diff/');
+ $content[] = $this->buildCrumbs(
+ array(
+ 'branch' => true,
+ 'path' => true,
+ 'view' => 'change',
+ ));
+
// TODO: This is pretty awkward, unify the CSS between Diffusion and
// Differential better.
require_celerity_resource('differential-core-view-css');
$content[] =
'<div class="differential-primary-pane">'.
$changeset_view->render().
'</div>';
$nav = $this->buildSideNav('change', true);
$nav->appendChild($content);
return $this->buildStandardPageResponse(
$nav,
array(
'title' => 'Change',
));
}
}
diff --git a/src/applications/diffusion/query/diff/base/DiffusionDiffQuery.php b/src/applications/diffusion/query/diff/base/DiffusionDiffQuery.php
index f9c858f98b..275a08e915 100644
--- a/src/applications/diffusion/query/diff/base/DiffusionDiffQuery.php
+++ b/src/applications/diffusion/query/diff/base/DiffusionDiffQuery.php
@@ -1,60 +1,74 @@
<?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.
*/
abstract class DiffusionDiffQuery {
private $request;
final private function __construct() {
// <private>
}
final public static function newFromDiffusionRequest(
DiffusionRequest $request) {
$repository = $request->getRepository();
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$class = 'DiffusionGitDiffQuery';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$class = 'DiffusionSvnDiffQuery';
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 loadChangeset() {
return $this->executeQuery();
}
abstract protected function executeQuery();
+
+ protected function getEffectiveCommit() {
+ $drequest = $this->getRequest();
+
+ $modified_query = DiffusionLastModifiedQuery::newFromDiffusionRequest(
+ $drequest);
+ list($commit) = $modified_query->loadLastModification();
+ if (!$commit) {
+ // TODO: Improve error messages here.
+ return null;
+ }
+ return $commit->getCommitIdentifier();
+ }
+
}
diff --git a/src/applications/diffusion/query/diff/base/__init__.php b/src/applications/diffusion/query/diff/base/__init__.php
index 500696c5a5..d6ecf69496 100644
--- a/src/applications/diffusion/query/diff/base/__init__.php
+++ b/src/applications/diffusion/query/diff/base/__init__.php
@@ -1,14 +1,15 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
+phutil_require_module('phabricator', 'applications/diffusion/query/lastmodified/base');
phutil_require_module('phabricator', 'applications/repository/constants/repositorytype');
phutil_require_module('phutil', 'symbols');
phutil_require_source('DiffusionDiffQuery.php');
diff --git a/src/applications/diffusion/query/diff/git/DiffusionGitDiffQuery.php b/src/applications/diffusion/query/diff/git/DiffusionGitDiffQuery.php
index 38099827bd..53fbf740b7 100644
--- a/src/applications/diffusion/query/diff/git/DiffusionGitDiffQuery.php
+++ b/src/applications/diffusion/query/diff/git/DiffusionGitDiffQuery.php
@@ -1,61 +1,72 @@
<?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.
*/
final class DiffusionGitDiffQuery extends DiffusionDiffQuery {
protected function executeQuery() {
$drequest = $this->getRequest();
$repository = $drequest->getRepository();
+ if (!$drequest->getRawCommit()) {
+ $effective_commit = $this->getEffectiveCommit();
+ if (!$effective_commit) {
+ return null;
+ }
+ // TODO: This side effect is kind of skethcy.
+ $drequest->setCommit($effective_commit);
+ } else {
+ $effective_commit = $drequest->getCommit();
+ }
+
$options = array(
'-M',
'-C',
'--no-ext-diff',
'--no-color',
'--src-prefix=a/',
'--dst-prefix=b/',
'-U65535',
);
$options = implode(' ', $options);
list($raw_diff) = execx(
"(cd %s && git diff {$options} %s^ %s -- %s)",
$repository->getDetail('local-path'),
- $drequest->getCommit(),
- $drequest->getCommit(),
+ $effective_commit,
+ $effective_commit,
$drequest->getPath());
$parser = new ArcanistDiffParser();
$parser->setDetectBinaryFiles(true);
$changes = $parser->parseDiff($raw_diff);
$diff = DifferentialDiff::newFromRawChanges($changes);
$changesets = $diff->getChangesets();
$changeset = reset($changesets);
$id =
$drequest->getBranchURIComponent($drequest->getBranch()).
$drequest->getPath().';'.
$drequest->getCommit();
$changeset->setID($id);
return $changeset;
}
}
diff --git a/src/applications/diffusion/query/diff/svn/DiffusionSvnDiffQuery.php b/src/applications/diffusion/query/diff/svn/DiffusionSvnDiffQuery.php
index c8e7916148..8dca68469e 100644
--- a/src/applications/diffusion/query/diff/svn/DiffusionSvnDiffQuery.php
+++ b/src/applications/diffusion/query/diff/svn/DiffusionSvnDiffQuery.php
@@ -1,141 +1,150 @@
<?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.
*/
final class DiffusionSvnDiffQuery extends DiffusionDiffQuery {
protected function executeQuery() {
$drequest = $this->getRequest();
+ if (!$drequest->getRawCommit()) {
+ $effective_commit = $this->getEffectiveCommit();
+ if (!$effective_commit) {
+ return null;
+ }
+ // TODO: Sketchy side effect.
+ $drequest->setCommit($effective_commit);
+ }
+
$path_change_query = DiffusionPathChangeQuery::newFromDiffusionRequest(
$drequest);
$path_changes = $path_change_query->loadChanges();
$path = null;
foreach ($path_changes as $change) {
if ($change->getPath() == $drequest->getPath()) {
$path = $change;
}
}
if (!$path) {
return null;
}
$change_type = $path->getChangeType();
switch ($change_type) {
case DifferentialChangeType::TYPE_MULTICOPY:
case DifferentialChangeType::TYPE_DELETE:
if ($path->getTargetPath()) {
$old = array(
$path->getTargetPath(),
$path->getTargetCommitIdentifier());
} else {
$old = array($path->getPath(), $path->getCommitIdentifier() - 1);
}
$old_name = $path->getPath();
$new_name = '';
$new = null;
break;
case DifferentialChangeType::TYPE_ADD:
$old = null;
$new = array($path->getPath(), $path->getCommitIdentifier());
$old_name = '';
$new_name = $path->getPath();
break;
case DifferentialChangeType::TYPE_MOVE_HERE:
case DifferentialChangeType::TYPE_COPY_HERE:
$old = array(
$path->getTargetPath(),
$path->getTargetCommitIdentifier());
$new = array($path->getPath(), $path->getCommitIdentifier());
$old_name = $path->getTargetPath();
$new_name = $path->getPath();
break;
default:
$old = array($path->getPath(), $path->getCommitIdentifier() - 1);
$new = array($path->getPath(), $path->getCommitIdentifier());
$old_name = $path->getPath();
$new_name = $path->getPath();
break;
}
$futures = array(
'old' => $this->buildContentFuture($old),
'new' => $this->buildContentFuture($new),
);
$futures = array_filter($futures);
foreach (Futures($futures) as $key => $future) {
$futures[$key] = $future->resolvex();
}
$old_data = idx($futures, 'old', '');
$new_data = idx($futures, 'new', '');
$old_tmp = new TempFile();
$new_tmp = new TempFile();
Filesystem::writeFile($old_tmp, $old_data);
Filesystem::writeFile($new_tmp, $new_data);
list($err, $raw_diff) = exec_manual(
'diff -L %s -L %s -U65535 %s %s',
nonempty($old_name, '/dev/universe').' 9999-99-99',
nonempty($new_name, '/dev/universe').' 9999-99-99',
$old_tmp,
$new_tmp);
$parser = new ArcanistDiffParser();
$parser->setDetectBinaryFiles(true);
$arcanist_changes = DiffusionPathChange::convertToArcanistChanges(
$path_changes);
$parser->setChanges($arcanist_changes);
$parser->forcePath($path->getPath());
$changes = $parser->parseDiff($raw_diff);
$change = $changes[$path->getPath()];
$diff = DifferentialDiff::newFromRawChanges(array($change));
$changesets = $diff->getChangesets();
$changeset = reset($changesets);
$reference = $drequest->getPath().';'.$drequest->getCommit();
$changeset->setRenderingReference($reference);
return $changeset;
}
private function buildContentFuture($spec) {
if (!$spec) {
return null;
}
$drequest = $this->getRequest();
$repository = $drequest->getRepository();
list($ref, $rev) = $spec;
return new ExecFuture(
'svn --non-interactive cat %s%s@%d',
$repository->getDetail('remote-uri'),
$ref,
$rev);
}
}
diff --git a/src/applications/diffusion/request/base/DiffusionRequest.php b/src/applications/diffusion/request/base/DiffusionRequest.php
index c4b89144be..378dd9e7ed 100644
--- a/src/applications/diffusion/request/base/DiffusionRequest.php
+++ b/src/applications/diffusion/request/base/DiffusionRequest.php
@@ -1,151 +1,156 @@
<?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;
protected $repositoryCommit;
protected $repositoryCommitData;
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;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$class = 'DiffusionSvnRequest';
break;
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');
$object->initializeFromAphrontRequestDictionary();
return $object;
}
protected function initializeFromAphrontRequestDictionary() {
}
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;
}
public function getUriPath() {
return '/diffusion/'.$this->getCallsign().'/browse/'.$this->path;
}
public function getLine() {
return $this->line;
}
public function getCommit() {
return $this->commit;
}
public function getBranch() {
return $this->branch;
}
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());
if (!$data) {
$data = new PhabricatorRepositoryCommitData();
$data->setCommitMessage('(This commit has not fully parsed yet.)');
}
$this->repositoryCommitData = $data;
}
return $this->repositoryCommitData;
}
final public function getRawCommit() {
return $this->commit;
}
+ public function setCommit($commit) {
+ $this->commit = $commit;
+ return $this;
+ }
+
public function getCommitURIComponent($commit) {
return $commit;
}
public function getBranchURIComponent($branch) {
return $branch;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Wed, Apr 30, 2:10 AM (1 d, 5 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
108513
Default Alt Text
(16 KB)

Event Timeline