Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/diffusion/request/git/DiffusionGitRequest.php b/src/applications/diffusion/request/git/DiffusionGitRequest.php
index 82b244ea38..2232cb1996 100644
--- a/src/applications/diffusion/request/git/DiffusionGitRequest.php
+++ b/src/applications/diffusion/request/git/DiffusionGitRequest.php
@@ -1,139 +1,139 @@
<?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 DiffusionGitRequest extends DiffusionRequest {
protected function initializeFromAphrontRequestDictionary(array $data) {
parent::initializeFromAphrontRequestDictionary($data);
$path = $this->path;
$parts = explode('/', $path);
$branch = array_shift($parts);
if ($branch != ':') {
$this->branch = $this->decodeBranchName($branch);
}
foreach ($parts as $key => $part) {
// Prevent any hyjinx since we're ultimately shipping this to the
// filesystem under a lot of git workflows.
if ($part == '..') {
unset($parts[$key]);
}
}
$this->path = implode('/', $parts);
if ($this->repository) {
$repository = $this->repository;
// TODO: This is not terribly efficient and does not produce terribly
// good error messages, but it seems better to put error handling code
// here than to try to do it in every query.
$branch = $this->getBranch();
// TODO: Here, particularly, we should give the user a specific error
// message to indicate whether they've typed in some bogus branch and/or
// followed a bad link, or misconfigured the default branch in the
// Repository tool.
list($this->stableCommitName) = $repository->execxLocalCommand(
'rev-parse --verify %s',
$branch);
if ($this->commit) {
list($commit) = $repository->execxLocalCommand(
'rev-parse --verify %s',
$this->commit);
// Beyond verifying them, expand commit short forms to full 40-character
- // sha1s.
+ // hashes.
$this->commit = trim($commit);
// If we have a commit, overwrite the branch commit with the more
// specific commit.
$this->stableCommitName = $this->commit;
/*
TODO: Unclear if this is actually a good idea or not; it breaks commit views
at the very least.
list($contains) = $repository->execxLocalCommand(
'branch --contains %s',
$this->commit);
$contains = array_filter(explode("\n", $contains));
$found = false;
foreach ($contains as $containing_branch) {
$containing_branch = trim($containing_branch, "* \n");
if ($containing_branch == $branch) {
$found = true;
break;
}
}
if (!$found) {
throw new Exception(
"Commit does not exist on this branch!");
}
*/
}
}
}
public function getBranch() {
if ($this->branch) {
return $this->branch;
}
if ($this->repository) {
return $this->repository->getDetail('default-branch', 'origin/master');
}
throw new Exception("Unable to determine branch!");
}
public function getUriPath() {
return '/diffusion/'.$this->getCallsign().'/browse/'.
$this->getBranchURIComponent($this->branch).$this->path;
}
public function getCommit() {
if ($this->commit) {
return $this->commit;
}
return $this->getBranch();
}
public function getStableCommitName() {
return substr($this->stableCommitName, 0, 16);
}
public function getBranchURIComponent($branch) {
return $this->encodeBranchName($branch).'/';
}
private function decodeBranchName($branch) {
return str_replace(':', '/', $branch);
}
private function encodeBranchName($branch) {
return str_replace('/', ':', $branch);
}
}
diff --git a/src/storage/connection/isolated/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php b/src/storage/connection/isolated/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php
index dbed341c2f..e92aef2150 100644
--- a/src/storage/connection/isolated/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php
+++ b/src/storage/connection/isolated/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php
@@ -1,74 +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.
*/
class AphrontIsolatedDatabaseConnectionTestCase
extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
// We disable this here because this test is unique (it is testing that
// isolation actually occurs) and must establish a live connection to the
// database to verify that.
self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK => false,
);
}
public function testIsolation() {
$conn = $this->newIsolatedConnection();
- $test_phid = 'PHID-TEST-'.sha1(mt_rand());
+ $test_phid = 'PHID-TEST-'.Filesystem::readRandomCharacters(20);
queryfx(
$conn,
'INSERT INTO phabricator_phid.phid (phid) VALUES (%s)',
$test_phid);
try {
$real_phid = id(new PhabricatorPHID())->loadOneWhere(
'phid = %s',
$test_phid);
$this->assertEqual(
null,
$real_phid,
'Expect fake PHID to exist only in isolation.');
} catch (AphrontQueryConnectionException $ex) {
// If we can't connect to the database, conclude that the isolated
// connection actually is isolated. Philosophically, this perhaps allows
// us to claim this test does not depend on the database?
}
}
public function testInsertGeneratesID() {
$conn = $this->newIsolatedConnection();
queryfx($conn, 'INSERT');
$id1 = $conn->getInsertID();
queryfx($conn, 'INSERT');
$id2 = $conn->getInsertID();
$this->assertEqual(true, (bool)$id1, 'ID1 exists.');
$this->assertEqual(true, (bool)$id2, 'ID2 exists.');
$this->assertEqual(true, $id1 != $id2, 'IDs are distinct.');
}
private function newIsolatedConnection() {
$config = array();
return new AphrontIsolatedDatabaseConnection($config);
}
}
diff --git a/src/storage/connection/isolated/__tests__/__init__.php b/src/storage/connection/isolated/__tests__/__init__.php
index ce36833299..01b64ad096 100644
--- a/src/storage/connection/isolated/__tests__/__init__.php
+++ b/src/storage/connection/isolated/__tests__/__init__.php
@@ -1,17 +1,18 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/phid/storage/phid');
phutil_require_module('phabricator', 'infrastructure/testing/testcase');
phutil_require_module('phabricator', 'storage/connection/isolated');
phutil_require_module('phabricator', 'storage/queryfx');
+phutil_require_module('phutil', 'filesystem');
phutil_require_module('phutil', 'utils');
phutil_require_source('AphrontIsolatedDatabaseConnectionTestCase.php');

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jul 2, 10:34 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
164859
Default Alt Text
(8 KB)

Event Timeline