2011-03-08 23:29:02 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-03-13 19:18:11 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-03-08 23:29:02 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-20 03:52:14 +01:00
|
|
|
/**
|
|
|
|
* @group diffusion
|
|
|
|
*/
|
2012-03-13 19:18:11 +01:00
|
|
|
final class DiffusionGitRequest extends DiffusionRequest {
|
2011-03-08 23:29:02 +01:00
|
|
|
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-20 03:52:14 +01:00
|
|
|
protected function getSupportsBranches() {
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-08 23:29:02 +01:00
|
|
|
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-20 03:52:14 +01:00
|
|
|
protected function didInitialize() {
|
2011-03-08 23:29:02 +01:00
|
|
|
if ($this->repository) {
|
2011-11-10 00:29:41 +01:00
|
|
|
$repository = $this->repository;
|
2011-03-08 23:29:02 +01:00
|
|
|
|
|
|
|
// 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();
|
2011-03-09 02:31:44 +01:00
|
|
|
|
2011-04-02 02:11:05 +02:00
|
|
|
// 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.
|
2011-11-10 00:29:41 +01:00
|
|
|
list($this->stableCommitName) = $repository->execxLocalCommand(
|
2011-12-22 21:24:12 +01:00
|
|
|
'rev-parse --verify %s/%s',
|
|
|
|
DiffusionBranchInformation::DEFAULT_GIT_REMOTE,
|
2011-03-08 23:29:02 +01:00
|
|
|
$branch);
|
|
|
|
|
|
|
|
if ($this->commit) {
|
2011-11-10 00:29:41 +01:00
|
|
|
list($commit) = $repository->execxLocalCommand(
|
|
|
|
'rev-parse --verify %s',
|
2011-03-08 23:29:02 +01:00
|
|
|
$this->commit);
|
2011-03-14 00:19:39 +01:00
|
|
|
|
|
|
|
// Beyond verifying them, expand commit short forms to full 40-character
|
2011-11-17 20:44:28 +01:00
|
|
|
// hashes.
|
2011-03-14 00:19:39 +01:00
|
|
|
$this->commit = trim($commit);
|
|
|
|
|
2011-05-18 16:44:53 +02:00
|
|
|
// If we have a commit, overwrite the branch commit with the more
|
|
|
|
// specific commit.
|
|
|
|
$this->stableCommitName = $this->commit;
|
|
|
|
|
2011-03-31 07:08:41 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
TODO: Unclear if this is actually a good idea or not; it breaks commit views
|
|
|
|
at the very least.
|
|
|
|
|
2011-11-10 00:29:41 +01:00
|
|
|
list($contains) = $repository->execxLocalCommand(
|
|
|
|
'branch --contains %s',
|
2011-03-08 23:29:02 +01:00
|
|
|
$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!");
|
|
|
|
}
|
2011-03-31 07:08:41 +02:00
|
|
|
*/
|
|
|
|
|
2011-03-08 23:29:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBranch() {
|
|
|
|
if ($this->branch) {
|
|
|
|
return $this->branch;
|
|
|
|
}
|
|
|
|
if ($this->repository) {
|
2011-12-22 21:24:12 +01:00
|
|
|
return $this->repository->getDetail('default-branch', 'master');
|
2011-03-08 23:29:02 +01:00
|
|
|
}
|
|
|
|
throw new Exception("Unable to determine branch!");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommit() {
|
|
|
|
if ($this->commit) {
|
|
|
|
return $this->commit;
|
|
|
|
}
|
2011-12-22 21:24:12 +01:00
|
|
|
$remote = DiffusionBranchInformation::DEFAULT_GIT_REMOTE;
|
|
|
|
return $remote.'/'.$this->getBranch();
|
2011-03-08 23:29:02 +01:00
|
|
|
}
|
|
|
|
|
2011-05-18 16:44:53 +02:00
|
|
|
public function getStableCommitName() {
|
|
|
|
return substr($this->stableCommitName, 0, 16);
|
|
|
|
}
|
|
|
|
|
2011-03-08 23:29:02 +01:00
|
|
|
}
|