[PATCH] feat: Mirroring support for quiet manual mirror

3 views
Skip to first unread message

Robin H. Johnson

unread,
Mar 14, 2024, 1:19:58 AMMar 14
to sita...@gmail.com, gito...@googlegroups.com, Robin H. Johnson
Add copies type `nosync-quiet`, that offers nosync behavior without
triggering the warning on every push. Useful to manually sync a mirror
at specific times while not impacting regular work.

Signed-off-by: Robin H. Johnson <rob...@gentoo.org>
---
src/lib/Gitolite/Triggers/Mirroring.pm | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/lib/Gitolite/Triggers/Mirroring.pm b/src/lib/Gitolite/Triggers/Mirroring.pm
index 07b7f96..dd33354 100644
--- a/src/lib/Gitolite/Triggers/Mirroring.pm
+++ b/src/lib/Gitolite/Triggers/Mirroring.pm
@@ -194,15 +194,16 @@ sub post_git {

sub copies {
my $repo = shift;
+ my %out;

my $ref = git_config( $repo, "^gitolite-options\\.mirror\\.copies.*" );
- my %out = map { $_ => 'async' } map { split } values %$ref;
+ map { $out{$_} = 'async' } map { split } values %$ref;

- $ref = git_config( $repo, "^gitolite-options\\.mirror\\.copies\\.sync.*" );
- map { $out{$_} = 'sync' } map { split } values %$ref;
-
- $ref = git_config( $repo, "^gitolite-options\\.mirror\\.copies\\.nosync.*" );
- map { $out{$_} = 'nosync' } map { split } values %$ref;
+ my @sync_types = qw(sync async nosync nosync-quiet);
+ foreach my $sync_type ( @sync_types ) {
+ $ref = git_config( $repo, "^gitolite-options\\.mirror\\.copies\\.${sync_type}.*" );
+ map { $out{$_} = $sync_type } map { split } values %$ref;
+ }

return %out;
}
@@ -237,9 +238,14 @@ sub push_to_copies {
my $lb = "$ENV{GL_REPO_BASE}/$repo.git/.gl-mirror-lock";
for my $s ( sort keys %copies ) {
trace( 1, "push_to_copies skipping self" ), next if $s eq $hn;
- system("gitolite 1plus1 $lb.$s gitolite mirror push $s $repo </dev/null >/dev/null 2>&1 &") if $copies{$s} eq 'async';
- system("gitolite 1plus1 $lb.$s gitolite mirror push $s $repo </dev/null >/dev/null 2>&1") if $copies{$s} eq 'sync';
- _warn "manual mirror push pending for '$s'" if $copies{$s} eq 'nosync';
+ my $mirror_command = "gitolite 1plus1 $lb.$s gitolite mirror push $s $repo </dev/null >/dev/null 2>&1";
+ switch($copies{$s}) {
+ case 'async' { system($mirror_command . " &"); }
+ case 'sync' { system($mirror_command); }
+ case 'nosync' { _warn "manual mirror push pending for '$s'"; }
+ case 'nosync-quiet' { 1; }
+ else { _warn "unknown mirror copy type $copies{$s} for '$s'"; }
+ }
}

$ENV{GL_USER} = $u;
--
2.44.0

Robin H. Johnson

unread,
May 12, 2024, 4:15:22 PMMay 12
to sita...@gmail.com, gito...@googlegroups.com, Robin H. Johnson
Add copies type `nosync-quiet`, that offers nosync behavior without
triggering the warning on every push. Useful to manually sync a mirror
at specific times while not impacting regular work.

Signed-off-by: Robin H. Johnson <rob...@gentoo.org>
---
src/lib/Gitolite/Triggers/Mirroring.pm | 28 +++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)

v2: Replace switch keyword with if/else ladder; switch worked due to use Switch in local env.

diff --git a/src/lib/Gitolite/Triggers/Mirroring.pm b/src/lib/Gitolite/Triggers/Mirroring.pm
index 07b7f96..b05b2cf 100644
--- a/src/lib/Gitolite/Triggers/Mirroring.pm
+++ b/src/lib/Gitolite/Triggers/Mirroring.pm
@@ -194,15 +194,16 @@ sub post_git {

sub copies {
my $repo = shift;
+ my %out;

my $ref = git_config( $repo, "^gitolite-options\\.mirror\\.copies.*" );
- my %out = map { $_ => 'async' } map { split } values %$ref;
+ map { $out{$_} = 'async' } map { split } values %$ref;

- $ref = git_config( $repo, "^gitolite-options\\.mirror\\.copies\\.sync.*" );
- map { $out{$_} = 'sync' } map { split } values %$ref;
-
- $ref = git_config( $repo, "^gitolite-options\\.mirror\\.copies\\.nosync.*" );
- map { $out{$_} = 'nosync' } map { split } values %$ref;
+ my @sync_types = qw(sync async nosync nosync-quiet);
+ foreach my $sync_type ( @sync_types ) {
+ $ref = git_config( $repo, "^gitolite-options\\.mirror\\.copies\\.${sync_type}.*" );
+ map { $out{$_} = $sync_type } map { split } values %$ref;
+ }

return %out;
}
@@ -237,9 +238,18 @@ sub push_to_copies {
my $lb = "$ENV{GL_REPO_BASE}/$repo.git/.gl-mirror-lock";
for my $s ( sort keys %copies ) {
trace( 1, "push_to_copies skipping self" ), next if $s eq $hn;
- system("gitolite 1plus1 $lb.$s gitolite mirror push $s $repo </dev/null >/dev/null 2>&1 &") if $copies{$s} eq 'async';
- system("gitolite 1plus1 $lb.$s gitolite mirror push $s $repo </dev/null >/dev/null 2>&1") if $copies{$s} eq 'sync';
- _warn "manual mirror push pending for '$s'" if $copies{$s} eq 'nosync';
+ my $mirror_command = "gitolite 1plus1 $lb.$s gitolite mirror push $s $repo </dev/null >/dev/null 2>&1";
+ if ($copies{$s} eq 'async') {
+ system($mirror_command . " &");
+ } elsif ($copies{$s} eq 'sync') {
+ system($mirror_command);
+ } elsif ($copies{$s} eq 'nosync') {
+ _warn "manual mirror push pending for '$s'";
+ } elsif ($copies{$s} eq 'nosync-quiet') {
+ 1;
+ } else {
+ _warn "unknown mirror copy type $copies{$s} for '$s'";
+ }
}

$ENV{GL_USER} = $u;
--
2.45.0

Sitaram Chamarty

unread,
May 27, 2024, 9:54:48 PMMay 27
to Robin H. Johnson, gito...@googlegroups.com
On Sun, May 12, 2024 at 01:15:09PM -0700, Robin H. Johnson wrote:
> Add copies type `nosync-quiet`, that offers nosync behavior without
> triggering the warning on every push. Useful to manually sync a mirror
> at specific times while not impacting regular work.

Pushed; thank you! (And apologies for the delay!)

On a related note, last release (3.6.13) was July 2023 and this
change is the only code change since then. I'm reluctant to
push out 3.6.14 just for this but if you (or indeed anyone on
the list) feels it is required I can do that.

sitaram
Reply all
Reply to author
Forward
0 new messages