diff --git a/frontend/php/include/group.php b/frontend/php/include/group.php index 4afea29b..a546edea 100644 --- a/frontend/php/include/group.php +++ b/frontend/php/include/group.php @@ -450,20 +450,38 @@ class Group extends savane_error return $this->CanUse ($artifact); } + function getHomepageVCS () + { + $pref = group_get_preference ($this->group_id, 'homepage_vcs'); + if ($pref !== false) + return $pref; + return 'cvs'; # Historical default. + } + + function setHomepageVCS ($vcs) + { + group_set_preference ($this->group_id, 'homepage_vcs', $vcs); + } + + function getHomeBrowseURL () + { + $url = $this->getTypeUrl ($this->getHomepageVCS () . "_viewcvs"); + return preg_replace (',^(http(s?):)?//,', '$0web.', $url); + } + + # Determine if the group uses a specific artifact to manage its home page: + # - the group must use home page; + # - the group must be select the VCS for its home page; + # - the home page URL must be empty or default. function UsesForHomepage ($artifact) { - # Useful to determine whether the project is a specific artifact - # to manage its homepage: - # - must use homepage - # - must be set as homepage SCM for the group type - # - the projet url must be empty or equal to the group setting + if (!$this->Uses ("homepage")) + return false; + if ($this->getHomepageVCS () != $artifact) + return false; return - $this->Uses ("homepage") - && $this->type_data_array['homepage_scm'] == $artifact - && ( - $this->data_array['url_homepage'] == $this->getTypeUrl ('homepage') - || $this->data_array['url_homepage'] == "" - ); + $this->data_array['url_homepage'] == $this->getTypeUrl ('homepage') + || $this->data_array['url_homepage'] == ""; } # Related to mail notification. @@ -742,7 +760,7 @@ function group_get_artifact_url ($artifact, $hostname = 1) { global $project, $sys_home; $type_urls = [ - "homepage", "download", "cvs_viewcvs", "cvs_viewcvs_homepage", + "homepage", "download", "cvs_viewcvs", "arch_viewcvs", "svn_viewcvs", "git_viewcvs", "hg_viewcvs", "bzr_viewcvs" ]; if (in_array ($artifact, $type_urls)) diff --git a/frontend/php/include/pagemenu.php b/frontend/php/include/pagemenu.php index 9af82f33..b06c0d9d 100644 --- a/frontend/php/include/pagemenu.php +++ b/frontend/php/include/pagemenu.php @@ -344,15 +344,9 @@ function pagemenu_vcs_browse_entry ($group, $vcs, $name) function pagemenu_vcs_web_browse_url ($group, $vcs) { - if (!pagemenu_url_is_set ($group, "cvs_viewcvs_homepage")) - return ''; - if ($vcs == 'cvs') - $have_entry = $group->Uses ('homepage'); - else - $have_entry = $group->UsesForHomepage ($vcs); - if (!$have_entry) - return ''; - return $group->getUrl ("cvs_viewcvs_homepage"); + if ($group->UsesForHomepage ($vcs)) + return $group->getHomeBrowseURL (); + return ''; } function pagemenu_vcs_web_browse_entry ($group, $vcs, $name) diff --git a/frontend/php/include/vcs.php b/frontend/php/include/vcs.php index e8947ba9..701e1cc3 100644 --- a/frontend/php/include/vcs.php +++ b/frontend/php/include/vcs.php @@ -131,24 +131,40 @@ function vcs_sort_repos ($vcs, $group_id, $repos) return $ret; } +# Guess base VCS directory from the configuration. +function vcs_get_dir ($vcs) +{ + global $sys_vcs_dir; + if (empty ($sys_vcs_dir) || !is_array ($sys_vcs_dir)) + return null; + if (empty ($sys_vcs_dir[$vcs]['dir']) || !is_dir ($sys_vcs_dir[$vcs]['dir'])) + return null; + return $sys_vcs_dir[$vcs]['dir']; +} + +# Guess base VCS clone path from the configuration. +function vcs_get_clone_path ($vcs, $fallback = null) +{ + global $sys_vcs_dir; + if ($fallback === null) + $fallback = vcs_get_dir ($vcs); + if (empty ($sys_vcs_dir[$vcs]['clone-path'])) + return $fallback; + return $sys_vcs_dir[$vcs]['clone-path']; +} + # Get array of repository descriptions. function vcs_get_repos ($vcs, $group_id) { - global $sys_vcs_dir; $func = "{$vcs}_list_repos"; if (!function_exists ($func)) return []; + $vcs_dir = vcs_get_dir ($vcs); + if ($vcs_dir === null) + return []; $group = project_get_object ($group_id); $group_name = $group->getUnixName (); - if (empty ($sys_vcs_dir) || !is_array ($sys_vcs_dir)) - return []; - if (empty ($sys_vcs_dir[$vcs]['dir']) || !is_dir ($sys_vcs_dir[$vcs]['dir'])) - return []; - $vcs_dir = $sys_vcs_dir[$vcs]['dir']; - if (empty ($sys_vcs_dir[$vcs]['clone-path'])) - $clone_path = $vcs_dir; - else - $clone_path = $sys_vcs_dir[$vcs]['clone-path']; + $clone_path = vcs_get_clone_path ($vcs, $vcs_dir); $repos = $func ($group_name, $vcs_dir, $clone_path); $repos = vcs_override_descriptions ($vcs, $group_id, $repos); return vcs_sort_repos ($vcs, $group_id, $repos); @@ -209,8 +225,7 @@ function vcs_print_links_to_repos ($group, $group_id, $vcs_exfix, $vcs_name) $repo_list = vcs_get_repos ($vcs_exfix, $group_id); $have_links = $group->Uses ($vcs_exfix) && pagemenu_url_is_set ($group, "{$vcs_exfix}_viewcvs"); - $have_web_links = $group->UsesForHomepage ($vcs_exfix) - && pagemenu_url_is_set ($group, "cvs_viewcvs_homepage"); + $have_web_links = $group->UsesForHomepage ($vcs_exfix); if (!($have_links || $have_web_links)) return; vcs_print_browsing_preface ($vcs_name); @@ -218,7 +233,7 @@ function vcs_print_links_to_repos ($group, $group_id, $vcs_exfix, $vcs_name) if ($have_links) vcs_print_source_repo_links ($group, $vcs_exfix, $repo_list); if ($have_web_links) - print '
"; show_checkbox (no_i18n ("Can use homepage"), 'can_use_homepage', $row_grp); print "
"; -$sel_val = null; -$selection = $row_grp['homepage_scm']; -foreach ($vcs_list as $title => $name) - if ($name === $selection) - { - $sel_val = $title; - break; - } -$vals = array_keys ($vcs_list); -$select_box = - html_build_select_box_from_array ($vals, no_i18n ("VCS"), $sel_val); - print ""; -specific_showinput (no_i18n ("Selected SCM:"), $select_box); - html_select_typedir_box ("dir_type_homepage", $row_grp['dir_type_homepage']); $idx = 'dir_homepage'; specific_input ( @@ -353,11 +338,6 @@ $idx = 'url_homepage'; specific_input ( no_i18n ("Homepage URL:"), $row_grp[$idx], $idx, $textfield_size ); -$idx = 'url_cvs_viewcvs_homepage'; -specific_input ( - no_i18n ("Homepage CVS view URL (webcvs, viewcvs):"), - $row_grp[$idx], $idx, $textfield_size -); print "
"; function source_code_manager ($HTML, $row_grp, $textfield_size, @@ -674,8 +654,6 @@ $checkboxes = [ "cvs" => no_i18n ("the cvs link can be modified"), "cvs_viewcvs" => [no_i18n ("the viewcvs link can be modified")], - "cvs_viewcvs_homepage" => - [no_i18n ("the viewcvs link for homepage code can be modified")], "arch" => no_i18n ("the GNU Arch link can be modified"), "arch_viewcvs" => [no_i18n ("the GNU Arch viewcvs link can be modified")], diff --git a/frontend/php/siteadmin/triggercreation.php b/frontend/php/siteadmin/triggercreation.php index 19cf9907..7d04e1c8 100644 --- a/frontend/php/siteadmin/triggercreation.php +++ b/frontend/php/siteadmin/triggercreation.php @@ -101,6 +101,9 @@ if ($upd_list) fb (no_i18n ("No field to update or SQL error")); } +$group = group_get_object ($group_id); +$group->setHomepageVCS ('git'); + # Now set a default notification setup for the trackers. # We do not even check whether the trackers are used, because we want this # configuration to be already done if at some point the tracker gets activated, diff --git a/frontend/php/testing/sane.php b/frontend/php/testing/sane.php index 600e4a72..07ee6c99 100644 --- a/frontend/php/testing/sane.php +++ b/frontend/php/testing/sane.php @@ -1912,6 +1912,7 @@ $reference = 'project/admin/conf-copy.php'; $reference = 'project/admin/editgroupfeatures.php'; { + $homepage_vcs_list = ['git' => _('Git'), 'cvs' => _('CVS')]; $post_names = function () { $vcs = ['cvs', 'arch', 'svn', 'git', 'hg', 'bzr']; @@ -1929,7 +1930,6 @@ $reference = 'project/admin/editgroupfeatures.php'; $urls = array_merge ($vcs, $viewvcs, $use_url); foreach ($urls as $u) $names['specialchars'][] = 'url_' . $u; - $names['specialchars'][] = 'url_cvs_viewcvs_homepage'; return $names; }; $names = $post_names (); @@ -1938,6 +1938,10 @@ $reference = 'project/admin/editgroupfeatures.php'; $in[$n] = $out[$n] = true; foreach ($names['specialchars'] as $n) $in[$n] = $out[$n] = $n; + $names['strings'] = [['homepage_vcs', array_keys ($homepage_vcs_list)]]; + $in ['homepage_vcs'] = '/'; $out ['homepage_vcs'] = null; + test_sane_import ($in, $names, $out); + $in ['homepage_vcs'] = $out['homepage_vcs'] = 'git'; test_sane_import ($in, $names, $out); } diff --git a/frontend/site-specific/gnu/cvs/index.php b/frontend/site-specific/gnu/cvs/index.php index 148b3cf4..cde2aaac 100644 --- a/frontend/site-specific/gnu/cvs/index.php +++ b/frontend/site-specific/gnu/cvs/index.php @@ -50,9 +50,9 @@ include dirname (__FILE__) . '/../fingerprints.php'; global $project, $sys_home, $sys_unix_group_name; $proj_unix_name = $project->getUnixName (); -$cvs_cmd_base = "cvs -z3 -d:pserver:anonymous@cvs." - . $project->getTypeBaseHost () . ":"; - +$base_host = $project->getTypeBaseHost (); +$cvs_cmd_base = "cvs -z3 -d:pserver:anonymous@cvs.$base_host:"; +$have_web = $project->isPublic () && $project->UsesForHomepage ('cvs'); if ($project->isPublic ()) { @@ -71,7 +71,7 @@ if ($project->isPublic ()) print "" . _('With other project modules:') . "
\n"; print "$cvs_cmd<" . _('modulename') . ">\n"; } - if ($project->CanUse("homepage") || $project->UsesForHomepage("cvs")) + if ($have_web) { print "
$cvs_cmd_base" . $project->getTypeDir('homepage') @@ -101,8 +101,7 @@ $username = user_getname (); if ($username == "NA") # For anonymous user. $username = '<' . _('membername') . '>'; -$cvs_cmd_base = "cvs -z3 -d:ext:$username@cvs." . $project->getTypeBaseHost() - . ":"; +$cvs_cmd_base = "cvs -z3 -d:ext:$username@cvs.$base_host:"; if ($project->Uses("cvs")) { $cvs_cmd = "$cvs_cmd_base" . $project->getTypeDir("cvs") . " co "; @@ -112,7 +111,7 @@ if ($project->Uses("cvs")) print "$cvs_cmd<" . _('modulename') . '>' . "\n"; } -if ($project->CanUse ("homepage") || $project->UsesForHomepage ("cvs")) +if ($have_web) { print "" . _('Webpage repository:') . "
\n"; print "$cvs_cmd_base" @@ -194,7 +193,7 @@ printf ( ); print "\n"; -if ($project->getTypeBaseHost () == "savannah.gnu.org") +if ($base_host == "savannah.gnu.org") { print '' . _('Web pages for GNU packages') . "
\n\n"; printf ( diff --git a/frontend/site-specific/gnu/git/index.php b/frontend/site-specific/gnu/git/index.php index d7d47ec2..8708ea1c 100644 --- a/frontend/site-specific/gnu/git/index.php +++ b/frontend/site-specific/gnu/git/index.php @@ -46,6 +46,11 @@ include dirname (__FILE__) . '/../fingerprints.php'; global $project, $repo_list; +$base_url = 'git.' . $project->getTypeBaseHost (); +$have_web = $project->UsesForHomepage ('git') && $project->isPublic (); +$web_dir = 'git-web'; +$web_repo = $web_dir . '/' . $project->getUnixName () . '.git'; + $n = count ($repo_list); if ($n > 1) print "
" . _('Note: this group has multiple Git repositories.') @@ -53,16 +58,21 @@ if ($n > 1) if ($project->isPublic ()) { print "
" . _('Anonymous clone:') . "
\n"; + $cmd_start = "git clone https://$base_url"; for ($i = 0; $i < $n; $i++) { if ($n > 1) print $repo_list[$i]['desc'] . "\n"; - print "git clone https://git." . $project->getTypeBaseHost () - . "/git/" . $repo_list[$i]['url'] . "\n"; + print "$cmd_start/git/" . $repo_list[$i]['url'] . "\n"; if ($i < $n - 1) print "\n"; } + if ($have_web) + { + print "\n" . _('Webpage repository:') . "\n"; + print "$cmd_start/$web_repo\n"; + } } print "\n\n" . _('Member clone:') . "
\n\n"; @@ -72,15 +82,21 @@ if ($username == "NA") # For anonymous user. $username = '<' . _('membername') . '>'; +$cmd_start = "git clone $username@$base_url:"; for ($i = 0; $i < $n; $i++) { if ($n > 1) print $repo_list[$i]['desc'] . "\n"; - print "git clone $username@git." . $project->getTypeBaseHost () . ":" - . $repo_list[$i]['path'] . "\n"; + print $cmd_start . $repo_list[$i]['path'] . "\n"; if ($i < $n - 1) print "\n"; } +if ($have_web) + { + $path = dirname (vcs_get_clone_path ('git')); + print "\n" . _('Webpage repository:') . "\n"; + print "$cmd_start/$path/$web_repo\n"; + } print "\n\n" . _("The SSHv2 public key fingerprints for the machine hosting the source\n" . "trees are:")