* [PATCH 2/2] clone: implement --exit-code
2023-01-05 11:41 [PATCH 0/2] public-inbox-clone updates Eric Wong
2023-01-05 11:41 ` [PATCH 1/2] clone: document --project-list and --post-update-hook Eric Wong
@ 2023-01-05 11:41 ` Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2023-01-05 11:41 UTC (permalink / raw)
To: meta
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<git-fetch(1)>
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');
^ permalink raw reply related [flat|nested] 3+ messages in thread