From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id BA11A1F97F for ; Sun, 9 Jun 2019 04:31:06 +0000 (UTC) From: "Eric Wong (Contractor, The Linux Foundation)" To: meta@public-inbox.org Subject: [PATCH 4/4] www: support $INBOX/git/$EPOCH.git for v2 cloning Date: Sun, 9 Jun 2019 04:31:05 +0000 Message-Id: <20190609043105.22338-5-e@80x24.org> In-Reply-To: <20190609043105.22338-1-e@80x24.org> References: <20190609043105.22338-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 4 ++-- lib/PublicInbox/WwwListing.pm | 2 +- t/psgi_v2.t | 2 ++ t/v2mirror.t | 8 +++++--- t/www_listing.t | 6 +++--- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index a546698..e468263 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -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); diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm index 690976a..e2724cc 100644 --- a/lib/PublicInbox/WwwListing.pm +++ b/lib/PublicInbox/WwwListing.pm @@ -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); diff --git a/t/psgi_v2.t b/t/psgi_v2.t index 9811249..5c358cd 100644 --- a/t/psgi_v2.t +++ b/t/psgi_v2.t @@ -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'); diff --git a/t/v2mirror.t b/t/v2mirror.t index fe05ec4..c31dcd5 100644 --- a/t/v2mirror.t +++ b/t/v2mirror.t @@ -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', diff --git a/t/www_listing.t b/t/www_listing.t index 546c2f8..2741e1b 100644 --- a/t/www_listing.t +++ b/t/www_listing.t @@ -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 $_"); } } -- EW