Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/controller/DiffusionRefTableController.php
12242 views
1
<?php
2
3
final class DiffusionRefTableController extends DiffusionController {
4
5
public function shouldAllowPublic() {
6
return true;
7
}
8
9
public function handleRequest(AphrontRequest $request) {
10
$response = $this->loadDiffusionContext();
11
if ($response) {
12
return $response;
13
}
14
15
$viewer = $this->getViewer();
16
$drequest = $this->getDiffusionRequest();
17
$repository = $drequest->getRepository();
18
19
if (!$drequest->supportsBranches()) {
20
return $this->newDialog()
21
->setTitle(pht('No Ref Support'))
22
->appendParagraph(
23
pht(
24
'The version control system this repository uses does not '.
25
'support named references, so you can not resolve or list '.
26
'repository refs in this repository.'))
27
->addCancelButton($repository->getURI());
28
}
29
30
$ref_name = $drequest->getBranch();
31
32
$cache_query = id(new DiffusionCachedResolveRefsQuery())
33
->setRepository($repository);
34
if ($ref_name !== null) {
35
$cache_query->withRefs(array($ref_name));
36
}
37
$cache_refs = $cache_query->execute();
38
39
$vcs_refs = DiffusionQuery::callConduitWithDiffusionRequest(
40
$viewer,
41
$drequest,
42
'diffusion.resolverefs',
43
array(
44
'refs' => array($ref_name),
45
));
46
47
$all = array();
48
foreach ($cache_refs as $ref => $results) {
49
foreach ($results as $result) {
50
$id = $result['type'].'/'.$result['identifier'];
51
$all[$ref][$id]['cache'] = $result;
52
}
53
}
54
55
foreach ($vcs_refs as $ref => $results) {
56
foreach ($results as $result) {
57
$id = $result['type'].'/'.$result['identifier'];
58
$all[$ref][$id]['vcs'] = $result;
59
}
60
}
61
62
$rows = array();
63
foreach ($all as $ref => $results) {
64
foreach ($results as $info) {
65
$cache = idx($info, 'cache', array());
66
$vcs = idx($info, 'vcs', array());
67
68
$type = idx($vcs, 'type');
69
if (!$type) {
70
$type = idx($cache, 'type');
71
}
72
73
$hash = idx($vcs, 'identifier');
74
if ($hash !== null) {
75
$hash = DiffusionView::linkCommit(
76
$repository,
77
$hash);
78
}
79
80
$cached_hash = idx($cache, 'identifier');
81
if ($cached_hash !== null) {
82
$cached_hash = DiffusionView::linkCommit(
83
$repository,
84
$cached_hash);
85
}
86
87
$closed = idx($vcs, 'closed', false);
88
if (!$vcs) {
89
$state = null;
90
} else {
91
$state = $closed ? pht('Closed') : pht('Open');
92
}
93
94
$cached_closed = idx($cache, 'closed', false);
95
if (!$cache) {
96
$cached_state = null;
97
} else {
98
$cached_state = $cached_closed ? pht('Closed') : pht('Open');
99
}
100
101
$alternate = idx($vcs, 'alternate');
102
if ($alternate !== null) {
103
$alternate = DiffusionView::linkCommit(
104
$repository,
105
$alternate);
106
}
107
108
$rows[] = array(
109
$ref,
110
$type,
111
$hash,
112
$cached_hash,
113
$state,
114
$cached_state,
115
$alternate,
116
);
117
}
118
}
119
120
$table = id(new AphrontTableView($rows))
121
->setHeaders(
122
array(
123
pht('Ref'),
124
pht('Type'),
125
pht('Hash'),
126
pht('Cached Hash'),
127
pht('State'),
128
pht('Cached State'),
129
pht('Alternate'),
130
));
131
132
$content = id(new PHUIObjectBoxView())
133
->setHeaderText(pht('Ref "%s"', $ref_name))
134
->setTable($table);
135
136
$crumbs = $this->buildCrumbs(array());
137
$crumbs->addTextCrumb(pht('Refs'));
138
139
return $this->newPage()
140
->setTitle(
141
array(
142
$ref_name,
143
pht('Ref'),
144
$repository->getDisplayName(),
145
))
146
->setCrumbs($crumbs)
147
->appendChild($content);
148
}
149
150
}
151
152