From: pk910 Date: Fri, 15 Feb 2013 15:57:20 +0000 (+0100) Subject: added hash_base system (base refs gets stored in the _SESSION) X-Git-Url: http://git.pk910.de/?p=phpgitweb.git;a=commitdiff_plain;h=b400fe63ce2c5db919a479101e8b261f479e8d0b added hash_base system (base refs gets stored in the _SESSION) --- diff --git a/htdocs/lib/CommitLoader.class.php b/htdocs/lib/CommitLoader.class.php index d6e822c..64fc898 100644 --- a/htdocs/lib/CommitLoader.class.php +++ b/htdocs/lib/CommitLoader.class.php @@ -17,17 +17,46 @@ */ class CommitLoader { + public static $commit_id, $commit_base_id; private $project; + public static function parse($log_page = false) { + if(array_key_exists('h', $_GET) && Validation::validate_hash($_GET['h'])) + $commit_id = $_GET['h']; + else + $commit_id = "all"; + + if(array_key_exists('hb', $_GET) && Validation::validate_hash($_GET['hb'])) + $commit_base_id = $_GET['hb']; + else if(!$log_page && $_SESSION['hb']) + $commit_base_id = $_SESSION['hb']; + else + $commit_base_id = $commit_id; + + if($log_page) + $_SESSION['hb'] = $commit_base_id; + + ContentProvider::overall_set('commit_base_id', $commit_base_id); + ContentProvider::overall_set('commit_id', $commit_id); + + self::$commit_id = $commit_id; + self::$commit_base_id = $commit_base_id; + return array('id' => $commit_id, 'base_id' => $commit_base_id); + } + public function __construct($project) { $this->project = $project; } - public function load($id) { - if(!Validation::validate_hash($id)) { + public function load($id = null) { + if(!$id && self::$commit_id) + $id = self::$commit_id; + else if(!Validation::validate_hash($id)) { trigger_error("Invalid hash parameter", E_USER_ERROR); return false; } + if(strtolower($id) == 'all') + $id = null; $commit = GitCommand::get_commit($this->project['path'], $id); return $commit; } diff --git a/htdocs/lib/ContentProvider.class.php b/htdocs/lib/ContentProvider.class.php index a32a37f..76b2eb0 100644 --- a/htdocs/lib/ContentProvider.class.php +++ b/htdocs/lib/ContentProvider.class.php @@ -113,6 +113,7 @@ class ContentProvider { $template_html = $this->load_template($this->template, $subtemplate); } $template_html = preg_replace_callback('/%([^%]*)%/', array($this, "replace_placeholder"), $template_html); + $template_html = preg_replace_callback('/%([^%]*)%/', array($this, "replace_placeholder"), $template_html); return $template_html; } diff --git a/htdocs/lib/GitCommand.class.php b/htdocs/lib/GitCommand.class.php index a8ede91..1e4b07f 100644 --- a/htdocs/lib/GitCommand.class.php +++ b/htdocs/lib/GitCommand.class.php @@ -124,7 +124,7 @@ class GitCommand { } public static function get_commit($git_path, $commit_id) { - $args = array("rev-list", "--header", "--max-count=1", $commit_id, "--"); + $args = array("rev-list", "--header", "--max-count=1", ($commit_id ? $commit_id : "--all"), "--"); $commit_data = self::git_execute($args, $git_path); $commit = self::parse_commit($commit_data); return $commit; diff --git a/htdocs/lib/PHPGitWeb.class.php b/htdocs/lib/PHPGitWeb.class.php index 5789d1f..dee9292 100644 --- a/htdocs/lib/PHPGitWeb.class.php +++ b/htdocs/lib/PHPGitWeb.class.php @@ -31,6 +31,7 @@ class PHPGitWeb { public function __construct() { $this->rendertime = microtime(true); + session_start(); $this->page = new ContentProvider('main', 'main'); set_error_handler(array($this, "error_handler")); $this->append_header_nav('projects', '?a=projects', false); @@ -51,7 +52,8 @@ class PHPGitWeb { $this->page->append('content', new ContentProvider('main', 'err404_project')); else { ContentProvider::overall_set('project', $this->project['name']); - ContentProvider::overall_set('project_head', "HEAD"); + ContentProvider::overall_set('commit_base_id', "all"); + ContentProvider::overall_set('commit_id', "HEAD"); $this->append_header_nav($this->project['name'], '?p='.$this->project['name'].'&a=summary', true); $this->append_title(" - ".$this->project['name'], false); $this->project_header = new ContentProvider('main', 'project_header'); @@ -77,12 +79,12 @@ class PHPGitWeb { } else $this->page->append('content', file_get_contents('pages/404.html')); if($this->project_header) { - $this->project_header->set('nav_summary', new ContentProvider('main', ($page == 'summary' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "summary", 'link' => "summary"))); - $this->project_header->set('nav_shortlog', new ContentProvider('main', ($page == 'shortlog' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "shortlog", 'link' => "shortlog"))); - $this->project_header->set('nav_log', new ContentProvider('main', ($page == 'log' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "log", 'link' => "log"))); - $this->project_header->set('nav_commit', new ContentProvider('main', ($page == 'commit' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "commit", 'link' => "commit"))); - $this->project_header->set('nav_commitdiff', new ContentProvider('main', ($page == 'commitdiff' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "commitdiff", 'link' => "commitdiff"))); - $this->project_header->set('nav_tree', new ContentProvider('main', ($page == 'tree' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "tree", 'link' => "tree"))); + $this->project_header->set('nav_summary', new ContentProvider('main', ($page == 'summary' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "summary", 'link' => "summary", 'link_add' => ""))); + $this->project_header->set('nav_shortlog', new ContentProvider('main', ($page == 'shortlog' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "shortlog", 'link' => "shortlog", 'link_add' => "&h=%commit_base_id%"))); + $this->project_header->set('nav_log', new ContentProvider('main', ($page == 'log' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "log", 'link' => "log", 'link_add' => "&h=%commit_base_id%"))); + $this->project_header->set('nav_commit', new ContentProvider('main', ($page == 'commit' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "commit", 'link' => "commit", 'link_add' => "&h=%commit_id%"))); + $this->project_header->set('nav_commitdiff', new ContentProvider('main', ($page == 'commitdiff' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "commitdiff", 'link' => "commitdiff", 'link_add' => "&h=%commit_id%"))); + $this->project_header->set('nav_tree', new ContentProvider('main', ($page == 'tree' ? 'project_header_nav_active' : 'project_header_nav_link'), array('name' => "tree", 'link' => "tree", 'link_add' => "&h=%commit_id%"))); } } diff --git a/htdocs/pages/commit.class.php b/htdocs/pages/commit.class.php index 389efaa..57f20e5 100644 --- a/htdocs/pages/commit.class.php +++ b/htdocs/pages/commit.class.php @@ -180,7 +180,6 @@ class difftree { class page_commit { private $page, $phpgitweb; - private $commitid; public function main($phpgitweb, $project) { $this->phpgitweb = $phpgitweb; @@ -189,19 +188,14 @@ class page_commit { $project['refs'] = $phpgitweb->get_project_loader()->getProjectRefs($project); $phpgitweb->append_header_nav("commit", null, true); $phpgitweb->append_title("commit"); + CommitLoader::parse(); $commit_loader = new CommitLoader($project); - - if(array_key_exists('h', $_GET)) - $commitid = $_GET['h']; - else - $commitid = "HEAD"; - - $commit = $commit_loader->load($commitid); + $commit = $commit_loader->load(); if(!$commit) return new ContentProvider('main', 'err404_object'); - ContentProvider::overall_set('project_head', $commit['id']); + ContentProvider::overall_set('commit_id', $commit['id']); $this->page = new ContentProvider('commit', 'main'); diff --git a/htdocs/pages/commitdiff.class.php b/htdocs/pages/commitdiff.class.php index 0897f5c..5ef3fa0 100644 --- a/htdocs/pages/commitdiff.class.php +++ b/htdocs/pages/commitdiff.class.php @@ -20,7 +20,6 @@ require_once("pages/commit.class.php"); class page_commitdiff { private $page, $phpgitweb; - private $commitid; public function main($phpgitweb, $project) { $this->phpgitweb = $phpgitweb; @@ -29,15 +28,10 @@ class page_commitdiff { $project['refs'] = $phpgitweb->get_project_loader()->getProjectRefs($project); $phpgitweb->append_header_nav("commit", null, true); $phpgitweb->append_title("commit"); + CommitLoader::parse(); $commit_loader = new CommitLoader($project); - - if(array_key_exists('h', $_GET)) - $commitid = $_GET['h']; - else - $commitid = "HEAD"; - - $commit = $commit_loader->load($commitid); + $commit = $commit_loader->load(); if(!$commit) return new ContentProvider('main', 'err404_object'); diff --git a/htdocs/pages/shortlog.class.php b/htdocs/pages/shortlog.class.php index 0bd823f..8e69ffd 100644 --- a/htdocs/pages/shortlog.class.php +++ b/htdocs/pages/shortlog.class.php @@ -26,6 +26,8 @@ class shortlog { 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) { @@ -152,6 +154,7 @@ class page_shortlog { $project['refs'] = $phpgitweb->get_project_loader()->getProjectRefs($project); $phpgitweb->append_header_nav("shortlog", null, true); $phpgitweb->append_title("shortlog"); + CommitLoader::parse(true); $this->page = new ContentProvider('shortlog', 'main'); @@ -180,7 +183,7 @@ class page_shortlog { } $shortlog = new shortlog(); - $this->page->set('shortlog', $shortlog->generate_shortlog($project, null, 100, $skip, null, true, $next_page)); + $this->page->set('shortlog', $shortlog->generate_shortlog($project, CommitLoader::$commit_base_id, 100, $skip, null, true, $next_page)); if($shortlog->get_have_more()) $subnav->set('next', new ContentProvider('shortlog', 'shortlog_subnav_next_link', array('page' => ($pg + 1)))); diff --git a/htdocs/pages/summary.class.php b/htdocs/pages/summary.class.php index 0e3eae6..09bdb4c 100644 --- a/htdocs/pages/summary.class.php +++ b/htdocs/pages/summary.class.php @@ -28,6 +28,7 @@ class page_summary { $project['refs'] = $phpgitweb->get_project_loader()->getProjectRefs($project); $phpgitweb->append_header_nav("summary", null, true); $phpgitweb->append_title("summary"); + CommitLoader::parse(true); $this->page = new ContentProvider('summary', 'main'); diff --git a/htdocs/templates/default/commit.tpl b/htdocs/templates/default/commit.tpl index 6164ed1..9d3aa8f 100644 --- a/htdocs/templates/default/commit.tpl +++ b/htdocs/templates/default/commit.tpl @@ -31,6 +31,9 @@ commit %hash% + + shortlog | log + tree diff --git a/htdocs/templates/default/main.tpl b/htdocs/templates/default/main.tpl index 38f7b58..ae7ea9b 100644 --- a/htdocs/templates/default/main.tpl +++ b/htdocs/templates/default/main.tpl @@ -62,7 +62,7 @@ Rendertime: %rendertime% sec