Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistInspectWorkflow.php
| Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | if (!$objects) { | ||||
| } | } | ||||
| echo tsprintf("\n"); | echo tsprintf("\n"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| $all_refs = array(); | $all_refs = array(); | ||||
| $ref_lists = array(); | |||||
| foreach ($objects as $description) { | foreach ($objects as $description) { | ||||
| $matches = null; | $matches = null; | ||||
| $pattern = '/^([\w-]+)(?:\(([^)]+)\))?\z/'; | $pattern = '/^([\w-]+)(?:\(([^)]+)\))?\z/'; | ||||
| if (!preg_match($pattern, $description, $matches)) { | if (!preg_match($pattern, $description, $matches)) { | ||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht( | pht( | ||||
| 'Object specification "%s" is unknown, expected a specification '. | 'Object specification "%s" is unknown, expected a specification '. | ||||
| 'like "commit(HEAD)".', | 'like "commit(HEAD)".', | ||||
| Show All 16 Lines | foreach ($objects as $description) { | ||||
| if (isset($matches[2])) { | if (isset($matches[2])) { | ||||
| $arguments = array($matches[2]); | $arguments = array($matches[2]); | ||||
| } else { | } else { | ||||
| $arguments = array(); | $arguments = array(); | ||||
| } | } | ||||
| $ref = $inspector->newInspectRef($arguments); | $ref = $inspector->newInspectRef($arguments); | ||||
| $ref_lists[get_class($ref)][] = $ref; | |||||
| $all_refs[] = $ref; | $all_refs[] = $ref; | ||||
| } | } | ||||
| if ($is_explore) { | if ($is_explore) { | ||||
| foreach ($ref_lists as $ref_class => $refs) { | $this->exploreRefs($all_refs); | ||||
| $ref = head($refs); | |||||
| $hardpoint_list = $ref->getHardpointList(); | |||||
| $hardpoints = $hardpoint_list->getHardpoints(); | |||||
| if ($hardpoints) { | |||||
| $hardpoint_keys = mpull($hardpoints, 'getHardpointKey'); | |||||
| $this->loadHardpoints($refs, $hardpoint_keys); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| $list = array(); | $list = array(); | ||||
| foreach ($all_refs as $ref) { | foreach ($all_refs as $ref) { | ||||
| $out = $this->describeRef($ref, 0); | $out = $this->describeRef($ref, 0); | ||||
| $list[] = implode('', $out); | $list[] = implode('', $out); | ||||
| } | } | ||||
| $list = implode("\n", $list); | $list = implode("\n", $list); | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | private function describeValue($value, $depth) { | ||||
| $out = array(); | $out = array(); | ||||
| $out[] = tsprintf( | $out[] = tsprintf( | ||||
| "%s> %s\n", | "%s> %s\n", | ||||
| $indent, | $indent, | ||||
| $display_value); | $display_value); | ||||
| return $out; | return $out; | ||||
| } | } | ||||
| private function exploreRefs(array $refs) { | |||||
| $seen = array(); | |||||
| $look = $refs; | |||||
| while ($look) { | |||||
| $ref_map = $this->getRefsByClass($look); | |||||
| $look = array(); | |||||
| $children = $this->inspectHardpoints($ref_map); | |||||
| foreach ($children as $child) { | |||||
| $hash = spl_object_hash($child); | |||||
| if (isset($seen[$hash])) { | |||||
| continue; | |||||
| } | |||||
| $seen[$hash] = true; | |||||
| $look[] = $child; | |||||
| } | |||||
| } | |||||
| } | |||||
| private function getRefsByClass(array $refs) { | |||||
| $ref_lists = array(); | |||||
| foreach ($refs as $ref) { | |||||
| $ref_lists[get_class($ref)][] = $ref; | |||||
| } | |||||
| foreach ($ref_lists as $ref_class => $refs) { | |||||
| $typical_ref = head($refs); | |||||
| $hardpoint_list = $typical_ref->getHardpointList(); | |||||
| $hardpoints = $hardpoint_list->getHardpoints(); | |||||
| if (!$hardpoints) { | |||||
| unset($ref_lists[$ref_class]); | |||||
| continue; | |||||
| } | |||||
| $hardpoint_keys = mpull($hardpoints, 'getHardpointKey'); | |||||
| $ref_lists[$ref_class] = array( | |||||
| 'keys' => $hardpoint_keys, | |||||
| 'refs' => $refs, | |||||
| ); | |||||
| } | |||||
| return $ref_lists; | |||||
| } | |||||
| private function inspectHardpoints(array $ref_lists) { | |||||
| foreach ($ref_lists as $ref_class => $spec) { | |||||
| $refs = $spec['refs']; | |||||
| $keys = $spec['keys']; | |||||
| $this->loadHardpoints($refs, $keys); | |||||
| } | |||||
| $child_refs = array(); | |||||
| foreach ($ref_lists as $ref_class => $spec) { | |||||
| $refs = $spec['refs']; | |||||
| $keys = $spec['keys']; | |||||
| foreach ($refs as $ref) { | |||||
| foreach ($keys as $key) { | |||||
| $value = $ref->getHardpoint($key); | |||||
| if (!is_array($value)) { | |||||
| $value = array($value); | |||||
| } | |||||
| foreach ($value as $child) { | |||||
| if ($child instanceof ArcanistRef) { | |||||
| $child_refs[] = $child; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| return $child_refs; | |||||
| } | |||||
| } | } | ||||