From 2d617a0af86e4f624dcc4843e43e758d16061937 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 30 Dec 2017 21:00:14 -0800 Subject: [PATCH] Notify.pm: make ref_change function private The "ref-change" message to taskd.pl has been obsolete for some time. However, the implementation was still directly calling the Girocco::Notify::ref_change function. We want all notifications to come through the one canonical Girocco::Notify::ref_changes function. Make Girocco::Notify::ref_change truly private (it's still used as part of the implementation of the ref_changes function) and modify taskd.pl to submit obsolete one-ref-at-a-time notifications received using the obsolete "ref-change" message through the Girocco::Notify::ref_changes function instead. With a single point of entry in Notify.pm, future extensions are greatly simplified. Signed-off-by: Kyle J. McKay --- Girocco/Notify.pm | 9 +++++---- taskd/taskd.pl | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Girocco/Notify.pm b/Girocco/Notify.pm index 8fbc90c..1087967 100644 --- a/Girocco/Notify.pm +++ b/Girocco/Notify.pm @@ -243,7 +243,8 @@ sub _notify_for_ref { $_[0] =~ m{^refs/heads/.} || $_[0] =~ m{^refs/tags/.}; } -sub ref_change { +my $_ref_change; +BEGIN {$_ref_change = sub { my ($proj, $user, $ref, $oldrev, $newrev) = @_; _notify_for_ref($ref) or return 0; @@ -279,7 +280,7 @@ sub ref_change { } return $mail_sh_ran; -} +}} # ref_changes($proj, $user, [$coderef,] [$oldrefs,] @changes) # $coderef gets called with ($oldrev, $newrev, $refname, $mail_sh_ran) as each @@ -346,7 +347,7 @@ sub ref_changes { foreach my $change (sort {&$headcmp($$a[2], $$b[2])} @{$updates{$_}}) { my ($old, $new, $ref) = @$change; $ENV{MAIL_SH_OTHER_BRANCHES} = join(' ', values(%curheads)); - my $ran_mail_sh = ref_change($proj, $user, $ref, $old, $new); + my $ran_mail_sh = &$_ref_change($proj, $user, $ref, $old, $new); &$proc($old, $new, $ref, $ran_mail_sh) if $proc; $curheads{$ref} = $new; } @@ -358,7 +359,7 @@ sub ref_changes { foreach (@_) { my ($old, $new, $ref) = @$_; if (!$newheadsdone || $ref !~ m{^refs/heads/.} || $new =~ /^0+$/) { - my $ran_mail_sh = ref_change($proj, $user, $ref, $old, $new); + my $ran_mail_sh = &$_ref_change($proj, $user, $ref, $old, $new); &$proc($old, $new, $ref, $ran_mail_sh) if $proc; } } diff --git a/taskd/taskd.pl b/taskd/taskd.pl index c66e498..dbe2f44 100755 --- a/taskd/taskd.pl +++ b/taskd/taskd.pl @@ -730,7 +730,7 @@ sub ref_change { my $ind = ref_indicator($proj->{path}, $oldrev, $newrev); statmsg "ref-$type $username $name ($ref: @{[substr($oldrev,0,$abbrev)]}$ind@{[substr($newrev,0,$abbrev)]})"; open STDIN, '<', File::Spec->devnull; - Girocco::Notify::ref_change($proj, $user, $ref, $oldrev, $newrev) if $has_notify; + Girocco::Notify::ref_changes($proj, $user, [$oldrev, $newrev, $ref]) if $has_notify; return 0; } -- 2.11.4.GIT