/**
  * Browse repository
  *
  * @param null
  * @return void
  */
 function browse()
 {
     if ($this->active_repository->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_repository->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     if ($this->active_commit->isNew()) {
         $this->active_commit = $this->active_repository->getLastCommit();
         if (instance_of($this->active_commit, 'Commit')) {
             $this->active_revision = $this->active_commit->getRevision();
         } else {
             flash_error('This repository is not updated yet. You need to update it first before you can browse it.');
             $this->redirectToReferer($this->active_repository->getViewUrl());
         }
         // if
     }
     // if
     $peg_revision = $this->request->get('peg');
     // wireframe stuff
     $this->wireframe->addPageAction(lang('Change Revision'), '#', null, array('id' => 'change_revision'));
     $this->wireframe->addPageAction(lang('Commit History'), $this->active_repository->getHistoryUrl());
     // path info
     $path_info = $this->repository_engine->getInfo($this->active_file, $this->active_revision, false, $peg_revision);
     // file source
     $file_source = file_source_can_be_displayed($path_info['path']) ? $this->repository_engine->cat($this->active_revision, $this->active_file, $peg_revision) : false;
     $file_path_info = pathinfo($this->active_file);
     $parent_directory = array_var($file_path_info, 'dirname', '');
     $latest_revision = $path_info['revision'];
     $file_latest_revision = Commits::findByRevision($latest_revision, $this->active_repository);
     if (!instance_of($file_latest_revision, 'Commit')) {
         $file_latest_revision = $this->active_commit;
     }
     // if
     // check if path is directory or file
     if ($path_info['type'] == 'directory') {
         /**** DIRECTORY ****/
         $this->smarty->assign(array('list' => $this->repository_engine->browse($this->active_revision, $this->active_file, $peg_revision), 'parent_directory' => $parent_directory == "/" ? "" : $parent_directory, 'can_go_up' => array_var($file_path_info, 'basename') !== ''));
         // custom template
         $this->setTemplate(array('module' => SOURCE_MODULE, 'controller' => $this->controller_name, 'template' => 'browse_directory'));
     } else {
         /**** FILE ****/
         $this->smarty->assign(array('lines' => implode("\n", range(1, count($file_source))), 'source' => $file_source !== false ? implode("\n", $file_source) : $file_source));
         // custom template
         $this->setTemplate(array('module' => SOURCE_MODULE, 'controller' => $this->controller_name, 'template' => 'browse_file'));
         js_assign('compare_url', $this->active_repository->getFileCompareUrl($this->active_commit, $this->active_file, $this->request->get('peg')));
     }
     // if
     js_assign('browse_url', $this->active_repository->getBrowseUrl(null, $this->active_file, $this->request->get('peg')));
     // general template vars for both directory and file
     $this->smarty->assign(array('navigation' => $this->repository_engine->linkify($this->active_revision, $this->active_file), 'latest_revision' => $file_latest_revision, 'active_commit' => $this->active_commit, 'active_revision' => $this->active_revision));
 }