Meta/add-by: support --mine=<sig> to keep the trailer at the end

Junio C Hamano committed Sep 9, 2022 at 15:11 UTC ddb098fc287671a8329e9a4cd559c2cde43ceb1f
1 file changed +36 -15
add-by
+36 -15
@@ -46,22 +46,32 @@ sub accumulate {
46 push @more, [@_];
47 }
48
49 +my $mine;
50 +
51 +sub compute_bylines {
52 + my %names = map { $_->[1] => 1 } @more;
53 + my %map = ();
54 + my @append;
55 + find_author(\%map, keys (%names));
56 + for (@more) {
57 + my ($tag, $name) = @$_;
58 + if ($tag eq 'mine') {
59 + $mine = $map{$name};
60 + next;
61 + }
62 + $tag = ucfirst($tag);
63 + push @append, "$tag: $map{$name}";
64 + }
65 + if (@append) {
66 + $append = join("\n", @append) . "\n";
67 + } else {
68 + $append = "";
69 + }
70 +}
71 +
72 sub add_more_bylines {
73 if (!defined $append) {
51 - my %names = map { $_->[1] => 1 } @more;
52 - my %map = ();
53 - my @append;
54 - find_author(\%map, keys (%names));
55 - for (@more) {
56 - my ($tag, $name) = @$_;
57 - $tag = ucfirst($tag);
58 - push @append, "$tag: $map{$name}";
59 - }
60 - if (@append) {
61 - $append = join("\n", @append) . "\n";
62 - } else {
63 - $append = "";
64 - }
74 + compute_bylines();
75 }
76 print $append;
77 }
@@ -74,25 +84,36 @@ exit 1 unless (GetOptions("signed-off-by=s" => \&accumulate,
84 "tested-by=s" => \&accumulate,
85 "helped-by=s" => \&accumulate,
86 "check-only!" => \$check_only,
87 + "mine=s" => \&accumulate,
88 "debug!" => \$debug,
89 ));
90
91 +compute_bylines();
92 +
93 if ($check_only) {
94 add_more_bylines();
95 exit 0;
96 }
97
98 +my $seen_mine = 0;
99 while (<>) {
100 if ($state == parsing) {
101 if (/^[-A-Za-z]+-by: /i || /^Cc: /i) {
102 $state = waiting;
103 }
104 } elsif ($state == waiting) {
91 - if (/^[-A-Za-z]+-by: /i || /^Cc: /i) {
105 + if (defined $mine && /^Signed-off-by: \Q$mine\E/) {
106 + $seen_mine = 1;
107 + next;
108 + } elsif (/^[-A-Za-z]+-by: /i || /^Cc: /i) {
109 $state = waiting;
110 } else {
111 add_more_bylines();
112 + if ($seen_mine) {
113 + print "Signed-off-by: $mine\n";
114 + }
115 $state = parsing;
116 + $seen_mine = 0;
117 }
118 }
119 print;