[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/conduit/ -> DiffusionLastModifiedQueryConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final class DiffusionLastModifiedQueryConduitAPIMethod
   4    extends DiffusionQueryConduitAPIMethod {
   5  
   6    public function getAPIMethodName() {
   7      return 'diffusion.lastmodifiedquery';
   8    }
   9  
  10    public function getMethodDescription() {
  11      return pht('Get the commits at which paths were last modified.');
  12    }
  13  
  14    public function defineReturnType() {
  15      return 'map<string, string>';
  16    }
  17  
  18    protected function defineCustomParamTypes() {
  19      return array(
  20        'paths' => 'required map<string, string>',
  21      );
  22    }
  23  
  24    protected function getGitResult(ConduitAPIRequest $request) {
  25      $drequest = $this->getDiffusionRequest();
  26      $repository = $drequest->getRepository();
  27  
  28      $paths = $request->getValue('paths');
  29      $results = $this->loadCommitsFromCache($paths);
  30  
  31      foreach ($paths as $path => $commit) {
  32        if (array_key_exists($path, $results)) {
  33          continue;
  34        }
  35        list($hash) = $repository->execxLocalCommand(
  36          'log -n1 --format=%%H %s -- %s',
  37          $commit,
  38          $path);
  39        $results[$path] = trim($hash);
  40      }
  41  
  42      return $results;
  43    }
  44  
  45    protected function getSVNResult(ConduitAPIRequest $request) {
  46      $drequest = $this->getDiffusionRequest();
  47      $repository = $drequest->getRepository();
  48  
  49      $results = array();
  50      foreach ($request->getValue('paths') as $path => $commit) {
  51        $history_result = DiffusionQuery::callConduitWithDiffusionRequest(
  52          $request->getUser(),
  53          $drequest,
  54          'diffusion.historyquery',
  55          array(
  56            'commit' => $commit,
  57            'path' => $path,
  58            'limit' => 1,
  59            'offset' => 0,
  60            'needDirectChanges' => true,
  61            'needChildChanges' => true,
  62          ));
  63  
  64        $history_array = DiffusionPathChange::newFromConduit(
  65          $history_result['pathChanges']);
  66        if ($history_array) {
  67          $results[$path] = head($history_array)
  68            ->getCommit()
  69            ->getCommitIdentifier();
  70        }
  71      }
  72  
  73      return $results;
  74    }
  75  
  76    protected function getMercurialResult(ConduitAPIRequest $request) {
  77      $drequest = $this->getDiffusionRequest();
  78      $repository = $drequest->getRepository();
  79  
  80      $paths = $request->getValue('paths');
  81      $results = $this->loadCommitsFromCache($paths);
  82  
  83      foreach ($paths as $path => $commit) {
  84        if (array_key_exists($path, $results)) {
  85          continue;
  86        }
  87  
  88        list($hash) = $repository->execxLocalCommand(
  89          'log --template %s --limit 1 --removed --rev %s -- %s',
  90          '{node}',
  91          hgsprintf('reverse(ancestors(%s))',  $commit),
  92          nonempty(ltrim($path, '/'), '.'));
  93        $results[$path] = trim($hash);
  94      }
  95  
  96      return $results;
  97    }
  98  
  99    private function loadCommitsFromCache(array $map) {
 100      $drequest = $this->getDiffusionRequest();
 101      $repository = $drequest->getRepository();
 102  
 103      $path_map = id(new DiffusionPathIDQuery(array_keys($map)))
 104        ->loadPathIDs();
 105  
 106      $commit_query = id(new DiffusionCommitQuery())
 107        ->setViewer($drequest->getUser())
 108        ->withRepository($repository)
 109        ->withIdentifiers(array_values($map));
 110      $commit_query->execute();
 111  
 112      $commit_map = $commit_query->getIdentifierMap();
 113      $commit_map = mpull($commit_map, 'getID');
 114  
 115      $graph_cache = new PhabricatorRepositoryGraphCache();
 116  
 117      $results = array();
 118      foreach ($map as $path => $commit) {
 119        $path_id = idx($path_map, $path);
 120        if (!$path_id) {
 121          continue;
 122        }
 123        $commit_id = idx($commit_map, $commit);
 124        if (!$commit_id) {
 125          continue;
 126        }
 127  
 128        $cache_result = $graph_cache->loadLastModifiedCommitID(
 129          $commit_id,
 130          $path_id);
 131  
 132        if ($cache_result !== false) {
 133          $results[$path] = $cache_result;
 134        }
 135      }
 136  
 137      if ($results) {
 138        $commits = id(new DiffusionCommitQuery())
 139          ->setViewer($drequest->getUser())
 140          ->withRepository($repository)
 141          ->withIDs($results)
 142          ->execute();
 143        foreach ($results as $path => $id) {
 144          $commit = idx($commits, $id);
 145          if ($commit) {
 146            $results[$path] = $commit->getCommitIdentifier();
 147          } else {
 148            unset($results[$path]);
 149          }
 150        }
 151      }
 152  
 153      return $results;
 154    }
 155  
 156  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1