2011-04-03 23:48:36 +02:00
|
|
|
<?php
|
|
|
|
|
2012-03-14 00:21:04 +01:00
|
|
|
final class PhabricatorOwnersPath extends PhabricatorOwnersDAO {
|
2011-04-03 23:48:36 +02:00
|
|
|
|
|
|
|
protected $packageID;
|
|
|
|
protected $repositoryPHID;
|
2018-03-07 04:33:49 +01:00
|
|
|
protected $pathIndex;
|
2011-04-03 23:48:36 +02:00
|
|
|
protected $path;
|
2018-03-07 04:50:09 +01:00
|
|
|
protected $pathDisplay;
|
2012-12-07 02:23:56 +01:00
|
|
|
protected $excluded;
|
2011-04-03 23:48:36 +02:00
|
|
|
|
2017-02-27 16:59:40 +01:00
|
|
|
private $fragments;
|
|
|
|
private $fragmentCount;
|
|
|
|
|
2015-01-13 20:47:05 +01:00
|
|
|
protected function getConfiguration() {
|
2011-04-03 23:48:36 +02:00
|
|
|
return array(
|
|
|
|
self::CONFIG_TIMESTAMPS => false,
|
2014-10-01 16:53:12 +02:00
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
2018-03-07 04:50:09 +01:00
|
|
|
'path' => 'text',
|
|
|
|
'pathDisplay' => 'text',
|
2018-03-07 04:33:49 +01:00
|
|
|
'pathIndex' => 'bytes12',
|
2014-10-01 16:53:12 +02:00
|
|
|
'excluded' => 'bool',
|
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
2018-03-07 04:42:02 +01:00
|
|
|
'key_path' => array(
|
|
|
|
'columns' => array('packageID', 'repositoryPHID', 'pathIndex'),
|
|
|
|
'unique' => true,
|
2014-10-01 16:53:12 +02:00
|
|
|
),
|
2018-03-07 05:25:17 +01:00
|
|
|
'key_repository' => array(
|
|
|
|
'columns' => array('repositoryPHID', 'pathIndex'),
|
|
|
|
),
|
2014-10-01 16:53:12 +02:00
|
|
|
),
|
2011-04-04 07:03:27 +02:00
|
|
|
) + parent::getConfiguration();
|
2011-04-03 23:48:36 +02:00
|
|
|
}
|
|
|
|
|
Convert Owners paths to application transactions
Summary:
Ref T8320. Fixes T8317. Fixes T2831. Fixes T8073. Fixes T7127.
There was a bug with this line:
for ($ii = 0; $ii < count($paths); $ii++) {
...because the array may be sparse if there have been deletes, so `count($paths)` might be 3, but the real keys could be `1`, `5` and `6`. I think this was the primary issue behind T7127.
The old Editor did a lot of work to try to validate paths. When a path failed to validate, it silently discarded it. This was silly and pointless: it's incredibly bad UX; and it's totally fine if users saves "invalid" paths. This was likely the cause of T8317, and probably the cause of T8073.
T2831 I'm less sure about, but I can't reproduce it and I rewrote all the logic so I suspect it's gone.
This also records and shows edits, so if stuff does keep happening it should be more clear what's going on.
I removed some adjacent stuff:
- I removed the ability to delete packages. I'll add "disable" in a future diff, plus `bin/remove destroy`, like other objects. Getting rid of this now let me get rid of all the mail stuff.
- I removed "path validation" where packages would try to automatically update in response to commits. This doesn't necessarily make sense in Git/Mercurial, is sketchy, could easily have been the source of T2831, and seems generally complicated and not very valuable. We could maybe restore it some day, but I'd like to get Owners stable before trying to do crazy stuff like that.
Test Plan: {F437687}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T8317, T8073, T7127, T2831, T8320
Differential Revision: https://secure.phabricator.com/D13032
2015-05-27 19:30:26 +02:00
|
|
|
public static function newFromRef(array $ref) {
|
|
|
|
$path = new PhabricatorOwnersPath();
|
|
|
|
$path->repositoryPHID = $ref['repositoryPHID'];
|
2018-03-07 04:33:49 +01:00
|
|
|
|
|
|
|
$raw_path = $ref['path'];
|
|
|
|
|
|
|
|
$path->pathIndex = PhabricatorHash::digestForIndex($raw_path);
|
|
|
|
$path->path = $raw_path;
|
2018-03-07 04:50:09 +01:00
|
|
|
$path->pathDisplay = $raw_path;
|
2018-03-07 04:33:49 +01:00
|
|
|
|
Convert Owners paths to application transactions
Summary:
Ref T8320. Fixes T8317. Fixes T2831. Fixes T8073. Fixes T7127.
There was a bug with this line:
for ($ii = 0; $ii < count($paths); $ii++) {
...because the array may be sparse if there have been deletes, so `count($paths)` might be 3, but the real keys could be `1`, `5` and `6`. I think this was the primary issue behind T7127.
The old Editor did a lot of work to try to validate paths. When a path failed to validate, it silently discarded it. This was silly and pointless: it's incredibly bad UX; and it's totally fine if users saves "invalid" paths. This was likely the cause of T8317, and probably the cause of T8073.
T2831 I'm less sure about, but I can't reproduce it and I rewrote all the logic so I suspect it's gone.
This also records and shows edits, so if stuff does keep happening it should be more clear what's going on.
I removed some adjacent stuff:
- I removed the ability to delete packages. I'll add "disable" in a future diff, plus `bin/remove destroy`, like other objects. Getting rid of this now let me get rid of all the mail stuff.
- I removed "path validation" where packages would try to automatically update in response to commits. This doesn't necessarily make sense in Git/Mercurial, is sketchy, could easily have been the source of T2831, and seems generally complicated and not very valuable. We could maybe restore it some day, but I'd like to get Owners stable before trying to do crazy stuff like that.
Test Plan: {F437687}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T8317, T8073, T7127, T2831, T8320
Differential Revision: https://secure.phabricator.com/D13032
2015-05-27 19:30:26 +02:00
|
|
|
$path->excluded = $ref['excluded'];
|
2018-03-07 04:33:49 +01:00
|
|
|
|
Convert Owners paths to application transactions
Summary:
Ref T8320. Fixes T8317. Fixes T2831. Fixes T8073. Fixes T7127.
There was a bug with this line:
for ($ii = 0; $ii < count($paths); $ii++) {
...because the array may be sparse if there have been deletes, so `count($paths)` might be 3, but the real keys could be `1`, `5` and `6`. I think this was the primary issue behind T7127.
The old Editor did a lot of work to try to validate paths. When a path failed to validate, it silently discarded it. This was silly and pointless: it's incredibly bad UX; and it's totally fine if users saves "invalid" paths. This was likely the cause of T8317, and probably the cause of T8073.
T2831 I'm less sure about, but I can't reproduce it and I rewrote all the logic so I suspect it's gone.
This also records and shows edits, so if stuff does keep happening it should be more clear what's going on.
I removed some adjacent stuff:
- I removed the ability to delete packages. I'll add "disable" in a future diff, plus `bin/remove destroy`, like other objects. Getting rid of this now let me get rid of all the mail stuff.
- I removed "path validation" where packages would try to automatically update in response to commits. This doesn't necessarily make sense in Git/Mercurial, is sketchy, could easily have been the source of T2831, and seems generally complicated and not very valuable. We could maybe restore it some day, but I'd like to get Owners stable before trying to do crazy stuff like that.
Test Plan: {F437687}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T8317, T8073, T7127, T2831, T8320
Differential Revision: https://secure.phabricator.com/D13032
2015-05-27 19:30:26 +02:00
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRef() {
|
|
|
|
return array(
|
|
|
|
'repositoryPHID' => $this->getRepositoryPHID(),
|
|
|
|
'path' => $this->getPath(),
|
2018-03-07 05:07:32 +01:00
|
|
|
'display' => $this->getPathDisplay(),
|
Convert Owners paths to application transactions
Summary:
Ref T8320. Fixes T8317. Fixes T2831. Fixes T8073. Fixes T7127.
There was a bug with this line:
for ($ii = 0; $ii < count($paths); $ii++) {
...because the array may be sparse if there have been deletes, so `count($paths)` might be 3, but the real keys could be `1`, `5` and `6`. I think this was the primary issue behind T7127.
The old Editor did a lot of work to try to validate paths. When a path failed to validate, it silently discarded it. This was silly and pointless: it's incredibly bad UX; and it's totally fine if users saves "invalid" paths. This was likely the cause of T8317, and probably the cause of T8073.
T2831 I'm less sure about, but I can't reproduce it and I rewrote all the logic so I suspect it's gone.
This also records and shows edits, so if stuff does keep happening it should be more clear what's going on.
I removed some adjacent stuff:
- I removed the ability to delete packages. I'll add "disable" in a future diff, plus `bin/remove destroy`, like other objects. Getting rid of this now let me get rid of all the mail stuff.
- I removed "path validation" where packages would try to automatically update in response to commits. This doesn't necessarily make sense in Git/Mercurial, is sketchy, could easily have been the source of T2831, and seems generally complicated and not very valuable. We could maybe restore it some day, but I'd like to get Owners stable before trying to do crazy stuff like that.
Test Plan: {F437687}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T8317, T8073, T7127, T2831, T8320
Differential Revision: https://secure.phabricator.com/D13032
2015-05-27 19:30:26 +02:00
|
|
|
'excluded' => (int)$this->getExcluded(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getTransactionValueChanges(array $old, array $new) {
|
|
|
|
return array(
|
|
|
|
self::getTransactionValueDiff($old, $new),
|
|
|
|
self::getTransactionValueDiff($new, $old),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function getTransactionValueDiff(array $u, array $v) {
|
|
|
|
$set = self::getSetFromTransactionValue($v);
|
|
|
|
|
|
|
|
foreach ($u as $key => $ref) {
|
|
|
|
if (self::isRefInSet($ref, $set)) {
|
|
|
|
unset($u[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $u;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getSetFromTransactionValue(array $v) {
|
|
|
|
$set = array();
|
|
|
|
foreach ($v as $ref) {
|
|
|
|
$set[$ref['repositoryPHID']][$ref['path']][$ref['excluded']] = true;
|
|
|
|
}
|
|
|
|
return $set;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function isRefInSet(array $ref, array $set) {
|
|
|
|
return isset($set[$ref['repositoryPHID']][$ref['path']][$ref['excluded']]);
|
|
|
|
}
|
|
|
|
|
2015-08-15 22:06:10 +02:00
|
|
|
/**
|
|
|
|
* Get the number of directory matches between this path specification and
|
|
|
|
* some real path.
|
|
|
|
*/
|
2017-02-27 16:59:40 +01:00
|
|
|
public function getPathMatchStrength($path_fragments, $path_count) {
|
|
|
|
$this_path = $this->path;
|
2015-08-15 22:06:10 +02:00
|
|
|
|
|
|
|
if ($this_path === '/') {
|
|
|
|
// The root path "/" just matches everything with strength 1.
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-02-27 16:59:40 +01:00
|
|
|
if ($this->fragments === null) {
|
|
|
|
$this->fragments = PhabricatorOwnersPackage::splitPath($this_path);
|
|
|
|
$this->fragmentCount = count($this->fragments);
|
|
|
|
}
|
2015-08-15 22:06:10 +02:00
|
|
|
|
2017-02-27 16:59:40 +01:00
|
|
|
$self_fragments = $this->fragments;
|
|
|
|
$self_count = $this->fragmentCount;
|
2015-08-15 22:06:10 +02:00
|
|
|
if ($self_count > $path_count) {
|
2016-08-30 22:56:25 +02:00
|
|
|
// If this path is longer (and therefore more specific) than the target
|
2015-08-15 22:06:10 +02:00
|
|
|
// path, we don't match it at all.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($ii = 0; $ii < $self_count; $ii++) {
|
|
|
|
if ($self_fragments[$ii] != $path_fragments[$ii]) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $self_count;
|
|
|
|
}
|
|
|
|
|
2011-04-03 23:48:36 +02:00
|
|
|
}
|