]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: support $INBOX/git/$EPOCH.git for v2 cloning
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Sun, 9 Jun 2019 04:31:05 +0000 (04:31 +0000)
committerEric Wong <e@80x24.org>
Sun, 9 Jun 2019 04:32:31 +0000 (04:32 +0000)
And use it in manifest.js.

To ease maintaining mirrors with grokmirror(1), we can accept
a "git/" directory prefix before the epoch, and ".git" suffix
after the epoch number.

We maintain compatibility with "$INBOX/$EPOCH" cloning, of
course, and it's still easier-to-type on the command-line.

lib/PublicInbox/WWW.pm
lib/PublicInbox/WwwListing.pm
t/psgi_v2.t
t/v2mirror.t
t/www_listing.t

index a54669808c76c6b3f5b86226289e613182f44a5c..e468263699bbcdd13af2e8efeb020f743b06907b 100644 (file)
@@ -74,7 +74,7 @@ sub call {
        my $method = $env->{REQUEST_METHOD};
 
        if ($method eq 'POST') {
-               if ($path_info =~ m!$INBOX_RE/(?:([0-9]+)/)?
+               if ($path_info =~ m!$INBOX_RE/(?:(?:git/)?([0-9]+)(?:\.git)?/)?
                                        (git-upload-pack)\z!x) {
                        my ($part, $path) = ($2, $3);
                        return invalid_inbox($ctx, $1) ||
@@ -98,7 +98,7 @@ sub call {
                invalid_inbox($ctx, $1) || get_atom($ctx);
        } elsif ($path_info =~ m!$INBOX_RE/new\.html\z!o) {
                invalid_inbox($ctx, $1) || get_new($ctx);
-       } elsif ($path_info =~ m!$INBOX_RE/(?:([0-9]+)/)?
+       } elsif ($path_info =~ m!$INBOX_RE/(?:(?:git/)?([0-9]+)(?:\.git)?/)?
                                ($PublicInbox::GitHTTPBackend::ANY)\z!ox) {
                my ($part, $path) = ($2, $3);
                invalid_inbox($ctx, $1) || serve_git($ctx, $part, $path);
index 690976acdc9ae2a6f9afb811c69e3d3fec041c35..e2724cc49e631dc63a38dc26410d0b6a9577707b 100644 (file)
@@ -144,7 +144,7 @@ sub manifest_add ($$;$) {
        my $git_dir = $ibx->{mainrepo};
        if (defined $epoch) {
                $git_dir .= "/git/$epoch.git";
-               $url_path .= "/$epoch";
+               $url_path .= "/git/$epoch.git";
        }
        return unless -d $git_dir;
        my $git = PublicInbox::Git->new($git_dir);
index 98112494b32cf90c202c02d103659961fd5fe6ad..5c358cdecb591720c785cce6ecc6a8fd1a718c96 100644 (file)
@@ -202,6 +202,8 @@ test_psgi(sub { $www->call(@_) }, sub {
 
        $res = $cb->(GET('/v2test/0/info/refs'));
        is($res->code, 200, 'got info refs for dumb clones');
+       $res = $cb->(GET('/v2test/0.git/info/refs'));
+       is($res->code, 200, 'got info refs for dumb clones w/ .git suffix');
        $res = $cb->(GET('/v2test/info/refs'));
        is($res->code, 404, 'unpartitioned git URL fails');
 
index fe05ec4d2c30916a6a01d424571e944080f7ca0f..c31dcd5bf7cdc2ed6c8df36ab89656eb70f8d7d2 100644 (file)
@@ -80,11 +80,13 @@ $sock = undef;
 
 my @cmd;
 foreach my $i (0..$epoch_max) {
-       @cmd = (qw(git clone --mirror -q), "http://$host:$port/v2/$i",
+       my $sfx = $i == 0 ? '.git' : '';
+       @cmd = (qw(git clone --mirror -q),
+               "http://$host:$port/v2/$i$sfx",
                "$tmpdir/m/git/$i.git");
 
-       is(system(@cmd), 0, 'cloned OK');
-       ok(-d "$tmpdir/m/git/$i.git", 'mirror OK');
+       is(system(@cmd), 0, "cloned $i.git");
+       ok(-d "$tmpdir/m/git/$i.git", "mirror $i OK");
 }
 
 @cmd = ("$script-init", '-V2', 'm', "$tmpdir/m", 'http://example.com/m',
index 546c2f8fab0cc18a8f98620c04feb9819f74a205..2741e1b8b531db17084b5c2ed0bb3ff51e5bb8bd 100644 (file)
@@ -111,7 +111,7 @@ SKIP: {
        is(HTTP::Date::time2str($bare->{modified}), $h{'Last-Modified'},
                'modified field and Last-Modified header match');
 
-       ok($manifest->{'/v2/0'}, 'v2 epoch appeared');
+       ok($manifest->{'/v2/git/0.git'}, 'v2 epoch appeared');
 
        skip 'skipping grok-pull integration test', 2 if !which('grok-pull');
 
@@ -130,7 +130,7 @@ mymanifest = $tmpdir/local-manifest.js.gz
 
        system(qw(grok-pull -c), "$tmpdir/repos.conf");
        is($? >> 8, 127, 'grok-pull exit code as expected');
-       for (qw(alt bare v2/0 v2/1 v2/2)) {
+       for (qw(alt bare v2/git/0.git v2/git/1.git v2/git/2.git)) {
                ok(-d "$tmpdir/mirror/$_", "grok-pull created $_");
        }
 
@@ -150,7 +150,7 @@ mymanifest = $tmpdir/per-inbox-manifest.js.gz
        ok(mkdir("$tmpdir/per-inbox"), 'prepare single-v2-inbox mirror');
        system(qw(grok-pull -c), "$tmpdir/per-inbox.conf");
        is($? >> 8, 127, 'grok-pull exit code as expected');
-       for (qw(v2/0 v2/1 v2/2)) {
+       for (qw(v2/git/0.git v2/git/1.git v2/git/2.git)) {
                ok(-d "$tmpdir/per-inbox/$_", "grok-pull created $_");
        }
 }