2011-04-04 04:20:47 +02:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DiffusionPathCompleteController extends DiffusionController {
|
2011-04-04 04:20:47 +02:00
|
|
|
|
2015-01-09 22:29:08 +01:00
|
|
|
protected function shouldLoadDiffusionRequest() {
|
|
|
|
return false;
|
2011-04-04 04:20:47 +02:00
|
|
|
}
|
|
|
|
|
2015-01-09 22:29:08 +01:00
|
|
|
protected function processDiffusionRequest(AphrontRequest $request) {
|
2011-04-04 04:20:47 +02:00
|
|
|
|
|
|
|
$repository_phid = $request->getStr('repositoryPHID');
|
2013-09-26 01:54:48 +02:00
|
|
|
$repository = id(new PhabricatorRepositoryQuery())
|
|
|
|
->setViewer($request->getUser())
|
|
|
|
->withPHIDs(array($repository_phid))
|
|
|
|
->executeOne();
|
2011-04-04 04:20:47 +02:00
|
|
|
if (!$repository) {
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$query_path = $request->getStr('q');
|
|
|
|
if (preg_match('@/$@', $query_path)) {
|
|
|
|
$query_dir = $query_path;
|
|
|
|
} else {
|
2012-07-16 21:44:14 +02:00
|
|
|
$query_dir = dirname($query_path).'/';
|
2011-04-04 04:20:47 +02:00
|
|
|
}
|
2012-07-16 21:44:14 +02:00
|
|
|
$query_dir = ltrim($query_dir, '/');
|
2011-04-04 04:20:47 +02: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
|
|
|
$drequest = DiffusionRequest::newFromDictionary(
|
2011-04-04 04:20:47 +02:00
|
|
|
array(
|
2013-05-15 00:32:19 +02:00
|
|
|
'user' => $request->getUser(),
|
|
|
|
'repository' => $repository,
|
|
|
|
'path' => $query_dir,
|
2011-04-04 04:20:47 +02:00
|
|
|
));
|
Diffusion - move DiffusionBrowseQuery => Conduit
Summary: see title. Ref T2784.
Test Plan:
In diffusion, for each of SVN, Mercurial, and Git, I loaded up /diffusion/CALLSIGN/. I verified the README was displayed and things looked good. Next I clicked on "browse" on the top-most commit and verified things looked correct. Also clicked through to a file for a good measure and things looked good.
In owners, for each of SVN, Mercurial, and Git, I played around with the path typeahead / validator. It worked correctly!
Reviewers: epriestley
Reviewed By: epriestley
CC: chad, aran, Korvin
Maniphest Tasks: T2784
Differential Revision: https://secure.phabricator.com/D5883
2013-05-10 20:02:58 +02:00
|
|
|
$this->setDiffusionRequest($drequest);
|
|
|
|
|
|
|
|
$browse_results = DiffusionBrowseResultSet::newFromConduit(
|
|
|
|
$this->callConduitWithDiffusionRequest(
|
|
|
|
'diffusion.browsequery',
|
|
|
|
array(
|
|
|
|
'path' => $drequest->getPath(),
|
|
|
|
'commit' => $drequest->getCommit(),
|
|
|
|
)));
|
|
|
|
$paths = $browse_results->getPaths();
|
2011-04-04 04:20:47 +02:00
|
|
|
|
|
|
|
$output = array();
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
$full_path = $query_dir.$path->getPath();
|
|
|
|
if ($path->getFileType() == DifferentialChangeType::FILE_DIRECTORY) {
|
|
|
|
$full_path .= '/';
|
|
|
|
}
|
|
|
|
$output[] = array('/'.$full_path, null, substr(md5($full_path), 0, 7));
|
|
|
|
}
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())->setContent($output);
|
|
|
|
}
|
|
|
|
}
|