git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 4/4] remote-mediawiki: allow using (Main) as a namespace and skip special namespaces

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Oct 29, 2017, 19:49 UTC
Message-ID
<CAPig+cSTp1Udo6xXk5-L6MpWBdiy4sPO__NcND03-89EvRgLHQ@mail.gmail.com>
In-Reply-To
<20171029160857.29460-5-anarcat@debian.org>
On Sun, Oct 29, 2017 at 12:08 PM, Antoine Beaupré <anarcat@debian.org> wrote:
> Subject: remote-mediawiki: allow using (Main) as a namespace and skip special namespaces

This patch is more difficult to review than it perhaps ought to be since it is making multiple unrelated changes.

It's not clear from the description what special namespaces are and why they need to be skipped. It's also not clear why (Main) is special. Perhaps the commit message(s) could explain these issues in more detail.

To simplify review and make it easier to gauge what it going on, it might make sense to split this patch into at least two: one which skips "special namespaces", and one which gives special treatment to (Main).

More below...
Show 25 quoted lines
> Reviewed-by: Antoine Beaupré <anarcat@debian.org>
> Signed-off-by: Antoine Beaupré <anarcat@debian.org>
> ---
> diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
> @@ -264,16 +264,27 @@ sub get_mw_tracked_categories {
>  sub get_mw_tracked_namespaces {
>      my $pages = shift;
> -    foreach my $local_namespace (@tracked_namespaces) {
> -        my $mw_pages = $mediawiki->list( {
> -            action => 'query',
> -            list => 'allpages',
> -            apnamespace => get_mw_namespace_id($local_namespace),
> -            aplimit => 'max' } )
> -            || die $mediawiki->{error}->{code} . ': '
> -                . $mediawiki->{error}->{details} . "\n";
> -        foreach my $page (@{$mw_pages}) {
> -            $pages->{$page->{title}} = $page;
> +    foreach my $local_namespace (sort @tracked_namespaces) {
> +        my ($mw_pages, $namespace_id);
> +        if ($local_namespace eq "(Main)") {
> +            $namespace_id = 0;
> +        } else {
> +            $namespace_id = get_mw_namespace_id($local_namespace);
> +        }
> +        if ($namespace_id >= 0) {

This may be problematic since get_mw_namespace_id() may return undef rather than a number, in which case Perl will complain. Since the code skips the $mediawiki query altogether when it encounters "(Main)", you could fix this problem and simplify the code overall by simply skipping the bulk of the foreach loop body instead of mucking around with $namespace_id. For instance:

    foreach my $local_namespace (sort @tracked_namespaces) {
        next if ($local_namespace eq "(Main)");
        ...normal processing...
    }
Show 6 quoted lines
> +            if ($mw_pages = $mediawiki->list( {
> +                action => 'query',
> +                list => 'allpages',
> +                apnamespace => $namespace_id,
> +                aplimit => 'max' } )) {
> +                print {*STDERR} "$#{$mw_pages} found in namespace $local_namespace ($namespace_id)\n";

The original code did not emit this diagnostic but the new code does so unconditionally. Is this just leftover debugging code or is intended that all users should see this information all the time?

Show 6 quoted lines
> +                foreach my $page (@{$mw_pages}) {
> +                    $pages->{$page->{title}} = $page;
> +                }
> +            } else {
> +                warn $mediawiki->{error}->{code} . ': '
> +                    . $mediawiki->{error}->{details} . "\n";

I guess this is the part which "skips special namespaces". The original code die()'d but this merely warns. Aside from these "special namespaces", are there genuine cases when the $mediawiki query would return an error, and which should indeed die(), or is warning appropriate for all $mediawiki query error cases?

> +            }
>          }
>      }
>      return;
Previous: Antoine BeaupréNext: Antoine Beaupré
Message 3 of 78 in “WIP: git-remote-media wiki namespace support”
  1. 0/4 WIP: git-remote-media wiki namespace supportAntoine Beaupré, Oct 29, 2017
  2. 4/4 remote-mediawiki: allow using (Main) as a namespace and skip special namespacesAntoine Beaupré, Oct 29, 2017
  3. Eric SunshineOct 29, 2017
  4. Antoine BeaupréOct 30, 2017
  5. Eric SunshineOct 30, 2017
  6. Antoine BeaupréOct 30, 2017
  7. Eric SunshineOct 30, 2017
  8. Antoine BeaupréOct 30, 2017
  9. 1/4 remote-mediawiki: add namespace supportAntoine Beaupré, Oct 29, 2017
  10. Eric SunshineOct 29, 2017
  11. Antoine BeaupréOct 29, 2017
  12. Eric SunshineOct 29, 2017
  13. KevinOct 29, 2017
  14. Antoine BeaupréOct 30, 2017
  15. 0/7 remote-mediawiki: add namespace supportAntoine Beaupré, Oct 30, 2017
  16. 1/7 remote-mediawiki: add namespace supportAntoine Beaupré, Oct 30, 2017
  17. 3/7 remote-mediawiki: show known namespace choices on failureAntoine Beaupré, Oct 30, 2017
  18. 5/7 remote-mediawiki: support fetching from (Main) namespaceAntoine Beaupré, Oct 30, 2017
  19. Eric SunshineNov 1, 2017
  20. Antoine BeaupréNov 2, 2017
  21. 6/7 remote-mediawiki: process namespaces in orderAntoine Beaupré, Oct 30, 2017
  22. Eric SunshineNov 1, 2017
  23. 7/7 remote-mediawiki: show progress while fetching namespacesAntoine Beaupré, Oct 30, 2017
  24. Eric SunshineNov 1, 2017
  25. 4/7 remote-mediawiki: skip virtual namespacesAntoine Beaupré, Oct 30, 2017
  26. Eric SunshineNov 1, 2017
  27. Antoine BeaupréNov 1, 2017
  28. Junio C HamanoNov 2, 2017
  29. Antoine BeaupréNov 2, 2017
  30. Junio C HamanoNov 6, 2017
  31. 2/7 remote-mediawiki: allow fetching namespaces with spacesAntoine Beaupré, Oct 30, 2017
  32. 0/7 remote-mediawiki: namespace supportAntoine Beaupré, Nov 2, 2017
  33. 1/7 remote-mediawiki: add namespace supportAntoine Beaupré, Nov 2, 2017
  34. 2/7 remote-mediawiki: allow fetching namespaces with spacesAntoine Beaupré, Nov 2, 2017
  35. 3/7 remote-mediawiki: show known namespace choices on failureAntoine Beaupré, Nov 2, 2017
  36. 4/7 remote-mediawiki: skip virtual namespacesAntoine Beaupré, Nov 2, 2017
  37. Eric SunshineNov 2, 2017
  38. Antoine BeaupréNov 2, 2017
  39. 5/7 remote-mediawiki: support fetching from (Main) namespaceAntoine Beaupré, Nov 2, 2017
  40. Eric SunshineNov 2, 2017
  41. 7/7 remote-mediawiki: show progress while fetching namespacesAntoine Beaupré, Nov 2, 2017
  42. Thomas AdamNov 2, 2017
  43. Antoine BeaupréNov 2, 2017
  44. Thomas AdamNov 2, 2017
  45. Antoine BeaupréNov 2, 2017
  46. Thomas AdamNov 4, 2017
  47. Eric SunshineNov 2, 2017
  48. 6/7 remote-mediawiki: process namespaces in orderAntoine Beaupré, Nov 2, 2017
  49. Eric SunshineNov 2, 2017
  50. 0/7 remote-mediawiki: namespace supportAntoine Beaupré, Nov 6, 2017
  51. 1/7 remote-mediawiki: add namespace supportAntoine Beaupré, Nov 6, 2017
  52. 3/7 remote-mediawiki: show known namespace choices on failureAntoine Beaupré, Nov 6, 2017
  53. Thomas AdamNov 7, 2017
  54. Antoine BeaupréNov 7, 2017
  55. 7/7 remote-mediawiki: show progress while fetching namespacesAntoine Beaupré, Nov 6, 2017
  56. 5/7 remote-mediawiki: support fetching from (Main) namespaceAntoine Beaupré, Nov 6, 2017
  57. 6/7 remote-mediawiki: process namespaces in orderAntoine Beaupré, Nov 6, 2017
  58. 4/7 remote-mediawiki: skip virtual namespacesAntoine Beaupré, Nov 6, 2017
  59. 2/7 remote-mediawiki: allow fetching namespaces with spacesAntoine Beaupré, Nov 6, 2017
  60. Thomas AdamNov 7, 2017
  61. Antoine BeaupréNov 7, 2017
  62. 0/7 namespace supportAntoine Beaupré, Nov 7, 2017
  63. 1/7 remote-mediawiki: add namespace supportAntoine Beaupré, Nov 7, 2017
  64. 3/7 remote-mediawiki: show known namespace choices on failureAntoine Beaupré, Nov 7, 2017
  65. 5/7 remote-mediawiki: support fetching from (Main) namespaceAntoine Beaupré, Nov 7, 2017
  66. 6/7 remote-mediawiki: process namespaces in orderAntoine Beaupré, Nov 7, 2017
  67. 4/7 remote-mediawiki: skip virtual namespacesAntoine Beaupré, Nov 7, 2017
  68. 7/7 remote-mediawiki: show progress while fetching namespacesAntoine Beaupré, Nov 7, 2017
  69. 2/7 remote-mediawiki: allow fetching namespaces with spacesAntoine Beaupré, Nov 7, 2017
  70. Junio C HamanoNov 8, 2017
  71. Matthieu MoyOct 30, 2017
  72. 3/4 remote-mediawiki: show known namespace choices on failureAntoine Beaupré, Oct 29, 2017
  73. Eric SunshineOct 29, 2017
  74. Antoine BeaupréOct 29, 2017
  75. Thomas AdamNov 4, 2017
  76. 2/4 remote-mediawiki: allow fetching namespaces with spacesAntoine Beaupré, Oct 29, 2017
  77. Matthieu MoyOct 30, 2017
  78. Antoine BeaupréOct 30, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.