]> Sergey Matveev's repositories - public-inbox.git/commitdiff
clone: support --project-list= for cgit
authorEric Wong <e@80x24.org>
Mon, 28 Nov 2022 05:32:31 +0000 (05:32 +0000)
committerEric Wong <e@80x24.org>
Mon, 28 Nov 2022 23:39:00 +0000 (23:39 +0000)
grokmirror supports it, and we also support cgit, so this should
make running mirrors easier.  This will be useful for scripting
purposes, too.

lib/PublicInbox/LeiMirror.pm
script/public-inbox-clone

index 0508c9a8c4aad99ca3cf2b8adddd92cb73a1c1cb..d4b146997c368876298d83f03f59e39aefa385a8 100644 (file)
@@ -991,6 +991,34 @@ sub dump_manifest ($$) {
        utime($mtime, $mtime, "$ft") or die "utime(..., $ft): $!";
 }
 
+sub dump_project_list ($$) {
+       my ($self, $m) = @_;
+       my $f = $self->{'-project-list'} // return;
+       my $old = PublicInbox::Git::try_cat($f);
+       my %new;
+
+       open my $dh, '<', '.' or die "open(.): $!";
+       chdir($self->{dst}) or die "chdir($self->{dst}): $!";
+       my @local = grep { -e $_ ? ($new{$_} = undef) : 1 } split(/\n/s, $old);
+       chdir($dh) or die "chdir(restore): $!";
+
+       $new{substr($_, 1)} = 1 for keys %$m; # drop leading '/'
+       my @list = sort keys %new;
+       my @remote = grep { !defined($new{$_}) } @list;
+
+       warn <<EOM if @remote;
+The following local repositories are ignored/gone from $self->{src}:
+EOM
+       warn "\t", $_, "\n" for @remote;
+       warn <<EOM if @local;
+The following repos in $f no longer exist on the filesystem:
+EOM
+       warn "\t", $_, "\n" for @local;
+
+       my (undef, $dn, $bn) = File::Spec->splitpath($f);
+       atomic_write($dn, $bn, join("\n", @list, ''));
+}
+
 # FIXME: this gets confused by single inbox instance w/ global manifest.js.gz
 sub try_manifest {
        my ($self) = @_;
@@ -1104,6 +1132,7 @@ EOM
        warn(<<EOM, map { ("\t", $_, "\n") } @$bad) if $bad;
 W: The following exist and have not been converted to symlinks
 EOM
+       dump_project_list($self, $m);
        ft_rename($ft, $manifest, 0666);
 }
 
@@ -1124,14 +1153,18 @@ sub do_mirror { # via wq_io_do or public-inbox-clone
                $ic =~ /\A(?:v1|v2|always|never)\z/s or die <<"";
 --inbox-config must be one of `always', `v2', `v1', or `never'
 
-               # we support --objstore= and --manifest= with '' (empty string)
-               for my $default (qw(objstore manifest.js.gz)) {
-                       my ($k) = (split(/\./, $default))[0];
+               # we support these switches with '' (empty string).
+               # defaults match example conf distributed with grokmirror
+               my @pairs = qw(objstore objstore manifest manifest.js.gz
+                               project-list projects.list);
+               while (@pairs) {
+                       my ($k, $default) = splice(@pairs, 0, 2);
                        my $v = $lei->{opt}->{$k} // next;
                        $v = $default if $v eq '';
                        $v = "$self->{dst}/$v" if $v !~ m!\A\.{0,2}/!;
                        $self->{"-$k"} = $v;
                }
+
                local $LIVE = {};
                local $TODO = {};
                local $FGRP_TODO = {};
index efe0cff6f50c0a94382219227e9eee82a85d304b..677c56c89c619e577ac447e4f2e4d04cd119899c 100755 (executable)
@@ -22,8 +22,12 @@ options:
     --quiet | -q      increase verbosity (may be repeated)
     -C DIR            chdir to specified directory
 EOF
+
+# cgit calls it `project-list', grokmirror calls it `projectslist',
+# support both :/
 GetOptions($opt, qw(help|h quiet|q verbose|v+ C=s@ c=s@ include|I=s@ exclude=s@
        inbox-config=s inbox-version=i objstore=s manifest=s
+       project-list|projectslist=s
        prune|p keep-going|k
        dry-run|n jobs|j=i no-torsocks torsocks=s epoch=s)) or die $help;
 if ($opt->{help}) { print $help; exit };