@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.

Prepare to support an "Ignore generated files" flag in Owners

Summary:
Depends on D19425. Ref T13130. See PHI251. Now that changesets have a durable "generated" attribute, we can let owners packages check it when we're computing which packages are affected by a revision.

There's no way to actualy configure a package to have this behavior yet.

Test Plan:
- Created a revision affecting a generated file and a non-generated file.
- When I faked `mustMatchUngeneratedPaths()` to `return true;`, saw the non-generated file get no packages owning it.
- Normally: lots of packages owning it).
- Created a revision affecting only generated files.
- When I faked things, saw no Owners actions trigger.
- Normally: some packages added reviewers or subscribers.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13130

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

+121 -20
+10
src/applications/differential/controller/DifferentialController.php
··· 76 76 $repository_phid, 77 77 $changeset_path); 78 78 79 + // If this particular changeset is generated code and the package does 80 + // not match generated code, remove it from the list. 81 + if ($changeset->isGeneratedChangeset()) { 82 + foreach ($packages as $key => $package) { 83 + if ($package->getMustMatchUngeneratedPaths()) { 84 + unset($packages[$key]); 85 + } 86 + } 87 + } 88 + 79 89 $this->pathPackageMap[$changeset_path] = $packages; 80 90 foreach ($packages as $package) { 81 91 $this->packageChangesetMap[$package->getPHID()][] = $changeset;
+19 -7
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 7 7 private $isCloseByCommit; 8 8 private $repositoryPHIDOverride = false; 9 9 private $didExpandInlineState = false; 10 - private $affectedPaths; 11 10 private $firstBroadcast = false; 12 11 private $wasBroadcasting; 13 12 private $isDraftDemotion; 13 + 14 + private $ownersDiff; 15 + private $ownersChangesets; 14 16 15 17 public function getEditorApplicationClass() { 16 18 return 'PhabricatorDifferentialApplication'; ··· 968 970 return array(); 969 971 } 970 972 971 - if (!$this->affectedPaths) { 973 + $diff = $this->ownersDiff; 974 + $changesets = $this->ownersChangesets; 975 + 976 + $this->ownersDiff = null; 977 + $this->ownersChangesets = null; 978 + 979 + if (!$changesets) { 972 980 return array(); 973 981 } 974 982 975 - $packages = PhabricatorOwnersPackage::loadAffectedPackages( 983 + $packages = PhabricatorOwnersPackage::loadAffectedPackagesForChangesets( 976 984 $repository, 977 - $this->affectedPaths); 985 + $diff, 986 + $changesets); 978 987 if (!$packages) { 979 988 return array(); 980 989 } ··· 1255 1264 $paths[] = $path_prefix.'/'.$changeset->getFilename(); 1256 1265 } 1257 1266 1258 - // Save the affected paths; we'll use them later to query Owners. This 1259 - // uses the un-expanded paths. 1260 - $this->affectedPaths = $paths; 1267 + // If this change affected paths, save the changesets so we can apply 1268 + // Owners rules to them later. 1269 + if ($paths) { 1270 + $this->ownersDiff = $diff; 1271 + $this->ownersChangesets = $changesets; 1272 + } 1261 1273 1262 1274 // Mark this as also touching all parent paths, so you can see all pending 1263 1275 // changes to any file within a directory.
+3 -2
src/applications/differential/herald/HeraldDifferentialRevisionAdapter.php
··· 120 120 121 121 $repository = $this->loadRepository(); 122 122 if ($repository) { 123 - $packages = PhabricatorOwnersPackage::loadAffectedPackages( 123 + $packages = PhabricatorOwnersPackage::loadAffectedPackagesForChangesets( 124 124 $repository, 125 - $this->loadAffectedPaths()); 125 + $this->getDiff(), 126 + $this->loadChangesets()); 126 127 $this->affectedPackages = $packages; 127 128 } 128 129 }
+10 -8
src/applications/differential/storage/DifferentialDiff.php
··· 827 827 DifferentialChangeset $changeset) { 828 828 829 829 $is_generated_trusted = self::isTrustedGeneratedCode($changeset); 830 - 831 - $changeset->setTrustedChangesetAttribute( 832 - DifferentialChangeset::ATTRIBUTE_GENERATED, 833 - $is_generated_trusted); 830 + if ($is_generated_trusted) { 831 + $changeset->setTrustedChangesetAttribute( 832 + DifferentialChangeset::ATTRIBUTE_GENERATED, 833 + $is_generated_trusted); 834 + } 834 835 835 836 $is_generated_untrusted = self::isUntrustedGeneratedCode($changeset); 836 - 837 - $changeset->setUntrustedChangesetAttribute( 838 - DifferentialChangeset::ATTRIBUTE_GENERATED, 839 - $is_generated_untrusted); 837 + if ($is_generated_untrusted) { 838 + $changeset->setUntrustedChangesetAttribute( 839 + DifferentialChangeset::ATTRIBUTE_GENERATED, 840 + $is_generated_untrusted); 841 + } 840 842 } 841 843 842 844 private static function isTrustedGeneratedCode(
+79 -3
src/applications/owners/storage/PhabricatorOwnersPackage.php
··· 147 147 return ($this->getStatus() == self::STATUS_ARCHIVED); 148 148 } 149 149 150 - public function setName($name) { 151 - $this->name = $name; 152 - return $this; 150 + public function getMustMatchUngeneratedPaths() { 151 + // TODO: For now, there's no way to actually configure this. 152 + return false; 153 153 } 154 154 155 155 public function loadOwners() { ··· 179 179 } 180 180 181 181 return self::loadPackagesForPaths($repository, $paths); 182 + } 183 + 184 + public static function loadAffectedPackagesForChangesets( 185 + PhabricatorRepository $repository, 186 + DifferentialDiff $diff, 187 + array $changesets) { 188 + assert_instances_of($changesets, 'DifferentialChangeset'); 189 + 190 + $paths_all = array(); 191 + $paths_ungenerated = array(); 192 + 193 + foreach ($changesets as $changeset) { 194 + $path = $changeset->getAbsoluteRepositoryPath($repository, $diff); 195 + 196 + $paths_all[] = $path; 197 + 198 + if (!$changeset->isGeneratedChangeset()) { 199 + $paths_ungenerated[] = $path; 200 + } 201 + } 202 + 203 + if (!$paths_all) { 204 + return array(); 205 + } 206 + 207 + $packages_all = self::loadAffectedPackages( 208 + $repository, 209 + $paths_all); 210 + 211 + // If there are no generated changesets, we can't possibly need to throw 212 + // away any packages for matching only generated paths. Just return the 213 + // full set of packages. 214 + if ($paths_ungenerated === $paths_all) { 215 + return $packages_all; 216 + } 217 + 218 + $must_match_ungenerated = array(); 219 + foreach ($packages_all as $package) { 220 + if ($package->getMustMatchUngeneratedPaths()) { 221 + $must_match_ungenerated[] = $package; 222 + } 223 + } 224 + 225 + // If no affected packages have the "Ignore Generated Paths" flag set, we 226 + // can't possibly need to throw any away. 227 + if (!$must_match_ungenerated) { 228 + return $packages_all; 229 + } 230 + 231 + if ($paths_ungenerated) { 232 + $packages_ungenerated = self::loadAffectedPackages( 233 + $repository, 234 + $paths_ungenerated); 235 + } else { 236 + $packages_ungenerated = array(); 237 + } 238 + 239 + // We have some generated paths, and some packages that ignore generated 240 + // paths. Take all the packages which: 241 + // 242 + // - ignore generated paths; and 243 + // - didn't match any ungenerated paths 244 + // 245 + // ...and remove them from the list. 246 + 247 + $must_match_ungenerated = mpull($must_match_ungenerated, null, 'getID'); 248 + $packages_ungenerated = mpull($packages_ungenerated, null, 'getID'); 249 + $packages_all = mpull($packages_all, null, 'getID'); 250 + 251 + foreach ($must_match_ungenerated as $package_id => $package) { 252 + if (!isset($packages_ungenerated[$package_id])) { 253 + unset($packages_all[$package_id]); 254 + } 255 + } 256 + 257 + return $packages_all; 182 258 } 183 259 184 260 public static function loadOwningPackages($repository, $path) {