[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorRepositoryManagementCacheWorkflow 4 extends PhabricatorRepositoryManagementWorkflow { 5 6 public function didConstruct() { 7 $this 8 ->setName('cache') 9 ->setExamples( 10 '**cache** [__options__] --commit __commit__ --path __path__') 11 ->setSynopsis(pht('Manage the repository graph cache.')) 12 ->setArguments( 13 array( 14 array( 15 'name' => 'commit', 16 'param' => 'commit', 17 'help' => pht('Specify a commit to look up.'), 18 ), 19 array( 20 'name' => 'path', 21 'param' => 'path', 22 'help' => pht('Specify a path to look up.'), 23 ), 24 )); 25 } 26 27 public function execute(PhutilArgumentParser $args) { 28 29 $commit_name = $args->getArg('commit'); 30 if ($commit_name === null) { 31 throw new PhutilArgumentUsageException( 32 pht('Specify a commit to look up with `--commit`.')); 33 } 34 $commit = $this->loadNamedCommit($commit_name); 35 36 $path_name = $args->getArg('path'); 37 if ($path_name === null) { 38 throw new PhutilArgumentUsageException( 39 pht('Specify a path to look up with `--path`.')); 40 } 41 42 $path_map = id(new DiffusionPathIDQuery(array($path_name))) 43 ->loadPathIDs(); 44 if (empty($path_map[$path_name])) { 45 throw new PhutilArgumentUsageException( 46 pht('Path "%s" is not known to Phabricator.', $path_name)); 47 } 48 $path_id = $path_map[$path_name]; 49 50 $graph_cache = new PhabricatorRepositoryGraphCache(); 51 52 $t_start = microtime(true); 53 $cache_result = $graph_cache->loadLastModifiedCommitID( 54 $commit->getID(), 55 $path_id); 56 $t_end = microtime(true); 57 58 $console = PhutilConsole::getConsole(); 59 60 $console->writeOut( 61 "%s\n", 62 pht('Query took %s ms.', new PhutilNumber(1000 * ($t_end - $t_start)))); 63 64 if ($cache_result === false) { 65 $console->writeOut( 66 "%s\n", 67 pht('Not found in graph cache.')); 68 } else if ($cache_result === null) { 69 $console->writeOut( 70 "%s\n", 71 pht('Path not modified in any ancestor commit.')); 72 } else { 73 $last = id(new DiffusionCommitQuery()) 74 ->setViewer($this->getViewer()) 75 ->withIDs(array($cache_result)) 76 ->executeOne(); 77 if (!$last) { 78 throw new Exception(pht('Cache returned bogus result!')); 79 } 80 81 $console->writeOut( 82 "%s\n", 83 pht( 84 'Path was last changed at %s.', 85 $commit->getRepository()->formatCommitName( 86 $last->getcommitIdentifier()))); 87 } 88 89 return 0; 90 } 91 92 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |