added hash_base system (base refs gets stored in the _SESSION)
authorpk910 <philipp@zoelle1.de>
Fri, 15 Feb 2013 15:57:20 +0000 (16:57 +0100)
committerpk910 <philipp@zoelle1.de>
Fri, 15 Feb 2013 15:57:20 +0000 (16:57 +0100)
htdocs/lib/CommitLoader.class.php
htdocs/lib/ContentProvider.class.php
htdocs/lib/GitCommand.class.php
htdocs/lib/PHPGitWeb.class.php
htdocs/pages/commit.class.php
htdocs/pages/commitdiff.class.php
htdocs/pages/shortlog.class.php
htdocs/pages/summary.class.php
htdocs/templates/default/commit.tpl
htdocs/templates/default/main.tpl
htdocs/templates/default/shortlog.tpl

index d6e822c2fa3b0058958b782540bcb9ca4f2f3133..64fc898251c623c15db24ac075eae08fd671f693 100644 (file)
  */
 
 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;
        }
index a32a37fb95d92a2593e5e730ca13b74b2dc4cfe9..76b2eb0f1e1a508053a9df9d46d1c8048fbd703a 100644 (file)
@@ -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;
        }
index a8ede915817beaafc0e070ddcb8027248bd8ae2a..1e4b07f6b4c29e4001c22e2bc2031804ea7809ee 100644 (file)
@@ -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;
index 5789d1f098152191c09d38bd4d2f013fd9451d1f..dee929252a051562fee362740df486deb5a7f512 100644 (file)
@@ -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%")));
                }
        }
        
index 389efaabf38acbbc7837f70a8975840bee8a37c8..57f20e5d8b18def5b68871a9bd58e9595cc67956 100644 (file)
@@ -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');
index 0897f5c130754ae24dc45b3f54c9e4d3e65b4ece..5ef3fa05b4e7b95fe165428a87541d6806f22997 100644 (file)
@@ -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');
                
index 0bd823f15b837c66b0eccce332c61beee344ed75..8e69ffd189df1b7a95333d1952b9bc3faa16ef4e 100644 (file)
@@ -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))));
index 0e3eae63ff62a39c88482c0da6f84f306bfef04a..09bdb4caf7836bc4a06e43b45d059208bb79dd83 100644 (file)
@@ -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');
                
index 6164ed1fa8c17b0e342bfc31dfb7732d70761ae4..9d3aa8f11f21a2851d1e59575db7676c091ece7d 100644 (file)
@@ -31,6 +31,9 @@
        <tr>
                <td>commit</td>
                <td class="sha1">%hash%</td>
+               <td class="link">
+                       <a href="?p=%project%&a=shortlog&h=%hash%">shortlog</a> | <a href="?p=%project%&a=log&h=%hash%">log</a>
+               </td>
        </tr>
        <tr>
                <td>tree</td>
index 38f7b5888bdc2f7db4de4b98256bb123cf9e1d9c..ae7ea9b64a146d104722c1e6aafd89854f1a33a3 100644 (file)
@@ -62,7 +62,7 @@ Rendertime: %rendertime% sec
 <div class="search">
 <input name="p" type="hidden" value="%project%" />
 <input name="a" type="hidden" value="search" />
-<input name="h" type="hidden" value="%project_head%" />
+<input name="h" type="hidden" value="%commit_base_id%" />
 <select name="st" >
 <option selected="selected" value="commit">commit</option>
 <option value="grep">grep</option>
@@ -79,7 +79,7 @@ Rendertime: %rendertime% sec
 </div>
 
 # [project_header_nav_link]
-<a href="/?p=%project%&a=%link%&h=%project_head%">%name%</a>
+<a href="/?p=%project%&a=%link%%link_add%">%name%</a>
 
 # [project_header_nav_active]
 %name%
index 424e9bf8259f1aaf12ae06a58000194d14be4763..a88337dd64b6c705b809b8145b152bb93a331efe 100644 (file)
@@ -30,7 +30,7 @@
 </tr>
 
 # [shortlog_page]
-<td colspan="4"><a title="Alt-n" accesskey="n" href="?p=%project%&a=shortlog&pg=%page%">next</a></td>
+<td colspan="4"><a title="Alt-n" accesskey="n" href="?p=%project%&a=shortlog&h=%commit_base_id%&pg=%page%">next</a></td>
 
 # [shortlog_refs]
 <span class="refs"> %refs%</span>
 %first% &sdot; %prev% &sdot; %next%
 
 # [shortlog_subnav_first_link]
-<a href="?p=%project%&a=shortlog">first</a>
+<a href="?p=%project%&a=shortlog&h=%commit_base_id%">first</a>
 
 # [shortlog_subnav_first]
 first
 
 # [shortlog_subnav_prev_link]
-<a title="Alt-p" accesskey="p" href="?p=%project%&a=shortlog&pg=%page%">prev</a>
+<a title="Alt-p" accesskey="p" href="?p=%project%&a=shortlog&h=%commit_base_id%&pg=%page%">prev</a>
 
 # [shortlog_subnav_prev]
 prev
 
 # [shortlog_subnav_next_link]
-<a title="Alt-n" accesskey="n" href="?p=%project%&a=shortlog&pg=%page%">next</a>
+<a title="Alt-n" accesskey="n" href="?p=%project%&a=shortlog&h=%commit_base_id%&pg=%page%">next</a>
 
 # [shortlog_subnav_next]
 next