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,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 EE1851F9F3 for ; Wed, 15 Sep 2021 21:35:59 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/5] clone|fetch|--mirror: add convenience $INBOX_DIR/Makefile Date: Wed, 15 Sep 2021 21:35:57 +0000 Message-Id: <20210915213559.21757-4-e@80x24.org> In-Reply-To: <20210915213559.21757-1-e@80x24.org> References: <20210915213559.21757-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Since the beginning of time, I've been dropping Makefiles in $INBOX_DIR (and above hiearchies) to organize groups of commands. make(1) is widely available in various flavors and a familiar tool for our target audience. It is easy to run in the right directory, typically has built-in shell completion, and doesn't silently ignore errors by default like Bourne shell. --- lib/PublicInbox/Fetch.pm | 3 +- lib/PublicInbox/LeiMirror.pm | 61 +++++++++++++++++++++++++++++++++++- t/lei-mirror.t | 2 ++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/Fetch.pm b/lib/PublicInbox/Fetch.pm index 0539fe50..184b4f26 100644 --- a/lib/PublicInbox/Fetch.pm +++ b/lib/PublicInbox/Fetch.pm @@ -91,7 +91,7 @@ sub get_fingerprint2 { Digest::SHA::sha256(do { local $/; <$rd> }); } -sub do_fetch { +sub do_fetch { # main entry point my ($cls, $lei, $cd) = @_; my $ibx_ver; $lei->{curl} //= PublicInbox::LeiCurl->new($lei) or return; @@ -124,6 +124,7 @@ Unable to infer inbox URL from <$git_url> EOM $ibx_uri = URI->new($inbox_url); } + PublicInbox::LeiMirror::write_makefile($dir, $ibx_ver); $lei->qerr("# inbox URL: $ibx_uri/"); my $res = do_manifest($lei, $dir, $ibx_uri) or return; my ($code, $v1_path, $v2_epochs, $muri, $ft, $mf) = @$res; diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm index c113c9de..749c6b7d 100644 --- a/lib/PublicInbox/LeiMirror.pm +++ b/lib/PublicInbox/LeiMirror.pm @@ -9,7 +9,7 @@ use parent qw(PublicInbox::IPC); use IO::Uncompress::Gunzip qw(gunzip $GunzipError); use PublicInbox::Spawn qw(popen_rd spawn run_die); use File::Temp (); -use Fcntl qw(SEEK_SET); +use Fcntl qw(SEEK_SET O_CREAT O_EXCL O_WRONLY); sub do_finish_mirror { # dwaitpid callback my ($arg, $pid) = @_; @@ -201,6 +201,7 @@ sub clone_v1 { my $cerr = run_reap($lei, $cmd, $opt); return $lei->child_error($cerr, "@$cmd failed") if $cerr; _try_config($self); + write_makefile($self->{dst}, 1); index_cloned_inbox($self, 1); } @@ -234,6 +235,7 @@ failed to extract epoch number from $src my $mg = PublicInbox::MultiGit->new($dst, 'all.git', 'git'); $mg->fill_alternates; for my $i ($mg->git_epochs) { $mg->epoch_cfg_set($i) } + write_makefile($self->{dst}, 2); undef $on_destroy; # unlock index_cloned_inbox($self, 2); } @@ -356,4 +358,61 @@ sub ipc_atfork_child { $self->SUPER::ipc_atfork_child; } +sub write_makefile { + my ($dir, $ibx_ver) = @_; + my $f = "$dir/Makefile"; + if (sysopen my $fh, $f, O_CREAT|O_EXCL|O_WRONLY) { + print $fh < $tmpdir }, sub { ok(-f "$t1/public-inbox/msgmap.sqlite3", 't1-mirror indexed'); is(PublicInbox::Inbox::try_cat("$t1/description"), "mirror of $http/t1/\n", 'description set'); + ok(-f "$t1/Makefile", 'convenience Makefile added (v1)'); lei_ok('ls-external'); like($lei_out, qr!\Q$t1\E!, 't1 added to ls-externals'); @@ -27,6 +28,7 @@ test_lei({ tmpdir => $tmpdir }, sub { lei_ok('add-external', $t2, '--mirror', "$http/t2/", \'--mirror v2'); ok(-f "$t2/msgmap.sqlite3", 't2-mirror indexed'); ok(-f "$t2/description", 't2 description'); + ok(-f "$t2/Makefile", 'convenience Makefile added (v2)'); is(PublicInbox::Inbox::try_cat("$t2/description"), "mirror of $http/t2/\n", 'description set');