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

Fix an issue in Owners where a transaction change could show too many effects

Summary:
Fixes T13324. Ref PHI1288. Currently, if you edit an Owners package that has some paths with no trailing slashes (like `README.md`) so their internal names and display names differ (`/README.md` display, vs `/README.md/` internal), the "Show Details" in the transaction log shows the path as re-normalized even if you didn't touch it.

Instead, be more careful about handling display paths vs internal paths.

(This code on the whole is significantly less clear than it probably could be, but this issue is so minor that I'm hesitant to start ripping things out.)

Test Plan:
- In a package with some paths like `/src/` and some paths like `/src`:
- Added new paths.
- Removed paths.
- Changed paths from `/src/` to `/src`.
- Changed paths from `/src` to `/src/`.

In all cases, the "paths" list and the transaction record identically reflected the edit in the way I expected them to.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13324

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

+46 -6
+14 -2
src/applications/owners/storage/PhabricatorOwnersPath.php
··· 79 79 public static function getSetFromTransactionValue(array $v) { 80 80 $set = array(); 81 81 foreach ($v as $ref) { 82 - $set[$ref['repositoryPHID']][$ref['path']][$ref['excluded']] = true; 82 + $key = self::getScalarKeyForRef($ref); 83 + $set[$key] = true; 83 84 } 84 85 return $set; 85 86 } 86 87 87 88 public static function isRefInSet(array $ref, array $set) { 88 - return isset($set[$ref['repositoryPHID']][$ref['path']][$ref['excluded']]); 89 + $key = self::getScalarKeyForRef($ref); 90 + return isset($set[$key]); 89 91 } 92 + 93 + private static function getScalarKeyForRef(array $ref) { 94 + return sprintf( 95 + 'repository=%s path=%s display=%s excluded=%d', 96 + $ref['repositoryPHID'], 97 + $ref['path'], 98 + $ref['display'], 99 + $ref['excluded']); 100 + } 101 + 90 102 91 103 /** 92 104 * Get the number of directory matches between this path specification and
+32 -4
src/applications/owners/xaction/PhabricatorOwnersPackagePathsTransaction.php
··· 12 12 13 13 public function generateNewValue($object, $value) { 14 14 $new = $value; 15 + 15 16 foreach ($new as $key => $info) { 16 - $new[$key]['excluded'] = (int)idx($info, 'excluded'); 17 + $info['excluded'] = (int)idx($info, 'excluded'); 18 + 19 + // The input has one "path" key with the display path. 20 + // Move it to "display", then normalize the value in "path". 21 + 22 + $display_path = $info['path']; 23 + $raw_path = rtrim($display_path, '/').'/'; 24 + 25 + $info['path'] = $raw_path; 26 + $info['display'] = $display_path; 27 + 28 + $new[$key] = $info; 17 29 } 30 + 18 31 return $new; 19 32 } 20 33 34 + public function getTransactionHasEffect($object, $old, $new) { 35 + list($add, $rem) = PhabricatorOwnersPath::getTransactionValueChanges( 36 + $old, 37 + $new); 38 + 39 + return ($add || $rem); 40 + } 41 + 21 42 public function validateTransactions($object, array $xactions) { 22 43 $errors = array(); 23 44 ··· 110 131 $display_map = array(); 111 132 $seen_map = array(); 112 133 foreach ($new as $key => $spec) { 113 - $display_path = $spec['path']; 114 - $raw_path = rtrim($display_path, '/').'/'; 134 + $raw_path = $spec['path']; 135 + $display_path = $spec['display']; 115 136 116 137 // If the user entered two paths in the same repository which normalize 117 138 // to the same value (like "src/main.c" and "src/main.c/"), discard the ··· 193 214 $rowc = array(); 194 215 foreach ($rows as $key => $row) { 195 216 $rowc[] = $row['class']; 217 + 218 + if (array_key_exists('display', $row)) { 219 + $display_path = $row['display']; 220 + } else { 221 + $display_path = $row['path']; 222 + } 223 + 196 224 $rows[$key] = array( 197 225 $row['change'], 198 226 $row['excluded'] ? pht('Exclude') : pht('Include'), 199 227 $this->renderHandle($row['repositoryPHID']), 200 - $row['path'], 228 + $display_path, 201 229 ); 202 230 } 203 231