Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/view/DifferentialTransactionView.php
12256 views
1
<?php
2
3
final class DifferentialTransactionView
4
extends PhabricatorApplicationTransactionView {
5
6
private $changesets = array();
7
private $revision;
8
private $rightDiff;
9
private $leftDiff;
10
11
public function setLeftDiff(DifferentialDiff $left_diff) {
12
$this->leftDiff = $left_diff;
13
return $this;
14
}
15
16
public function getLeftDiff() {
17
return $this->leftDiff;
18
}
19
20
public function setRightDiff(DifferentialDiff $right_diff) {
21
$this->rightDiff = $right_diff;
22
return $this;
23
}
24
25
public function getRightDiff() {
26
return $this->rightDiff;
27
}
28
29
public function setRevision(DifferentialRevision $revision) {
30
$this->revision = $revision;
31
return $this;
32
}
33
34
public function getRevision() {
35
return $this->revision;
36
}
37
38
public function setChangesets(array $changesets) {
39
assert_instances_of($changesets, 'DifferentialChangeset');
40
$this->changesets = $changesets;
41
return $this;
42
}
43
44
public function getChangesets() {
45
return $this->changesets;
46
}
47
48
// TODO: There's a whole lot of code duplication between this and
49
// PholioTransactionView to handle inlines. Merge this into the core? Some of
50
// it can probably be shared, while other parts are trickier.
51
52
protected function shouldGroupTransactions(
53
PhabricatorApplicationTransaction $u,
54
PhabricatorApplicationTransaction $v) {
55
56
if ($u->getAuthorPHID() != $v->getAuthorPHID()) {
57
// Don't group transactions by different authors.
58
return false;
59
}
60
61
if (($v->getDateCreated() - $u->getDateCreated()) > 60) {
62
// Don't group if transactions that happened more than 60s apart.
63
return false;
64
}
65
66
switch ($u->getTransactionType()) {
67
case PhabricatorTransactions::TYPE_COMMENT:
68
case DifferentialTransaction::TYPE_INLINE:
69
break;
70
default:
71
return false;
72
}
73
74
switch ($v->getTransactionType()) {
75
case DifferentialTransaction::TYPE_INLINE:
76
return true;
77
}
78
79
return parent::shouldGroupTransactions($u, $v);
80
}
81
82
protected function renderTransactionContent(
83
PhabricatorApplicationTransaction $xaction) {
84
85
$out = array();
86
87
$type_inline = DifferentialTransaction::TYPE_INLINE;
88
89
$group = $xaction->getTransactionGroup();
90
if ($xaction->getTransactionType() == $type_inline) {
91
array_unshift($group, $xaction);
92
} else {
93
$out[] = parent::renderTransactionContent($xaction);
94
}
95
96
// If we're rendering a preview, we show the inline comments in a separate
97
// section underneath the main transaction preview, so we skip rendering
98
// them in the preview body.
99
if ($this->getIsPreview()) {
100
return $out;
101
}
102
103
if (!$group) {
104
return $out;
105
}
106
107
$inlines = array();
108
foreach ($group as $xaction) {
109
switch ($xaction->getTransactionType()) {
110
case DifferentialTransaction::TYPE_INLINE:
111
$inlines[] = $xaction;
112
break;
113
default:
114
throw new Exception(pht('Unknown grouped transaction type!'));
115
}
116
}
117
118
if ($inlines) {
119
$inline_view = new PhabricatorInlineSummaryView();
120
121
$changesets = $this->getChangesets();
122
123
$inline_groups = DifferentialTransactionComment::sortAndGroupInlines(
124
$inlines,
125
$changesets);
126
foreach ($inline_groups as $changeset_id => $group) {
127
$changeset = $changesets[$changeset_id];
128
$items = array();
129
foreach ($group as $inline) {
130
$comment = $inline->getComment();
131
$item = array(
132
'id' => $comment->getID(),
133
'line' => $comment->getLineNumber(),
134
'length' => $comment->getLineLength(),
135
'content' => parent::renderTransactionContent($inline),
136
);
137
138
$changeset_diff_id = $changeset->getDiffID();
139
if ($comment->getIsNewFile()) {
140
$visible_diff_id = $this->getRightDiff()->getID();
141
} else {
142
$visible_diff_id = $this->getLeftDiff()->getID();
143
}
144
145
// TODO: We still get one edge case wrong here, when we have a
146
// versus diff and the file didn't exist in the old version. The
147
// comment is visible because we show the left side of the target
148
// diff when there's no corresponding file in the versus diff, but
149
// we incorrectly link it off-page.
150
151
$is_visible = ($changeset_diff_id == $visible_diff_id);
152
if (!$is_visible) {
153
$revision_id = $this->getRevision()->getID();
154
$comment_id = $comment->getID();
155
$item['href'] =
156
'/D'.$revision_id.
157
'?id='.$changeset_diff_id.
158
'#inline-'.$comment_id;
159
$item['where'] = pht('(On Diff #%d)', $changeset_diff_id);
160
}
161
162
$items[] = $item;
163
}
164
$inline_view->addCommentGroup(
165
$changeset->getFilename(),
166
$items);
167
}
168
169
$out[] = $inline_view;
170
}
171
172
return $out;
173
}
174
175
}
176
177