@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Differential - refine selecting a repository diff --> revision workflow

Summary: Fixes T6200. Ref T6237. When creating a diff from the web view, allow the user to select the repository at that time. When viewing a diff that has no associated revision and then creating a revision, pass along the repository phid to the create revision controller. Within the create revision controller, default the repository selector to this repository phid. Finally, in the editor, stop aggressively resetting the repository phid for every TYPE_UPDATE; rather, do so if its not a new object -- the diff should reign supreme in that case -- or if there's no repository -- let the diff be the guide.

Test Plan:
- made a diff with an associated repo, made a revision from the diff, saw the associated repo and it stuck on save!
- made a diff with an associated repo, made a revision from the diff but changed the repo and it stuck on save!
- made a diff with an associated repo, made a revision from the diff but changed the repo to nothing and it stuck on save!

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T6237, T6200

Differential Revision: https://secure.phabricator.com/D10872

+67 -8
+1
src/applications/differential/conduit/DifferentialCreateRawDiffConduitAPIMethod.php
··· 61 61 id(new DifferentialDiffEditor()) 62 62 ->setActor($viewer) 63 63 ->setContentSourceFromConduitRequest($request) 64 + ->setLookupRepository(false) // respect user choice 64 65 ->applyTransactions($diff, $xactions); 65 66 66 67 return $this->buildDiffInfoDictionary($diff);
+20 -1
src/applications/differential/controller/DifferentialDiffCreateController.php
··· 7 7 $request = $this->getRequest(); 8 8 9 9 $diff = null; 10 + $repository_phid = null; 11 + $repository_value = array(); 10 12 $errors = array(); 11 13 $e_diff = null; 12 14 $e_file = null; 13 15 $validation_exception = null; 14 16 if ($request->isFormPost()) { 15 17 18 + $repository_tokenizer = $request->getArr( 19 + id(new DifferentialRepositoryField())->getFieldKey()); 20 + if ($repository_tokenizer) { 21 + $repository_phid = reset($repository_tokenizer); 22 + } 23 + 16 24 if ($request->getFileExists('diff-file')) { 17 25 $diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']); 18 26 } else { ··· 33 41 'differential.createrawdiff', 34 42 array( 35 43 'diff' => $diff, 36 - )); 44 + 'repositoryPHID' => $repository_phid,)); 37 45 $call->setUser($request->getUser()); 38 46 $result = $call->execute(); 39 47 $path = id(new PhutilURI($result['uri']))->getPath(); ··· 56 64 57 65 $cancel_uri = $this->getApplicationURI(); 58 66 67 + if ($repository_phid) { 68 + $repository_value = $this->loadViewerHandles(array($repository_phid)); 69 + } 70 + 59 71 $form 60 72 ->setAction('/differential/diff/create/') 61 73 ->setEncType('multipart/form-data') ··· 81 93 ->setLabel(pht('Raw Diff From File')) 82 94 ->setName('diff-file') 83 95 ->setError($e_file)) 96 + ->appendChild( 97 + id(new AphrontFormTokenizerControl()) 98 + ->setName(id(new DifferentialRepositoryField())->getFieldKey()) 99 + ->setLabel(pht('Repository')) 100 + ->setDatasource(new DiffusionRepositoryDatasource()) 101 + ->setValue($repository_value) 102 + ->setLimit(1)) 84 103 ->appendChild( 85 104 id(new AphrontFormSubmitControl()) 86 105 ->addCancelButton($cancel_uri)
+3
src/applications/differential/controller/DifferentialDiffViewController.php
··· 80 80 ->setAction('/differential/revision/edit/') 81 81 ->addHiddenInput('diffID', $diff->getID()) 82 82 ->addHiddenInput('viaDiffView', 1) 83 + ->addHiddenInput( 84 + id(new DifferentialRepositoryField())->getFieldKey(), 85 + $diff->getRepositoryPHID()) 83 86 ->appendRemarkupInstructions( 84 87 pht( 85 88 'Review the diff for correctness. When you are satisfied, either '.
+25 -5
src/applications/differential/controller/DifferentialRevisionEditController.php
··· 71 71 ->setViewer($viewer) 72 72 ->readFieldsFromStorage($revision); 73 73 74 + if ($request->getStr('viaDiffView') && $diff) { 75 + $repo_key = id(new DifferentialRepositoryField())->getFieldKey(); 76 + $repository_field = idx( 77 + $field_list->getFields(), 78 + $repo_key); 79 + if ($repository_field) { 80 + $repository_field->setValue($request->getStr($repo_key)); 81 + } 82 + } 83 + 74 84 $validation_exception = null; 75 85 if ($request->isFormPost() && !$request->getStr('viaDiffView')) { 86 + 87 + $editor = id(new DifferentialTransactionEditor()) 88 + ->setActor($viewer) 89 + ->setContentSourceFromRequest($request) 90 + ->setContinueOnNoEffect(true); 91 + 76 92 $xactions = $field_list->buildFieldTransactionsFromRequest( 77 93 new DifferentialTransaction(), 78 94 $request); 79 95 80 96 if ($diff) { 97 + $repository_phid = null; 98 + $repository_tokenizer = $request->getArr( 99 + id(new DifferentialRepositoryField())->getFieldKey()); 100 + if ($repository_tokenizer) { 101 + $repository_phid = reset($repository_tokenizer); 102 + } 103 + 81 104 $xactions[] = id(new DifferentialTransaction()) 82 105 ->setTransactionType(DifferentialTransaction::TYPE_UPDATE) 83 106 ->setNewValue($diff->getPHID()); 107 + 108 + $editor->setRepositoryPHIDOverride($repository_phid); 84 109 } 85 110 86 111 $comments = $request->getStr('comments'); ··· 91 116 id(new DifferentialTransactionComment()) 92 117 ->setContent($comments)); 93 118 } 94 - 95 - $editor = id(new DifferentialTransactionEditor()) 96 - ->setActor($viewer) 97 - ->setContentSourceFromRequest($request) 98 - ->setContinueOnNoEffect(true); 99 119 100 120 try { 101 121 $editor->applyTransactions($revision, $xactions);
+7 -1
src/applications/differential/editor/DifferentialDiffEditor.php
··· 4 4 extends PhabricatorApplicationTransactionEditor { 5 5 6 6 private $diffDataDict; 7 + private $lookupRepository = true; 8 + 9 + public function setLookupRepository($bool) { 10 + $this->lookupRepository = $bool; 11 + return $this; 12 + } 7 13 8 14 public function getEditorApplicationClass() { 9 15 return 'PhabricatorDifferentialApplication'; ··· 80 86 // is old, or couldn't figure out which repository the working copy 81 87 // belongs to), apply heuristics to try to figure it out. 82 88 83 - if (!$object->getRepositoryPHID()) { 89 + if ($this->lookupRepository && !$object->getRepositoryPHID()) { 84 90 $repository = id(new DifferentialRepositoryLookup()) 85 91 ->setDiff($object) 86 92 ->setViewer($this->getActor())
+11 -1
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 6 6 private $heraldEmailPHIDs; 7 7 private $changedPriorToCommitURI; 8 8 private $isCloseByCommit; 9 + private $repositoryPHIDOverride = false; 9 10 10 11 public function getEditorApplicationClass() { 11 12 return 'PhabricatorDifferentialApplication'; ··· 43 44 44 45 public function getChangedPriorToCommitURI() { 45 46 return $this->changedPriorToCommitURI; 47 + } 48 + 49 + public function setRepositoryPHIDOverride($phid_or_null) { 50 + $this->repositoryPHIDOverride = $phid_or_null; 51 + return $this; 46 52 } 47 53 48 54 public function getTransactionTypes() { ··· 205 211 $diff = $this->requireDiff($xaction->getNewValue()); 206 212 207 213 $object->setLineCount($diff->getLineCount()); 208 - $object->setRepositoryPHID($diff->getRepositoryPHID()); 214 + if ($this->repositoryPHIDOverride !== false) { 215 + $object->setRepositoryPHID($this->repositoryPHIDOverride); 216 + } else { 217 + $object->setRepositoryPHID($diff->getRepositoryPHID()); 218 + } 209 219 $object->setArcanistProjectPHID($diff->getArcanistProjectPHID()); 210 220 $object->attachActiveDiff($diff); 211 221