| 
									
										
										
										
											2011-05-19 15:36:17 -07:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-04 12:03:36 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @group conduit | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-03-13 11:18:11 -07:00
										 |  |  | final class ConduitAPI_diffusion_getrecentcommitsbypath_Method | 
					
						
							| 
									
										
										
										
											2013-03-13 07:09:05 -07:00
										 |  |  |   extends ConduitAPI_diffusion_Method { | 
					
						
							| 
									
										
										
										
											2011-05-19 15:36:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-22 14:38:01 -07:00
										 |  |  |   const DEFAULT_LIMIT = 10; | 
					
						
							| 
									
										
										
										
											2011-05-19 15:36:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   public function getMethodDescription() { | 
					
						
							|  |  |  |     return "Get commit identifiers for recent commits affecting a given path."; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public function defineParamTypes() { | 
					
						
							|  |  |  |     return array( | 
					
						
							|  |  |  |       'callsign' => 'required string', | 
					
						
							|  |  |  |       'path' => 'required string', | 
					
						
							| 
									
										
										
										
											2012-06-22 14:38:01 -07:00
										 |  |  |       'limit' => 'optional int', | 
					
						
							| 
									
										
										
										
											2011-05-19 15:36:17 -07:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public function defineReturnType() { | 
					
						
							|  |  |  |     return 'nonempty list<string>'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public function defineErrorTypes() { | 
					
						
							|  |  |  |     return array( | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   protected function execute(ConduitAPIRequest $request) { | 
					
						
							| 
									
										
											  
											
												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-19 19:52:14 -07:00
										 |  |  |     $drequest = DiffusionRequest::newFromDictionary( | 
					
						
							|  |  |  |       array( | 
					
						
							|  |  |  |         'callsign'  => $request->getValue('callsign'), | 
					
						
							|  |  |  |         'path'      => $request->getValue('path'), | 
					
						
							|  |  |  |       )); | 
					
						
							| 
									
										
										
										
											2011-05-19 15:36:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-22 14:38:01 -07:00
										 |  |  |     $limit = nonempty( | 
					
						
							|  |  |  |       $request->getValue('limit'), | 
					
						
							| 
									
										
										
										
											2013-02-19 13:33:10 -08:00
										 |  |  |       self::DEFAULT_LIMIT); | 
					
						
							| 
									
										
										
										
											2012-06-22 14:38:01 -07: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-19 19:52:14 -07:00
										 |  |  |     $history = DiffusionHistoryQuery::newFromDiffusionRequest($drequest) | 
					
						
							| 
									
										
										
										
											2012-06-22 14:38:01 -07:00
										 |  |  |     ->setLimit($limit) | 
					
						
							| 
									
										
										
										
											2011-05-24 16:02:53 -07:00
										 |  |  |     ->needDirectChanges(true) | 
					
						
							|  |  |  |     ->needChildChanges(true) | 
					
						
							| 
									
										
										
										
											2011-05-19 15:36:17 -07:00
										 |  |  |     ->loadHistory(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $raw_commit_identifiers = mpull($history, 'getCommitIdentifier'); | 
					
						
							|  |  |  |     $result = array(); | 
					
						
							|  |  |  |     foreach ($raw_commit_identifiers as $id) { | 
					
						
							|  |  |  |       $result[] = 'r'.$request->getValue('callsign').$id; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return $result; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |