added hash_base system (base refs gets stored in the _SESSION)
[phpgitweb.git] / htdocs / lib / CommitLoader.class.php
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;
        }