diff --git includes/VersioncontrolRepository.php includes/VersioncontrolRepository.php index 40c3291..a27d1ab 100644 --- includes/VersioncontrolRepository.php +++ includes/VersioncontrolRepository.php @@ -112,13 +112,6 @@ abstract class VersioncontrolRepository implements VersioncontrolEntityInterface */ protected $pluginInstances = array(); - /** - * The instance for this repository url handler. - * - * @var VersioncontrolRepositoryUrlHandlerInterface - */ - protected $urlHandler; - protected $defaultCrudOptions = array( 'update' => array('nested' => TRUE), 'insert' => array('nested' => TRUE), @@ -373,18 +366,18 @@ abstract class VersioncontrolRepository implements VersioncontrolEntityInterface * Convinience method to retrieve url handler. */ public function getUrlHandler() { - if (!isset($this->urlHandler)) { + if (!isset($this->pluginInstances['webviewer_url_handler'])) { $plugin = $this->getPlugin('webviewer_url_handler', 'webviewer_url_handlers'); $class_name = ctools_plugin_get_class($plugin, 'handler'); if (!class_exists($class_name)) { throw new Exception("Plugin 'webviewer_url_handler' of type 'webviewer_url_handlers' does not contain a valid class name in handler slot 'handler'", E_WARNING); return FALSE; } - $this->urlHandler = new $class_name( + $this->pluginInstances['webviewer_url_handler'] = new $class_name( $this, $this->data['versioncontrol']['base_url'], $plugin['url_templates'] ); } - return $this->urlHandler; + return $this->pluginInstances['webviewer_url_handler']; } /** @@ -469,187 +462,3 @@ abstract class VersioncontrolRepository implements VersioncontrolEntityInterface } } - -/** - * Base class for URL handlers. - */ -class VersioncontrolRepositoryUrlHandler implements VersioncontrolWebviewerUrlHandlerInterface { - - /** - * Repository where this urls belongs. - * - * @var VersioncontrolRepository - */ - public $repository; - - /** - * The first part of the URL that is going to be prepended to each URL - * retrieved. - * - * @var string - */ - public $baseUrl; - - /** - * An array of template URLs for the web viewer. - * - * @var array - */ - public $templateUrls; - - public function __construct($repository, $base_url, $template_urls) { - $this->repository = $repository; - $this->baseUrl = $base_url; - $this->templateUrls = $template_urls; - } - - public function getTemplateUrl($name) { - return sprintf('%s/%s', $this->baseUrl, $this->templateUrls[$name]); - } - - /** - * Retrieve the URL of the repository viewer that displays the given commit - * in the corresponding repository. - * - * @param $revision - * The revision on the commit operation whose view URL should be retrieved. - * - * @return - * The commit view URL corresponding to the given arguments. - * An empty string is returned if no commit view URL has been defined, - * or if the commit cannot be viewed for any reason. - */ - public function getCommitViewUrl($revision) { - if (empty($revision)) { - return ''; - } - return strtr($this->getTemplateUrl('commit_view'), array( - '%revision' => $revision, - )); - } - - /** - * Retrieve the URL of the repository viewer that displays the commit log - * of the given item in the corresponding repository. If no such URL has been - * specified by the user, the appropriate URL from the Commit Log module is - * used as a fallback (if that module is enabled). - * - * @param $item - * The item whose log view URL should be retrieved. - * - * @return - * The item log view URL corresponding to the given arguments. - * An empty string is returned if no item log view URL has been defined - * (and if not even Commit Log is enabled), or if the item cannot be viewed - * for any reason. - */ - public function getItemLogViewUrl(&$item) { - $label = $item->getSelectedLabel(); - - if (isset($label->type) && $label->type == VERSIONCONTROL_LABEL_BRANCH) { - $current_branch = $label->name; - } - - if (!empty($this->templateUrls['file_log_view'])) { - if ($item->isFile()) { - return strtr($this->getTemplateUrl('file_log_view'), array( - '%path' => $item->path, - '%revision' => $item->revision, - '%branch' => isset($current_branch) ? $current_branch : '', - )); - } - // The default URL backend doesn't do log view URLs for directory items: - return ''; - } - elseif (module_exists('commitlog')) { // fallback, as 'file_log_view' is empty - $query = array( - 'repos' => $item->repository->repo_id, - 'paths' => drupal_urlencode($item->path), - ); - if (isset($current_branch)) { - $query['branches'] = $current_branch; - } - // FIXME change this to current view - return url('commitlog', array( - 'query' => $query, - 'absolute' => TRUE, - )); - } - return ''; // in case we really can't retrieve any sensible URL - } - - /** - * Retrieve the URL of the repository viewer that displays the contents of the - * given item in the corresponding repository. - * - * @param $item - * The item whose view URL should be retrieved. - * - * @return - * The item view URL corresponding to the given arguments. - * An empty string is returned if no item view URL has been defined, - * or if the item cannot be viewed for any reason. - */ - public function getItemViewUrl(&$item) { - $label = $item->getSelectedLabel(); - - if (isset($label->type) && $label->type == VERSIONCONTROL_LABEL_BRANCH) { - $current_branch = $label->name; - } - $view_url = $item->isFile() - ? $this->getTemplateUrl('file_view') - : $this->getTemplateUrl('directory_view'); - - return strtr($view_url, array( - '%path' => $item->path, - '%revision' => $item->revision, - '%branch' => isset($current_branch) ? $current_branch : '', - )); - } - - /** - * Retrieve the URL of the repository viewer that displays the diff between - * two given files in the corresponding repository. - * - * @param $file_item_new - * The new version of the file that should be diffed. - * @param $file_item_old - * The old version of the file that should be diffed. - * - * @return - * The diff URL corresponding to the given arguments. - * An empty string is returned if no diff URL has been defined, - * or if the two items cannot be diffed for any reason. - */ - public function getDiffUrl(&$file_item_new, $file_item_old) { - $label = $file_item_new->getSelectedLabel(); - - if (isset($label->type) && $label->type == VERSIONCONTROL_LABEL_BRANCH) { - $current_branch = $label->name; - } - return strtr($this->getTemplateUrl('diff'), array( - '%path' => $file_item_new->path, - '%new-revision' => $file_item_new->revision, - '%old-path' => $file_item_old->path, - '%old-revision' => $file_item_old->revision, - '%branch' => isset($current_branch) ? $current_branch : '', - )); - } - - /** - * Retrieve the URL of the issue tracker that displays the issue/case/bug page - * of an issue id which presumably has been mentioned in a commit message. - * As issue tracker URLs are specific to each repository, this also needs - * to be given as argument. - * - * @param $issue_id - * A number that uniquely identifies the mentioned issue/case/bug. - * - * @return - * The issue tracker URL corresponding to the given arguments. - * An empty string is returned if no issue tracker URL has been defined. - */ - public function getTrackerUrl($issue_id) { - return strtr($this->getTemplateUrl('tracker'), array('%d' => $issue_id)); - } -} diff --git includes/plugins/webviewer_url_handlers/VersioncontrolRepositoryUrlHandler.inc includes/plugins/webviewer_url_handlers/VersioncontrolRepositoryUrlHandler.inc new file mode 100644 index 0000000..37ac6b7 --- /dev/null +++ includes/plugins/webviewer_url_handlers/VersioncontrolRepositoryUrlHandler.inc @@ -0,0 +1,170 @@ +repository = $repository; + $this->baseUrl = $base_url; + $this->templateUrls = $template_urls; + } + + public function getTemplateUrl($name) { + if (empty($this->templateUrls[$name])) { + return ''; + } + return sprintf('%s/%s', $this->baseUrl, $this->templateUrls[$name]); + } + + /** + * Retrieve the URL of the repository viewer that displays the given commit + * in the corresponding repository. + * + * @param $revision + * The revision on the commit operation whose view URL should be retrieved. + * + * @return + * The commit view URL corresponding to the given arguments. + * An empty string is returned if no commit view URL has been defined, + * or if the commit cannot be viewed for any reason. + */ + public function getCommitViewUrl($revision) { + if (empty($revision)) { + return ''; + } + return strtr($this->getTemplateUrl('commit_view'), array( + '%repo_name' => $this->repository->name, + '%revision' => $revision, + )); + } + + /** + * Retrieve the URL of the repository viewer that displays the commit log + * of the given item in the corresponding repository. If no such URL has been + * specified by the user, the appropriate URL from the Commit Log module is + * used as a fallback (if that module is enabled). + * + * @param $item + * The item whose log view URL should be retrieved. + * + * @return + * The item log view URL corresponding to the given arguments. + * An empty string is returned if no item log view URL has been defined + * (and if not even Commit Log is enabled), or if the item cannot be viewed + * for any reason. + */ + public function getItemLogViewUrl(&$item) { + $label = $item->getSelectedLabel(); + + if (isset($label->type) && $label->type == VERSIONCONTROL_LABEL_BRANCH) { + $current_branch = $label->name; + } + + if ($item->isFile()) { + return strtr($this->getTemplateUrl('file_log_view'), array( + '%repo_name' => $this->repository->name, + '%path' => $item->path, + '%revision' => $item->revision, + '%branch' => isset($current_branch) ? $current_branch : '', + )); + } + else { // directory + return strtr($this->getTemplateUrl('directory_log_view'), array( + '%repo_name' => $this->repository->name, + '%path' => $item->path, + '%revision' => $item->revision, + '%branch' => isset($current_branch) ? $current_branch : '', + )); + } + } + + /** + * Retrieve the URL of the repository viewer that displays the contents of the + * given item in the corresponding repository. + * + * @param $item + * The item whose view URL should be retrieved. + * + * @return + * The item view URL corresponding to the given arguments. + * An empty string is returned if no item view URL has been defined, + * or if the item cannot be viewed for any reason. + */ + public function getItemViewUrl(&$item) { + $label = $item->getSelectedLabel(); + + if (isset($label->type) && $label->type == VERSIONCONTROL_LABEL_BRANCH) { + $current_branch = $label->name; + } + $view_url = $item->isFile() + ? $this->getTemplateUrl('file_view') + : $this->getTemplateUrl('directory_view'); + + return strtr($view_url, array( + '%repo_name' => $this->repository->name, + '%path' => $item->path, + '%revision' => $item->revision, + '%branch' => isset($current_branch) ? $current_branch : '', + )); + } + + /** + * Retrieve the URL of the repository viewer that displays the diff between + * two given files in the corresponding repository. + * + * @param $file_item_new + * The new version of the file that should be diffed. + * @param $file_item_old + * The old version of the file that should be diffed. + * + * @return + * The diff URL corresponding to the given arguments. + * An empty string is returned if no diff URL has been defined, + * or if the two items cannot be diffed for any reason. + */ + public function getDiffUrl(&$file_item_new, $file_item_old) { + $label = $file_item_new->getSelectedLabel(); + + if (isset($label->type) && $label->type == VERSIONCONTROL_LABEL_BRANCH) { + $current_branch = $label->name; + } + return strtr($this->getTemplateUrl('diff'), array( + '%repo_name' => $this->repository->name, + '%path' => $file_item_new->path, + '%new_revision' => $file_item_new->revision, + '%old_path' => $file_item_old->path, + '%old_revision' => $file_item_old->revision, + '%branch' => isset($current_branch) ? $current_branch : '', + )); + } + +} diff --git includes/plugins/webviewer_url_handlers/gitweb.inc includes/plugins/webviewer_url_handlers/gitweb.inc index 2c028bf..6b57378 100644 --- includes/plugins/webviewer_url_handlers/gitweb.inc +++ includes/plugins/webviewer_url_handlers/gitweb.inc @@ -1,108 +1,32 @@ 'git', 'title' => t('Gitweb URL autogenerator'), - /** - * Leave empty the URL template if the web viewer do not support that template. - */ 'url_templates' => array( - - /** - * Template url for the commit view. - * - * The URL of the repository viewer that displays a given commit in the - * repository. - * It contains the following placeholders: - * - "%base_url" the path to gitweb. - * - "%repo_name" the name of the repository on the filesystem. - * - "%revision" for the revision/commit/changeset identifier. - */ 'commit_view' => '%base_url/?p=%repo_name;a=commit;h=%revision', - - /** - * Template url for the file log view. - * - * The URL of the repository viewer that displays the commit log of - * a given file in the repository. - * It contains the following placeholders: - * - "%base_url" the path to gitweb. - * - "%repo_name" the name of the repository on the filesystem. - * - "%path" for the file path - * - "%revision" will be replaced by the file-level revision (the one - * in {versioncontrol_item_revisions}.revision) - * - "%branch" will be replaced by the branch name that the file is on - */ 'file_log_view' => '%base_url/?p=%repo_name;a=history;f=%path;h=%revision;hb=%branch', - - /** - * Template url for the file view. - * - * The URL of the repository viewer that displays the contents of a - * given file in the repository. - * It contains the following placeholders: - * - "%base_url" the path to gitweb. - * - "%repo_name" the name of the repository on the filesystem. - * - "%path" for the file path - * - "%revision" will be replaced by the file-level revision (the - * one in {versioncontrol_item_revisions}.revision) - * - "%branch" will be replaced by the branch name that the file is on - */ + 'directory_log_view' => '%base_url/?p=%repo_name;a=history;f=%path;h=%revision;hb=%branch', 'file_view' => '%base_url/?p=%repo_name;a=blob;f=%path;h=%revision;hb=%branch', - - /** - * Template url for the directory view. - * - * The URL of the repository viewer that displays the contents of a given - * directory in the repository. - * It contains the following placeholders: - * - "%base_url" the path to gitweb. - * - "%repo_name" the name of the repository on the filesystem. - * - "%path" for the directory path - * - "%revision" will be replaced by the file-level revision (the - * one in {versioncontrol_item_revisions}.revision - only makes sense - * if directories are versioned, of course) - * - "%branch" will be replaced by the branch name that the - * directory is on. - */ 'directory_view' => '%base_url/?p=%repo_name;a=tree;f=%path;h=%revision;hb=%branch', - /** - * Template url for the diff view. - * - * The URL of the repository viewer that displays the diff between two - * given files in the repository. - * It contains the following placeholders: - * - "%base_url" the path to gitweb. - * - "%repo_name" the name of the repository on the filesystem. - * - "%path" and "%old-path" for the new and old paths (for some - * version control systems, like CVS, those paths will always be - * the same). - * - "%new-revision" and "%old-revision" will be replaced by the - * respective file-level revisions (from - * {versioncontrol_item_revisions}.revision) - * - "%branch" will be replaced by the branch name that the file is on. - * FIXME gitweb need blob hashes in order to do this, but versioncontrol_git is not storing blobs, so stop supporting this until we can do this. - * 'diff' => '%base_url/?p=%repo_name;a=blobdiff;f=%path;h=%new-blob-hash;hp=%old-blob-hash;hb=%new-revision;hpb=%old-revision', + * FIXME gitweb need blob hashes in order to do this, but + * versioncontrol_git is not storing blobs, so stop supporting this + * until we can do this. + * Template should be like this: + * '%base_url/?p=%repo_name;a=blobdiff;f=%path;h=%new_blob_hash;hp=%old_blob_hash;hb=%new_revision;hpb=%old_revision', */ 'diff' => '', - - /** - * Template url for the issue tracker view. - * - * The URL of the issue tracker that displays the issue/case/bug page of - * an issue id which presumably has been mentioned in a commit message. - * As issue tracker URLs are likely specific to each repository, this is - * also a per-repository setting. (Although... maybe it would make sense - * to have per-project rather than per-repository. Oh well.) - */ - 'tracker' => '' - ), 'handler' => array( 'class' => 'VersioncontrolRepositoryUrlHandler', + 'file' => 'VersioncontrolRepositoryUrlHandler.inc', + 'path' => drupal_get_path('module', 'versioncontrol') . '/includes/plugins/webviewer_url_handlers', ), ); diff --git includes/plugins/webviewer_url_handlers/none.inc includes/plugins/webviewer_url_handlers/none.inc new file mode 100644 index 0000000..307fac4 --- /dev/null +++ includes/plugins/webviewer_url_handlers/none.inc @@ -0,0 +1,120 @@ + 'test', + + // This title is going to be shown on the repository edition, for the + // user to identify the plugin. + 'title' => t('Empty URL handler'), + + // The list of URL templates this webviewer. Leave empty the URL + // template entry if the web viewer do not support that template. + 'url_templates' => array( + + /** + * Template url for the commit view. + * + * The URL of the repository viewer that displays a given commit in the + * repository. + * It contains the following placeholders: + * - "%base_url" the path to gitweb. + * - "%repo_name" the name of the repository on the filesystem. + * - "%revision" for the revision/commit/changeset identifier. + */ + 'commit_view' => '', + + /** + * Template url for the file log view. + * + * The URL of the repository viewer that displays the commit log of + * a given file in the repository. + * It contains the following placeholders: + * - "%base_url" the path to gitweb. + * - "%repo_name" the name of the repository on the filesystem. + * - "%path" for the file path + * - "%revision" will be replaced by the file-level revision (the one + * in {versioncontrol_item_revisions}.revision) + * - "%branch" will be replaced by the branch name that the file is on + */ + 'file_log_view' => '', + + /** + * Template url for the file directory log view. + * + * The URL of the repository viewer that displays the commit log of + * a given directoryin the repository. + * It contains the following placeholders: + * - "%base_url" the path to gitweb. + * - "%repo_name" the name of the repository on the filesystem. + * - "%path" for the file path + * - "%revision" will be replaced by the file-level revision (the one + * in {versioncontrol_item_revisions}.revision) + * - "%branch" will be replaced by the branch name that the file is on + */ + 'directory_log_view' => '', + + /** + * Template url for the file view. + * + * The URL of the repository viewer that displays the contents of a + * given file in the repository. + * It contains the following placeholders: + * - "%base_url" the path to gitweb. + * - "%repo_name" the name of the repository on the filesystem. + * - "%path" for the file path + * - "%revision" will be replaced by the file-level revision (the + * one in {versioncontrol_item_revisions}.revision) + * - "%branch" will be replaced by the branch name that the file is on + */ + 'file_view' => '', + + /** + * Template url for the directory view. + * + * The URL of the repository viewer that displays the contents of a given + * directory in the repository. + * It contains the following placeholders: + * - "%base_url" the path to gitweb. + * - "%repo_name" the name of the repository on the filesystem. + * - "%path" for the directory path + * - "%revision" will be replaced by the file-level revision (the + * one in {versioncontrol_item_revisions}.revision - only makes sense + * if directories are versioned, of course) + * - "%branch" will be replaced by the branch name that the + * directory is on. + */ + 'directory_view' => '', + + /** + * Template url for the diff view. + * + * The URL of the repository viewer that displays the diff between two + * given files in the repository. + * It contains the following placeholders: + * - "%base_url" the path to gitweb. + * - "%repo_name" the name of the repository on the filesystem. + * - "%path" and "%old_path" for the new and old paths (for some + * version control systems, like CVS, those paths will always be + * the same). + * - "%new_revision" and "%old_revision" will be replaced by the + * respective file-level revisions (from + * {versioncontrol_item_revisions}.revision) + * - "%branch" will be replaced by the branch name that the file is on. + */ + 'diff' => '', + + ), + 'handler' => array( + 'class' => 'VersioncontrolRepositoryUrlHandler', + 'file' => 'VersioncontrolRepositoryUrlHandler.inc', + 'path' => drupal_get_path('module', 'versioncontrol') . '/includes/plugins/webviewer_url_handlers', + ), +); diff --git versioncontrol.admin.inc versioncontrol.admin.inc index debd50e..003711c 100644 --- versioncontrol.admin.inc +++ versioncontrol.admin.inc @@ -383,7 +383,7 @@ function versioncontrol_admin_repository_edit(&$form_state, $repository, $vcs = $form['repository_urls']['base_url'] = array( '#type' => 'textfield', '#title' => t('Base URL'), - '#default_value' => isset($repo_url_handler) ? $repo_url_handler->base_url : '', + '#default_value' => isset($repo_url_handler) ? $repo_url_handler->baseUrl : '', '#size' => 40, '#maxlength' => 255, '#description' => t('The URL that let you see the repository web viewer. Do not use a trailing slash.'), @@ -393,7 +393,7 @@ function versioncontrol_admin_repository_edit(&$form_state, $repository, $vcs = '#title' => t('Web viewer URL handler'), '#description' => t('The handler which will provide the URLs that will be used to add links to item and commit displays such as the commit log.'), '#default_value' => $repository_exists ? $repository->plugins['webviewer_url_handler'] : 0, - '#options' => versioncontrol_webviewer_url_handlers_get_names(), + '#options' => versioncontrol_webviewer_url_handlers_get_names($form['#vcs']), ); $form['submit'] = array( diff --git versioncontrol.info versioncontrol.info index 835bba9..bf6db51 100644 --- versioncontrol.info +++ versioncontrol.info @@ -10,10 +10,10 @@ files[] = includes/VersioncontrolBranch.php files[] = includes/VersioncontrolItem.php files[] = includes/VersioncontrolOperation.php files[] = includes/VersioncontrolRepository.php +files[] = includes/VersioncontrolRepositoryUrlHandler.php files[] = includes/VersioncontrolTag.php files[] = includes/interfaces.inc files[] = includes/controllers.inc -files[] = includes/VersioncontrolRepository.php files[] = includes/views_sets.inc package = Version Control core = 6.x diff --git versioncontrol.install versioncontrol.install index bd81477..86f7cff 100644 --- versioncontrol.install +++ versioncontrol.install @@ -1139,3 +1139,22 @@ function versioncontrol_update_6311() { return $ret; } + +/** + * Remove url_handler from repository data. + * Add base_url to repository data. + */ +function versioncontrol_update_6312() { + $ret = array(); + $result = db_query("SELECT repo_id, data FROM {versioncontrol_repositories}"); + + while ($row = db_fetch_object($result)) { + $data = unserialize($row->data); + unset($data['versioncontrol']['url_handler']); + $data['versioncontrol']['base_url'] = ''; + $data = serialize($row->data); + db_query('UPDATE {versioncontrol_repositories} SET data = %s WHERE repo_id = %d', $row->data, $row->repo_id); + } + + return $ret; +} diff --git versioncontrol.module versioncontrol.module index dc0b033..06f5033 100644 --- versioncontrol.module +++ versioncontrol.module @@ -1023,12 +1023,19 @@ function versioncontrol_auth_handlers_get_names() { /** * Load the names of all 'webviewer_url_handlers' for use at forms. */ -function versioncontrol_webviewer_url_handlers_get_names() { +function versioncontrol_webviewer_url_handlers_get_names($vcs='') { ctools_include('plugins'); $names = array(); foreach (ctools_get_plugins('versioncontrol', 'webviewer_url_handlers') as $name => $plugin) { - $names[$name] = $plugin['title']; + if (!empty($vcs)) { + if ($plugin['vcs'] == $vcs) { + $names[$name] = $plugin['title']; + } + } + else { + $names[$name] = $plugin['title']; + } } asort($names);