X-Git-Url: http://git.pk910.de/?p=phpgitweb.git;a=blobdiff_plain;f=htdocs%2Flib%2FPageClasses.shortlog.class.php;fp=htdocs%2Flib%2FPageClasses.shortlog.class.php;h=75573f28abde66f1b9d6cc20eb3e10ecb332f0b9;hp=0000000000000000000000000000000000000000;hb=780b7fde2894a42749ac292fa3d180147afeff1a;hpb=a2a32a9c8fe1f0f5f378ed53090dc5f957c092af diff --git a/htdocs/lib/PageClasses.shortlog.class.php b/htdocs/lib/PageClasses.shortlog.class.php new file mode 100644 index 0000000..75573f2 --- /dev/null +++ b/htdocs/lib/PageClasses.shortlog.class.php @@ -0,0 +1,143 @@ +. + */ + +class shortlog { + private $project; + private $graph_data; + private $first_commit; + private $have_more = false; + + public function generate_shortlog($project, $head, $max, $skip, $file = null, $pages = true, $next_page = 0) { + $this->project = $project; + if($head && strtolower($head) == 'all') + $head = null; + $content = new ContentProvider('shortlog', 'shortlog'); + + if(GitConfig::GITGRAPH_ENABLE) { + if($max+$skip >= 2000) { //only load the last 2k commits + $real_skip = ($max+$skip) - 2000; + $skip -= $real_skip; + } else + $real_skip = 0; + } else { + $real_skip = $skip; + $skip = 0; + } + + $commits = GitCommand::get_commits($project['path'], $head, $max+$skip+1, $real_skip, $file); + + if(GitConfig::GITGRAPH_ENABLE) { + $this->graph_data = new graph_data_generator(); + if($head == null) { + //add all refs to the graph + $rhash = GitCommand::get_hash($project['path'], "HEAD"); + if($rhash) + $this->graph_data->add_branch($rhash, null); + + foreach($this->project['refs'] as $ref => $rhash) { + if(preg_match('#^refs/heads/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) { + $this->graph_data->add_branch($rhash, $ref); + } + } + foreach($this->project['refs'] as $ref => $rhash) { + if(preg_match('#^refs/remotes/#i', $ref) && preg_match('/^[a-f0-9]*$/i', $rhash)) { + $this->graph_data->add_branch($rhash, $ref); + } + } + } + $this->graph_data->parse($commits); + $content->set('graph_data', $this->graph_data->get_header_graph()); + } + + $commit_counter = 0; + $this->first_commit = $commits[0]; + foreach($commits as $commit) { + $commit_counter++; + if($commit_counter <= $skip) + continue; + if($commit_counter > $max+$skip) { + $this->have_more = true; + if($pages) { + $content->append('entries', new ContentProvider('shortlog', 'shortlog_page', array("page" => $next_page))); + } else + $content->append('entries', new ContentProvider('shortlog', 'shortlog_more')); + } else + $content->append('entries', $this->shortlog_entry(($commit_counter % 2 ? 'dark' : 'light'), $commit)); + } + + return $content; + } + + public function get_first_commit() { + return $this->first_commit; + } + + public function get_have_more() { + return $this->have_more; + } + + private function shortlog_entry($class, $commit) { + $entry = new ContentProvider('shortlog', 'shortlog_entry'); + $entry->set('class', $class); + $entry->set('hash', $commit['id']); + $entry->set('author', htmlentities($commit['author'])); + $entry->set('message', htmlentities(Tools::chop_text($commit['text'], 50, 5))); + $age = time() - $commit['committer_time']; + $date_str = date("Y-m-d", ($commit['committer_time'] ? $commit['committer_time'] : $commit['author_time'])); + $age_calc = Tools::age_calculate($commit['committer_time']); + $age_str = $age_calc['age_str']; + if($age > 60*60*24*7*2) { + $entry->set('date', $age_str); + $entry->set('age', $date_str); + } else { + $entry->set('date', $date_str); + $entry->set('age', $age_str); + } + if(GitConfig::GITGRAPH_ENABLE) + $entry->set('graph_data', $this->graph_data->get_graph($commit['id'])); + + $entry->set('refs', $this->shortlog_commit_refs($this->project, $commit['id'])); + + return $entry; + } + + public function shortlog_commit_refs($project, $hash) { + if(!is_array($project['refs'])) + return ""; + $refs = new ContentProvider('shortlog', 'shortlog_refs'); + $found = false; + foreach($project['refs'] as $ref => $rhash) { + if(strtolower($rhash) == strtolower($hash)) { + $refexp = explode('/', $ref, 3); + $reftype = $refexp[1]; + if($reftype == 'heads') + $reftype = 'head'; + else if($reftype == 'remotes') + $reftype = 'remote'; + else if($reftype == 'tags') + $reftype = 'tag'; + $refs->append('refs', new ContentProvider('shortlog', 'shortlog_ref_'.$reftype, array("name" => $refexp[2], "ref_link" => $ref))); + $found = true; + } + } + return ($found ? $refs : ""); + } + +} + +?> \ No newline at end of file