import
[web.mtrack] / web / changeset.php
1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3
4 include '../inc/common.php';
5
6 MTrackACL::requireAllRights('Browser', 'read');
7
8 $path = mtrack_get_pathinfo(true);
9 $pi = $path;
10 $repo = MTrackSCM::factory($pi);
11
12 MTrackACL::requireAllRights("repo:$repo->repoid", 'read');
13
14 function get_change_data($pi)
15 {
16   $repo = MTrackSCM::factory($pi);
17   $ents = $repo->history(null, 1, 'rev', $pi);
18   $data = new stdclass;
19   if (!count($ents)) {
20     $data->ent = null;
21   } else {
22     $ent = $ents[0];
23     $data->ent = $ent;
24
25     // Determine project from the file list
26     $the_proj = $repo->projectFromPath($ent->files);
27     if ($the_proj > 1) {
28       $proj = MTrackProject::loadById($the_proj);
29       $changelog = $proj->adjust_links($ent->changelog, true);
30     } else {
31       $changelog = $ent->changelog;
32     }
33     $data->changelog = $changelog;
34
35     if (is_array($ent->files)) foreach ($ent->files as $file) {
36       $file->diff = mtrack_diff($repo->diff($file, $ent->rev));
37     }
38   }
39
40   return $data;
41 }
42
43 function get_change_data_relatives($pi, $rev)
44 {
45   $repo = MTrackSCM::factory($pi);
46   $data = new stdclass;
47   list($data->parents, $data->kids) = $repo->getRelatedChanges($rev);
48   return $data;
49 }
50
51 $data = mtrack_cache('get_change_data', array($path), 864000);
52 $ent = $data->ent;
53 if ($ent === null) {
54   throw new Exception("invalid parameters");
55 }
56
57 $rdata = mtrack_cache('get_change_data_relatives', array($path, $ent->rev));
58
59 if (isset($_GET['fmt']) && $_GET['fmt'] == 'diff') {
60   $filename = "$repo->shortname.$ent->rev.diff";
61   header("Content-Type: text/plain; name=\"$filename\"");
62   header("Content-Disposition: attachment; filename=\"$filename\"");
63
64   echo "Changeset: $repo->shortname $ent->rev\n";
65   echo "By: $ent->changeby\n";
66   echo "When: $ent->ctime\n";
67   echo "\n";
68   echo $data->changelog . "\n\n";
69
70   if (is_array($ent->files) && count($ent->files)) {
71     foreach ($ent->files as $id => $file) {
72       echo "$file->status $file->name\n";
73     }
74     echo "\n";
75
76     foreach ($ent->files as $id => $file) {
77       $fpath = $file->name;
78       if ($fpath[0] != '/') $fpath = '/' . $fpath;
79       $diff = $repo->diff($file, $ent->rev);
80       if (is_resource($diff)) {
81         echo stream_get_contents($diff);
82       } elseif (is_array($diff)) {
83         echo join("\n", $diff);
84       } else {
85         echo $diff;
86       }
87     }
88   }
89   exit;
90 }
91
92 mtrack_head("Changeset " . $ent->rev);
93
94 echo "<div class='revinfo'>\n";
95 echo "Revision: $repo->shortname $ent->rev";
96 foreach ($ent->branches as $b) {
97   echo " " . mtrack_branch($b);
98 }
99 foreach ($ent->tags as $t) {
100   echo " " . mtrack_tag($t);
101 }
102 echo "<br>\n";
103
104
105 echo MTrackWiki::format_to_html($data->changelog);
106
107 echo "<div class='changeinfo'>\n";
108 echo mtrack_username($ent->changeby, array('size' => 32)) . "<br>\n";
109 echo mtrack_date($ent->ctime, true) . "<br>\n";
110
111 if (count($rdata->parents)) {
112   echo "Prior:";
113   foreach ($rdata->parents as $p) {
114     echo " " . mtrack_changeset($p, $repo);
115   }
116   echo " ";
117 }
118
119 if (count($rdata->kids)) {
120   echo "Next:";
121   foreach ($rdata->kids as $kid) {
122     echo " " . mtrack_changeset($kid, $repo);
123   }
124 }
125
126 echo "</div>\n";
127 echo "</div>\n";
128
129 if (is_array($ent->files) && count($ent->files)) {
130   echo "<br><br><a href='${ABSWEB}changeset.php$path?fmt=diff'>Download diff</a>";
131   echo "<div class='difffiles'>Affected files:<ul>";
132   foreach ($ent->files as $id => $file) {
133     echo "<li><a href='#d$id'><b>$file->status</b> $file->name</a></li>\n";
134   }
135   echo "</ul></div>";
136
137   foreach ($ent->files as $id => $file) {
138     $fpath = $file->name;
139     if ($fpath[0] != '/') $fpath = '/' . $fpath;
140     echo "<a name='d$id'></a><a href='{$ABSWEB}file.php/{$repo->getBrowseRootName()}$fpath?rev=$ent->rev'>$file</a><br>\n";
141     $diff = $file->diff; // populated in get_change_data
142     if ($diff === null) {
143       echo "No diff available.  File status is <b>$file->status</b><br><br>";
144     } else {
145       echo $diff;
146     }
147   }
148 }
149
150
151 mtrack_foot();
152