better checking on hash
[web.mtrack] / MTrackWeb / Browse.php
index ebcdcf7..ac29c99 100644 (file)
@@ -68,6 +68,11 @@ class MTrackWeb_Browse extends MTrackWeb
         if (!$this->repo->id) {
             $this->repo = false;
         }
+        // if we have an active project.. enforce it..
+        if ($this->currentProject() && $this->repo &&  $this->repo->project_id != $this->currentProject()) {
+            $this->repo =  false; // no repo..
+        }
+        
         
         $this->object = null;
         $this->ident = null;
@@ -253,6 +258,10 @@ class MTrackWeb_Browse extends MTrackWeb
         } else {
             $do->orderBy("shortname ASC");
         }
+        
+        if ($this->currentProject()) {
+            $do->project_id = $this->currentProject();
+        }
 // FIXME -> permissions on repositories goes here.. 
         //$do->ensurePerm($this->authUser); 
         //$do->fetchAll();
@@ -309,15 +318,16 @@ class MTrackWeb_Browse extends MTrackWeb
         if ($repo) {
             //try {
             $ents = $repo->readdir($pi, $object, $ident);
-            if ($hashes == false) { 
+            if ($hashes === false) { 
                 $ents = $this->cachedChangeEvent($ents);
             } else {
-                $ents = $this->cachedChangeEventFill($ents, $hashes);
-                return $ents;
+                // we are filling the cache..
+                return $this->cachedChangeEventFill($ents, $hashes);
+                 
             }
             
             foreach ($ents as $file) {
-                if (!is_a($file, 'MTrackEvent')) {
+                if (isset($file->hash)) {
                     $needLog[] = $file->hash;
                 }
                 
@@ -344,6 +354,7 @@ class MTrackWeb_Browse extends MTrackWeb
     }
     /**
      * New version of Directory listing
+     * Basically fetching the last change is very slow...
      *  - 1st run through -> fetch all the change events that we have
      *  for ones we do not have, fetch them later..
      *
@@ -355,7 +366,10 @@ class MTrackWeb_Browse extends MTrackWeb
         $map = array();
         foreach($ar as $e) {
             $e->basename = basename($e->name);
+            // remove e->rev as it's not valid..
+            $e->rev = false;
             $map[$e->hash] = $e;
+            
         }
         
         $q = DB_DataObject::factory('mtrack_clcache');
@@ -365,8 +379,14 @@ class MTrackWeb_Browse extends MTrackWeb
         $impl = $this->repo->impl();
         
         foreach($revs as $hash => $sobject) {
-            $event = $impl->commitLogToEvent($sobject);             
-            $map[$hash] =  $impl->commitLogToEvent($sobject); // this was previous only done for directories??? why???
+            $event = $impl->commitLogToEvent($sobject);
+            // add something??? 
+            if (isset($map[$hash]) && is_object($map[$hash])) {
+                $event->is_dir = $map[$hash]->is_dir;
+                $event->name = $map[$hash]->name;
+                $event->basename = $map[$hash]->basename;
+            }
+            $map[$hash] =  $event; // this was previous only done for directories??? why???
         }
         return array_values($map);
     }
@@ -374,19 +394,63 @@ class MTrackWeb_Browse extends MTrackWeb
     function cachedChangeEventFill($ar,$hashes)
     {
         $map = array();
+        $impl = $this->repo->impl();
+                
         foreach($ar as $e) {
             if (!in_array($e->hash,$hashes)) {
                 continue;
             }
-            $map[$e->hash] = $e;
+            
+            // there is a small chance that concurrent users are looking for the same info..
+            $q = DB_DataObject::factory('mtrack_clcache');
+            $q->rev = $e->hash;
+            $q->repo_id = $this->repo->id;
+            
+            if ($q->find(true)) {
+                $event = $impl->commitLogToEvent($q->sobject);
+            } else { 
+                $ent = $this->repo->history($e->name, 1, 'rev', $e->rev);
+                
+                
+                if (!$ent) {
+                    continue;
+                }
+                $event = $ent[0];
+                // cache it..
+                $q = DB_DataObject::factory('mtrack_clcache');
+                $q->rev = $e->hash;
+                $q->repo_id = $this->repo->id;
+                $q->sobject = $event->commit;
+                $q->insert();
+            }
+            
+            // only copy a few essentials from ent, as we will send it back via json.
+            // these all need escaoing..
+            $add = new stdClass;
+            $add->changelog = $event->changelogOneToHtml($this->link);
+            $add->age = $event->ctimeToHtml($this->link);
+            $add->basename = basename($e->name);
+            $add->changeby = htmlspecialchars($event->changeby); 
+            $add->rev = '<a class="changesetlink browse-link"  href="'. 
+                        htmlspecialchars($this->baseURL) .
+                        '/Changeset/' .
+                        htmlspecialchars($this->repo->displayName()). 
+                        '/'.
+                        htmlspecialchars($event->rev) .
+                        '">'.
+                        htmlspecialchars($event->rev) .
+                        '</a>';
+            
+            $map[$e->hash] = $add;
+            
+            
         }
-        
-        
+        return $map;
         
         
     
     }
-    function post()
+    function post($pi)
     {
         $this->pi =  $pi . (strlen($pi) ? $this->bootLoader->ext : '');