On Wed, Jan 17, 2024 at 07:26:35PM +0000, Ineiev wrote:
> > Do you suggest alternatives?
> 
> Yes.  I'll send the details a few hours later.

Attached.

In short, homepage VCS selection is stored in group preferences,
url_cvs_viewcvs_homepage is decommissioned, the value
is derived from type_data_array["{$vcs}_viewvcs"].
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 '<li><a href="' . $group->getUrl ("cvs_viewcvs_homepage") . '">'
+    print '<li><a href="' . $group->getHomeBrowseURL () . '">'
       . _("Browse Web Pages Repository") . "</a></li>\n";
   print "</ul>\n";
 }
diff --git a/frontend/php/project/admin/editgroupfeatures.php b/frontend/php/project/admin/editgroupfeatures.php
index 00b11a1a..9bd89355 100644
--- a/frontend/php/project/admin/editgroupfeatures.php
+++ b/frontend/php/project/admin/editgroupfeatures.php
@@ -45,11 +45,11 @@
 require_once('../../include/init.php');
 require_once('../../include/sane.php');
 
-session_require(array('group' => $group_id,
-                      'admin_flags' => 'A'));
-
+session_require (['group' => $group_id, 'admin_flags' => 'A']);
+$homepage_vcs_list = ['git' => _('Git'), 'cvs' => _('CVS')];
 $post_names = function ()
 {
+  global $homepage_vcs_list;
   $vcs = ['cvs', 'arch', 'svn', 'git', 'hg', 'bzr'];
   $use_url = [
     'bugs', 'support', 'patch', 'task', 'mail', 'download', 'homepage',
@@ -65,7 +65,7 @@ $post_names = function ()
   $urls = array_merge ($vcs, $viewvcs, $use_url);
   foreach ($urls as $u)
     $names['specialchars'][] = 'url_' . $u;
-  $names['specialchars'][] = 'url_cvs_viewcvs_homepage';
+  $names['strings'] = [['homepage_vcs', array_keys ($homepage_vcs_list)]];
   return $names;
 };
 
@@ -87,8 +87,6 @@ function field_usable ($group, $field, $field_name)
     return true;
   if ($field_name == "extralink_documentation")
     return true;
-  if ($field == "url_cvs_viewcvs_homepage" && $group->CanUse ("homepage"))
-    return true;
   foreach (['cvs', 'arch', 'svn', 'git', 'hg', 'bzr'] as $vcs)
     if ($field == "url_{$vcs}_viewcvs" && $group->CanUse ($vcs))
       return true;
@@ -122,6 +120,8 @@ if ($update)
     #FIXME: feeds the database with default values... instead of checkbox,
     # it should be select boxes "default/activated/deactivated".
     group_add_history ('Changed Activated Features', '', $group_id);
+    if (!empty ($homepage_vcs))
+      $project->setHomepageVCS ($homepage_vcs);
     # In the database, these all default to '1',
     # so we have to explicity set 0 (this is ugly).
     foreach (
@@ -177,6 +177,17 @@ $next_td = function (&$i)
 };
 $close_td = function () { print "</td>\n"; };
 
+function homepage_vcs_select_box ()
+{
+  global $homepage_vcs_list, $homepage_vcs, $project;
+  $keys = array_keys ($homepage_vcs_list);
+  $texts = array_values ($homepage_vcs_list);
+  $vcs = $project->getHomepageVCS ();
+  print html_build_select_box_from_arrays (
+    $keys, $texts, 'homepage_vcs', $vcs, false
+  );
+}
+
 function specific_line ($artifact, $explanation, $use, $increment=1)
 {
   global $next_td, $close_td;
@@ -193,13 +204,17 @@ function specific_line ($artifact, $explanation, $use, $increment=1)
   # (viewcvs cannot be activated or deactivated, they are not in the menu).
   if (str_match ("viewcvs", $artifact))
     print "---";
+  elseif ($artifact == 'homepage_vcs')
+    print homepage_vcs_select_box ();
   else
     print form_checkbox ("use_$artifact", $use);
   $close_td ();
   # Print the default setting
-  # (extralink_* does not have any default).
+  # (extralink_* does not have any default), homepage_vcs has no URL.
   $next_td ($i);
-  if (!str_match ("extralink", $artifact))
+  if ($artifact == 'homepage_vcs' || str_match ("extralink", $artifact))
+    print "---";
+  else
     {
       $art_url = group_get_artifact_url ($artifact);
       print "<a href=\"$art_url\">$art_url</a>";
@@ -245,12 +260,26 @@ print html_build_list_table_top (
 
 if ($project->CanUse ("homepage"))
   {
-    specific_line ("homepage", _("Homepage"), $project->Uses("homepage"));
-    specific_line ("cvs_viewcvs_homepage",
-      _("Homepage Source Code Web Browsing"), 0, 0
-    );
+    specific_line ("homepage", _("Homepage"), $project->Uses ("homepage"));
+    specific_line ("homepage_vcs", _("Homepage VCS"), 0, 0);
   }
 
+foreach (
+  [
+    'cvs' => [_("CVS"), _("CVS Web Browsing")],
+    'arch' => [_("GNU Arch"), _("Arch Web Browsing")],
+    'svn' => [_("Subversion"), _("Subversion Web Browsing")],
+    'git' => [_("Git"), _("Git Web Browsing")],
+    'hg' => [_("Mercurial"), _("Mercurial Web Browsing")],
+    'bzr' => [_("Bazaar"), _("Bazaar Web Browsing")]
+  ] as $vcs => $labels
+)
+  if ($project->CanUse ($vcs) || $project->UsesForHomepage ($vcs))
+    {
+      specific_line ($vcs, $labels[0], $project->Uses ($vcs));
+      specific_line ("{$vcs}_viewcvs", $labels[1], 0, 0);
+    }
+
 if ($project->CanModifyUrl ("extralink_documentation"))
   specific_line ("extralink_documentation", _("Documentation"),
     $project->Uses("extralink_documentation")
@@ -283,26 +312,6 @@ if ($project->CanUse ("download") && $project->CanModifyDir("download_dir"))
     print "</td>\n</tr>\n";
   }
 
-if ($project->CanUse ("cvs") || $project->CanUse ("homepage"))
-  {
-    specific_line ("cvs", _("CVS"), $project->Uses ("cvs"));
-    specific_line ("cvs_viewcvs", _("CVS Web Browsing"), 0, 0);
-  }
-foreach (
-  [
-    'arch' => [_("GNU Arch"), _("Arch Web Browsing")],
-    'svn' => [_("Subversion"), _("Subversion Web Browsing")],
-    'git' => [_("Git"), _("Git Web Browsing")],
-    'hg' => [_("Mercurial"), _("Mercurial Web Browsing")],
-    'bzr' => [_("Bazaar"), _("Bazaar Web Browsing")]
-  ] as $vcs => $labels
-)
-  if ($project->CanUse ($vcs))
-    {
-      specific_line ($vcs, $labels[0], $project->Uses ($vcs));
-      specific_line ("{$vcs}_viewcvs", $labels[1], 0, 0);
-    }
-
 foreach (
   [
     "mail" => _("Mailing Lists"), "forum" => _("Forum"), "news" => _("News"),
diff --git a/frontend/php/siteadmin/group_type.php b/frontend/php/siteadmin/group_type.php
index 6941d1c3..7de93934 100644
--- a/frontend/php/siteadmin/group_type.php
+++ b/frontend/php/siteadmin/group_type.php
@@ -124,7 +124,7 @@ $name_matching = function ($trackers, $vcs_list)
 {
   $names = [
     'specialchars' => [
-      'name', 'description',  'base_host', 'homepage_scm',
+      'name', 'description',  'base_host',
       'admin_email_adress', # Sic! adress not address, single 'd'.
     ],
     'true' => []
@@ -140,7 +140,6 @@ $name_matching = function ($trackers, $vcs_list)
     $names['specialchars'][] = "url_$hd";
   foreach ($vcs_list as $vcs)
     $names['specialchars'][] = "url_{$vcs}_viewcvs";
-  $names['specialchars'][] = "url_cvs_viewcvs_homepage";
   foreach (
     [
       'listinfo', 'subscribe', 'unsubscribe', 'archives', 'archives_private',
@@ -328,21 +327,7 @@ print "<p>";
 show_checkbox (no_i18n ("Can use homepage"), 'can_use_homepage', $row_grp);
 print "</p>";
 
-$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 "<p>";
-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 "</p>";
 
 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 "<p>" . _('With other project modules:') . "</p>\n";
         print "<pre>$cvs_cmd&lt;<i>" . _('modulename') . "</i>&gt;</pre>\n";
       }
-    if ($project->CanUse("homepage") || $project->UsesForHomepage("cvs"))
+    if ($have_web)
       {
         print "<h4>" . _('Webpage repository:') . "</h4>\n";
         print "<pre>$cvs_cmd_base" . $project->getTypeDir('homepage')
@@ -101,8 +101,7 @@ $username = user_getname ();
 if ($username == "NA")
   # For anonymous user.
   $username = '&lt;<i>' . _('membername') . '</i>&gt;';
-$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 "<pre>$cvs_cmd&lt;<i>" . _('modulename') . '</i>&gt;'
       . "</pre></p>\n";
   }
-if ($project->CanUse ("homepage") || $project->UsesForHomepage ("cvs"))
+if ($have_web)
   {
     print "<h4>" . _('Webpage repository:') . "</h4>\n";
     print "<pre>$cvs_cmd_base"
@@ -194,7 +193,7 @@ printf (
 );
 
 print "</p>\n";
-if ($project->getTypeBaseHost () == "savannah.gnu.org")
+if ($base_host == "savannah.gnu.org")
   {
     print '<h2>' . _('Web pages for GNU packages') . "</h2>\n\n<p>";
     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 "<p>" . _('Note: this group has multiple Git repositories.')
@@ -53,16 +58,21 @@ if ($n > 1)
 if ($project->isPublic ())
   {
     print "<h3>" . _('Anonymous clone:') . "</h3>\n<pre>";
+    $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 "</pre>\n\n<h3>" . _('Member clone:') . "</h3>\n\n<pre>";
@@ -72,15 +82,21 @@ if ($username == "NA")
   # For anonymous user.
   $username = '&lt;<i>' . _('membername') . '</i>&gt;';
 
+$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 "</pre>\n\n<p>"
   . _("The SSHv2 public key fingerprints for the machine hosting the source\n"
       . "trees are:")

Attachment: signature.asc
Description: PGP signature

Reply via email to