[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DiffusionLowLevelParentsQuery 4 extends DiffusionLowLevelQuery { 5 6 private $identifier; 7 8 public function withIdentifier($identifier) { 9 $this->identifier = $identifier; 10 return $this; 11 } 12 13 public function executeQuery() { 14 if (!strlen($this->identifier)) { 15 throw new Exception( 16 pht('You must provide an identifier with withIdentifier()!')); 17 } 18 19 $type = $this->getRepository()->getVersionControlSystem(); 20 switch ($type) { 21 case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 22 $result = $this->loadGitParents(); 23 break; 24 case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: 25 $result = $this->loadMercurialParents(); 26 break; 27 case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 28 $result = $this->loadSubversionParents(); 29 break; 30 default: 31 throw new Exception(pht('Unsupported repository type "%s"!', $type)); 32 } 33 34 return $result; 35 } 36 37 private function loadGitParents() { 38 $repository = $this->getRepository(); 39 40 list($stdout) = $repository->execxLocalCommand( 41 'log -n 1 --format=%s %s', 42 '%P', 43 $this->identifier); 44 45 return preg_split('/\s+/', trim($stdout)); 46 } 47 48 private function loadMercurialParents() { 49 $repository = $this->getRepository(); 50 51 list($stdout) = $repository->execxLocalCommand( 52 'log --debug --limit 1 --template={parents} --rev %s', 53 $this->identifier); 54 $stdout = PhabricatorRepository::filterMercurialDebugOutput($stdout); 55 56 $hashes = preg_split('/\s+/', trim($stdout)); 57 foreach ($hashes as $key => $value) { 58 // Mercurial parents look like "23:ad9f769d6f786fad9f76d9a" -- we want 59 // to strip out the local rev part. 60 list($local, $global) = explode(':', $value); 61 $hashes[$key] = $global; 62 63 // With --debug we get 40-character hashes but also get the "000000..." 64 // hash for missing parents; ignore it. 65 if (preg_match('/^0+$/', $global)) { 66 unset($hashes[$key]); 67 } 68 } 69 70 return $hashes; 71 } 72 73 private function loadSubversionParents() { 74 $n = (int)$this->identifier; 75 if ($n > 1) { 76 $ids = array($n - 1); 77 } else { 78 $ids = array(); 79 } 80 81 return $ids; 82 } 83 84 }
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 |