/
diff.php
120 lines (107 loc) · 4.08 KB
/
diff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
// diff.php -- Peteramati diff page
// HotCRP and Peteramati are Copyright (c) 2006-2019 Eddie Kohler and others
// See LICENSE for open-source distribution terms
require_once("src/initweb.php");
global $User, $Pset, $Info, $Qreq;
ContactView::set_path_request($Qreq, ["/@", "/@/p", "/@/p/h", "/@/p/h/h", "/p/h/h"], $Conf);
if ($Me->is_empty()) {
$Me->escape();
}
$User = $Me;
if (isset($Qreq->u)
&& !($User = ContactView::prepare_user($Qreq, $Me))) {
$Conf->redirect_self($Qreq, ["u" => null]);
}
assert($User === $Me || $Me->isPC);
$Conf->set_siteinfo("uservalue", $Me->user_linkpart($User));
$Pset = ContactView::find_pset_redirect($Qreq->pset, $Me);
if ($Pset->gitless) {
$Conf->errorMsg("That problem set does not use git.");
$Me->escape(); // XXX stay on this page
}
$Info = PsetView::make($Pset, $User, $Me);
if (!$Info->repo) {
$Conf->errorMsg("No repository.");
$Me->escape(); // XXX stay on this page
}
if (!$Qreq->commit || !$Qreq->commit1) {
if (!$Qreq->commit1) {
$Qreq->commit1 = $Info->hash();
}
if (!$Qreq->commit) {
$Qreq->commit = $Info->derived_handout_hash();
}
if ($Qreq->commit && $Qreq->commit1) {
$Conf->redirect_self($Qreq, ["commit" => $Qreq->commit, "commit1" => $Qreq->commit1]);
} else {
$Me->escape();
}
}
$commita = $Info->find_commit($Qreq->commit);
$commitb = $Info->find_commit($Qreq->commit1);
if (!$commita || !$commitb) {
if (!$commita) {
$Conf->errorMsg("Commit " . htmlspecialchars($Qreq->commit) . " is not connected to your repository.");
}
if (!$commitb) {
$Conf->errorMsg("Commit " . htmlspecialchars($Qreq->commit1) . " is not connected to your repository.");
}
$Me->escape();
}
$Info->set_hash($commitb->hash);
if ($commita->hash === $Info->grading_hash()) {
$commita->subject .= " ✱"; // space, nbsp
}
if ($commitb->hash === $Info->grading_hash()) {
$commitb->subject .= " ✱"; // space, nbsp
}
$Conf->header('<span class="pset-title">' . htmlspecialchars($Pset->title) . '</span>', "home");
ContactView::echo_heading($User, $Me);
$infoj = $Info->info_json();
$infoj["base_commit"] = $commita->hash;
$infoj["base_handout"] = $Pset->is_handout($commita);
echo '<div class="pa-psetinfo" data-pa-pset="', htmlspecialchars($Info->pset->urlkey),
'" data-pa-base-commit="', htmlspecialchars($commita->hash),
'" data-pa-commit="', htmlspecialchars($commitb->hash),
'" data-pa-gradeinfo=\'', json_escape_browser_sqattr($infoj), '\'';
if (!$Pset->gitless && $Pset->directory) {
echo ' data-pa-directory="', htmlspecialchars($Pset->directory_slash), '"';
}
if ($Info->user->extension) {
echo ' data-pa-user-extension="yes"';
}
echo '>';
echo "<table class=\"mb-4\"><tr><td><h2>diff</h2></td><td style=\"padding-left:10px;line-height:110%\">",
"<div class=\"pa-dl pa-gdsamp\" style=\"padding:2px 5px\"><big>",
$Info->commit_link(substr($commita->hash, 0, 7), " " . htmlspecialchars($commita->subject), $commita->hash),
"</big></div><div class=\"pa-dl pa-gisamp\" style=\"padding:2px 5px\"><big>",
$Info->commit_link(substr($commitb->hash, 0, 7), " " . htmlspecialchars($commitb->subject), $commitb->hash),
"</big></div></td></tr></table>";
// collect diff and sort line notes
$lnorder = $Pset->is_handout($commitb) ? $Info->empty_line_notes() : $Info->visible_line_notes();
// print line notes
$notelinks = [];
foreach ($lnorder->seq() as $note) {
if (!$note->is_empty()) {
$notelinks[] = $note->render_line_link_html($Pset);
}
}
if (!empty($notelinks)) {
ContactView::echo_group("notes", join(", ", $notelinks));
}
$diff = $Info->diff($commita, $commitb, $lnorder, [
"no_full" => !$Pset->is_handout($commita) || $Pset->is_handout($commitb),
"no_user_collapse" => true
]);
if ($diff) {
echo '<div class="pa-diffset">';
// diff and line notes
foreach ($diff as $file => $dinfo) {
$Info->echo_file_diff($file, $dinfo, $lnorder, ["only_diff" => true]);
}
echo '</div>';
}
Ht::stash_script('$(window).on("beforeunload",$pa.beforeunload)');
echo "</div><hr class=\"c\" />\n";
$Conf->footer();