0897f5c130754ae24dc45b3f54c9e4d3e65b4ece
[phpgitweb.git] / htdocs / pages / commitdiff.class.php
1 <?php
2 /* commitdiff.class.php - phpgitweb
3  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
4  * 
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License 
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
17  */
18
19 require_once("pages/commit.class.php");
20
21 class page_commitdiff {
22     private $page, $phpgitweb;
23         private $commitid;
24         
25     public function main($phpgitweb, $project) {
26                 $this->phpgitweb = $phpgitweb;
27                 if(!$project)
28                         return new ContentProvider('main', 'err400');
29                 $project['refs'] = $phpgitweb->get_project_loader()->getProjectRefs($project);
30                 $phpgitweb->append_header_nav("commit", null, true);
31                 $phpgitweb->append_title("commit");
32                 
33                 $commit_loader = new CommitLoader($project);
34                 
35                 if(array_key_exists('h', $_GET))
36                         $commitid = $_GET['h'];
37                 else
38                         $commitid = "HEAD";
39                 
40                 $commit = $commit_loader->load($commitid);
41                 if(!$commit)
42                         return new ContentProvider('main', 'err404_object');
43                 
44                 ContentProvider::overall_set('project_head', $commit['id']);
45                 
46                 
47                 $this->page = new ContentProvider('commitdiff', 'main');
48                 $this->page->set('hash', $commit['id']);
49                 $this->page->set('author', htmlentities($commit['author']));
50                 $this->page->set('author_mail', htmlentities($commit['author_mail']));
51                 $this->page->set('author_date', gmdate('r', $commit['author_time']));
52                 $author_local_time = $commit['author_time'] + Tools::parseTimeZone($commit['author_timezone']);
53                 if(gmdate('H', $author_local_time) < 6)
54                         $this->page->set('author_local_date', '<span class="atnight">'.gmdate('H:i', $author_local_time).'</span>');
55                 else
56                         $this->page->set('author_local_date', gmdate('H:i', $author_local_time));
57                 $this->page->set('author_timezone', $commit['author_timezone']);
58                 $this->page->set('committer', htmlentities($commit['committer']));
59                 $this->page->set('committer_mail', htmlentities($commit['committer_mail']));
60                 $this->page->set('committer_date', gmdate('r', $commit['committer_time']));
61                 $committer_local_time = $commit['committer_time'] + Tools::parseTimeZone($commit['committer_timezone']);
62                 if(gmdate('H', $committer_local_time) < 6)
63                         $this->page->set('committer_local_date', '<span class="atnight">'.gmdate('H:i', $committer_local_time).'</span>');
64                 else
65                         $this->page->set('committer_local_date', gmdate('H:i', $committer_local_time));
66                 $this->page->set('committer_timezone', $commit['committer_timezone']);
67                 $this->page->set('message', htmlentities(Tools::chop_text($commit['text'], 80, 5)));
68                 
69                 
70                 $refs = new ContentProvider('commit', 'commit_refs');
71                 $found = false;
72                 foreach($project['refs'] as $ref => $rhash) {
73                         if(strtolower($rhash) == strtolower($commit['id'])) {
74                                 $refexp = explode('/', $ref, 3);
75                                 $reftype = $refexp[1];
76                                 if($reftype == 'heads')
77                                         $reftype = 'head';
78                                 else if($reftype == 'remotes')
79                                         $reftype = 'remote';
80                                 else if($reftype == 'tags')
81                                         $reftype = 'tag';
82                                 $refs->append('refs', new ContentProvider('commit', 'commit_ref_'.$reftype, array("name" => $refexp[2], "ref_link" => $ref)));
83                                 $found = true;
84                         }
85                 }
86                 $this->page->set('refs', ($found ? $refs : ""));
87                 
88                 $difftree = new difftree();
89                 $diff_data = GitCommand::get_commit_diff($project['path'], $commit['id'], $commit['parent']);
90                 $difftree->push_difftree_data($diff_data['tree']);
91                 $this->page->set('difftree', $difftree->generate_difftree($project, $commit, true));
92                 
93                 
94                 
95                 return $this->page;
96         }
97 }
98
99 ?>