Path: blob/master/src/applications/owners/storage/PhabricatorOwnersPath.php
12256 views
<?php12final class PhabricatorOwnersPath extends PhabricatorOwnersDAO {34protected $packageID;5protected $repositoryPHID;6protected $pathIndex;7protected $path;8protected $pathDisplay;9protected $excluded;1011private $fragments;12private $fragmentCount;1314protected function getConfiguration() {15return array(16self::CONFIG_TIMESTAMPS => false,17self::CONFIG_COLUMN_SCHEMA => array(18'path' => 'text',19'pathDisplay' => 'text',20'pathIndex' => 'bytes12',21'excluded' => 'bool',22),23self::CONFIG_KEY_SCHEMA => array(24'key_path' => array(25'columns' => array('packageID', 'repositoryPHID', 'pathIndex'),26'unique' => true,27),28'key_repository' => array(29'columns' => array('repositoryPHID', 'pathIndex'),30),31),32) + parent::getConfiguration();33}3435public static function newFromRef(array $ref) {36$path = new PhabricatorOwnersPath();37$path->repositoryPHID = $ref['repositoryPHID'];3839$raw_path = $ref['path'];4041$path->pathIndex = PhabricatorHash::digestForIndex($raw_path);42$path->path = $raw_path;43$path->pathDisplay = $raw_path;4445$path->excluded = $ref['excluded'];4647return $path;48}4950public function getRef() {51return array(52'repositoryPHID' => $this->getRepositoryPHID(),53'path' => $this->getPath(),54'display' => $this->getPathDisplay(),55'excluded' => (int)$this->getExcluded(),56);57}5859public static function getTransactionValueChanges(array $old, array $new) {60return array(61self::getTransactionValueDiff($old, $new),62self::getTransactionValueDiff($new, $old),63);64}6566private static function getTransactionValueDiff(array $u, array $v) {67$set = self::getSetFromTransactionValue($v);6869foreach ($u as $key => $ref) {70if (self::isRefInSet($ref, $set)) {71unset($u[$key]);72}73}7475return $u;76}7778public static function getSetFromTransactionValue(array $v) {79$set = array();80foreach ($v as $ref) {81$key = self::getScalarKeyForRef($ref);82$set[$key] = true;83}84return $set;85}8687public static function isRefInSet(array $ref, array $set) {88$key = self::getScalarKeyForRef($ref);89return isset($set[$key]);90}9192private static function getScalarKeyForRef(array $ref) {93// See T13464. When building refs from raw transactions, the path has94// not been normalized yet and doesn't have a separate "display" path.95// If the "display" path isn't populated, just use the actual path to96// build the ref key.9798if (isset($ref['display'])) {99$display = $ref['display'];100} else {101$display = $ref['path'];102}103104return sprintf(105'repository=%s path=%s display=%s excluded=%d',106$ref['repositoryPHID'],107$ref['path'],108$display,109$ref['excluded']);110}111112113/**114* Get the number of directory matches between this path specification and115* some real path.116*/117public function getPathMatchStrength($path_fragments, $path_count) {118$this_path = $this->path;119120if ($this_path === '/') {121// The root path "/" just matches everything with strength 1.122return 1;123}124125if ($this->fragments === null) {126$this->fragments = PhabricatorOwnersPackage::splitPath($this_path);127$this->fragmentCount = count($this->fragments);128}129130$self_fragments = $this->fragments;131$self_count = $this->fragmentCount;132if ($self_count > $path_count) {133// If this path is longer (and therefore more specific) than the target134// path, we don't match it at all.135return 0;136}137138for ($ii = 0; $ii < $self_count; $ii++) {139if ($self_fragments[$ii] != $path_fragments[$ii]) {140return 0;141}142}143144return $self_count;145}146147}148149150