From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A92C51F47E for ; Thu, 5 Jan 2023 11:41:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1672918917; bh=BdcEwgnK+k4Q6TUKeavMB88KLjfEO1CTrMkAH8AFJq4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=L8ln47zVyBx6GfgY+xOiiOFzd0JEWMucObMouAYeHg3kEhaePMeTo4t6Mb5ydrjeW GSyqcHDVFn7i4A2U5DkHjF9vnez9T3VxWw0ER6AJpRjT0h0Fy+UdCA6EJwcN1wRENJ XojGH/xvBfAW6J9DQj3SuDjM1qMZwuTMrtLaKD5M= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/2] clone: implement --exit-code Date: Thu, 5 Jan 2023 11:41:57 +0000 Message-Id: <20230105114157.2239454-3-e@80x24.org> In-Reply-To: <20230105114157.2239454-1-e@80x24.org> References: <20230105114157.2239454-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Since public-inbox-clone is now useful for incremental updates with manifest, --exit-code belongs here, too. --- Documentation/public-inbox-clone.pod | 6 ++++++ lib/PublicInbox/LeiMirror.pm | 12 +++++++++++- script/public-inbox-clone | 2 +- t/clone-coderepo.t | 6 +++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Documentation/public-inbox-clone.pod b/Documentation/public-inbox-clone.pod index 53acf356..7498aed9 100644 --- a/Documentation/public-inbox-clone.pod +++ b/Documentation/public-inbox-clone.pod @@ -136,6 +136,12 @@ order specified on the command-line. Pass the C<--prune> and C<--prune-tags> flags to L calls on incremental clones. +=item --exit-code + +Exit with C<127> if no updates are done when relying on a manifest. +Updates include fingerprint mismatches in the manifest, new symlinks, +new repositories, and removed repositories from the L<--project-list> + =item -k =item --keep-going diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm index 34a4bd1c..db249ece 100644 --- a/lib/PublicInbox/LeiMirror.pm +++ b/lib/PublicInbox/LeiMirror.pm @@ -516,6 +516,7 @@ sub resume_fetch { fetch_args($self->{lei}, $opt), $rn ]; push @$cmd, '-P' if $self->{lei}->{prune}; # --prune-tags implied my $run_puh = PublicInbox::OnDestroy->new($$, \&run_puh, $self, $fini); + ++$self->{chg}->{nr_chg}; start_cmd($self, $cmd, $opt, $run_puh); } @@ -533,6 +534,7 @@ sub fgrp_enqueue { $fgrp->{dry_run} ? $fgrp->{lei}->qerr("# @cmd @kv") : run_die([@cmd, @kv], undef, $opt); } + ++$fgrp->{chg}->{nr_chg}; push @{$FGRP_TODO->{$fgrp->{-osdir}}}, $fgrp; } @@ -565,6 +567,7 @@ sub clone_v1 { "$self->{dst}$ref"; } } + ++$self->{chg}->{nr_chg}; start_cmd($self, $cmd, $opt, PublicInbox::OnDestroy->new($$, \&run_puh, $self, $fini)); } @@ -750,6 +753,7 @@ sub update_ent { } } symlink($tgt, $ln) or die "symlink($tgt, $ln): $!"; + ++$self->{chg}->{nr_chg}; } } if (defined(my $t = $self->{-ent}->{modified})) { @@ -1051,6 +1055,7 @@ EOM warn "\t", $_, "\n" for @local; my (undef, $dn, $bn) = File::Spec->splitpath($f); + $self->{chg}->{nr_chg} += scalar(@remote) + scalar(@local); atomic_write($dn, $bn, join("\n", @list, '')); } @@ -1082,7 +1087,10 @@ sub try_manifest { } # bail out if curl -z/--timecond hit 304 Not Modified, $ft will be empty - return $lei->qerr("# $manifest unchanged") if -f $manifest && !-s $ft; + if (-f $manifest && !-s $ft) { + $lei->child_error(127 << 8) if $lei->{opt}->{'exit-code'}; + return $lei->qerr("# $manifest unchanged"); + } my $m = eval { decode_manifest($ft, $ft, $uri) }; if ($@) { @@ -1170,6 +1178,8 @@ W: The following exist and have not been converted to symlinks EOM dump_project_list($self, $m); ft_rename($ft, $manifest, 0666); + !$self->{chg}->{nr_chg} && $lei->{opt}->{'exit-code'} and + $lei->child_error(127 << 8); } sub start_clone_url { diff --git a/script/public-inbox-clone b/script/public-inbox-clone index 6ed7ab6b..e93ac37b 100755 --- a/script/public-inbox-clone +++ b/script/public-inbox-clone @@ -28,7 +28,7 @@ EOF 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 post-update-hook=s@ - prune|p keep-going|k + prune|p keep-going|k exit-code dry-run|n jobs|j=i no-torsocks torsocks=s epoch=s)) or die $help; if ($opt->{help}) { print $help; exit }; require PublicInbox::Admin; # loads Config diff --git a/t/clone-coderepo.t b/t/clone-coderepo.t index 66eaa030..2e628963 100644 --- a/t/clone-coderepo.t +++ b/t/clone-coderepo.t @@ -86,7 +86,7 @@ EOM } my $cmd = [qw(-clone --inbox-config=never --manifest= --project-list= - --objstore= -p -q), $url, "$tmpdir/dst"]; + --objstore= -p -q), $url, "$tmpdir/dst", '--exit-code']; ok(run_script($cmd), 'clone'); is(xqx([qw(git config gitweb.owner)], { GIT_DIR => "$tmpdir/dst/a.git" }), "Alice\n", 'a.git gitweb.owner set'); @@ -149,6 +149,10 @@ my $test_puh = sub { unlink($log) or xbail "unlink: $!"; ok(run_script($x, $env), "no-op clone @clone_arg w/ post-update-hook"); ok(!-e $log, "hooks not run on no-op @clone_arg"); + + push @$x, '--exit-code'; + ok(!run_script($x, $env), 'no-op clone w/ --exit-code fails'); + is($? >> 8, 127, '--exit-code gave 127'); }; $test_puh->(); ok(!-e "$tmpdir/dst/objstore", 'no objstore, yet');