~ubuntu-branches/ubuntu/wily/phabricator/wily

« back to all changes in this revision

Viewing changes to src/differential/ArcanistDifferentialDependencyGraph.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-11-01 23:20:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20141101232006-mvlnp0cil67tsboe
Tags: upstream-0~git20141101/arcanist
Import upstream version 0~git20141101, component arcanist

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
final class ArcanistDifferentialDependencyGraph extends AbstractDirectedGraph {
 
4
 
 
5
  private $repositoryAPI;
 
6
  private $conduit;
 
7
  private $startPHID;
 
8
 
 
9
  public function setStartPHID($start_phid) {
 
10
    $this->startPHID = $start_phid;
 
11
    return $this;
 
12
  }
 
13
  public function getStartPHID() {
 
14
    return $this->startPHID;
 
15
  }
 
16
 
 
17
  public function setRepositoryAPI(ArcanistRepositoryAPI $repository_api) {
 
18
    $this->repositoryAPI = $repository_api;
 
19
    return $this;
 
20
  }
 
21
  public function getRepositoryAPI() {
 
22
    return $this->repositoryAPI;
 
23
  }
 
24
 
 
25
  public function setConduit(ConduitClient $conduit) {
 
26
    $this->conduit = $conduit;
 
27
    return $this;
 
28
  }
 
29
  public function getConduit() {
 
30
    return $this->conduit;
 
31
  }
 
32
 
 
33
  protected function loadEdges(array $nodes) {
 
34
    $repository_api = $this->getRepositoryAPI();
 
35
 
 
36
    $dependencies = $this->getConduit()->callMethodSynchronous(
 
37
      'differential.query',
 
38
      array(
 
39
        'phids' => $nodes,
 
40
      ));
 
41
 
 
42
    $edges = array();
 
43
    foreach ($dependencies as $dependency) {
 
44
      $dependency_revision = $this->getCommitHashFromDict($dependency);
 
45
      if ($repository_api->hasLocalCommit($dependency_revision)) {
 
46
        $edges[$dependency['phid']] = array();
 
47
        continue;
 
48
      }
 
49
      $auxillary = idx($dependency, 'auxiliary', array());
 
50
      $edges[$dependency['phid']] = idx(
 
51
        $auxillary,
 
52
        'phabricator:depends-on',
 
53
        array());
 
54
    }
 
55
    return $edges;
 
56
  }
 
57
 
 
58
  private function getCommitHashFromDict($dict) {
 
59
    $api = $this->getRepositoryAPI();
 
60
    $hashes = idx($dict, 'hashes', array());
 
61
    if ($api instanceof ArcanistGitAPI) {
 
62
      $key = ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT;
 
63
    } else if ($api instanceof ArcanistMercurialAPI) {
 
64
      $key = ArcanistDifferentialRevisionHash::HASH_MERCURIAL_COMMIT;
 
65
    } else {
 
66
      $key = null;
 
67
    }
 
68
 
 
69
    return idx($hashes, $key);
 
70
  }
 
71
 
 
72
}