From ce5d7b18c0143dda7b3c9a78260b6e5ce7eec11a Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Wed, 8 Sep 2021 21:05:33 -0400 Subject: Add repeat and all options to git-comment --- bin/git-comment.pl | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/bin/git-comment.pl b/bin/git-comment.pl index 17b9da64..42ff9143 100644 --- a/bin/git-comment.pl +++ b/bin/git-comment.pl @@ -10,36 +10,46 @@ use Git; my $repo = Git->repository(); +my $all = 0; my $commentStart = $repo->config('comment.start') // "/*"; my $commentLead = $repo->config('comment.lead') // " *"; my $commentEnd = $repo->config('comment.end') // " */"; -my $threshold = $repo->config('comment.groupThreshold') // 1; +my $minGroup = $repo->config('comment.minGroup') // 2; +my $minRepeat = $repo->config('comment.minRepeat') // 20; +my $noRepeat = $repo->config_bool('comment.noRepeat'); GetOptions( + 'all' => \$all, 'comment-start=s' => \$commentStart, 'comment-lead=s' => \$commentLead, 'comment-end:s' => \$commentEnd, - 'group-threshold=i' => \$threshold, + 'min-group=i' => \$minGroup, + 'min-repeat=i' => \$minRepeat, + 'no-repeat' => \$noRepeat, ) or die; sub printComment { my ($indent, $abbrev, $summary, @body) = @_; - print "$indent$commentStart $abbrev $summary\n"; - print "$indent$commentLead\n"; - foreach (@body) { - print "$indent$commentLead"; - print " $_" if $_; - print "\n"; + print "$indent$commentStart $abbrev $summary"; + if (@body) { + print "\n$indent$commentLead\n"; + foreach (@body) { + print "$indent$commentLead"; + print " $_" if $_; + print "\n"; + } + print "$indent$commentEnd\n" if $commentEnd; + } else { + print "$commentEnd\n"; } - print "$indent$commentEnd\n" if $commentEnd; } my ($pipe, $ctx) = $repo->command_output_pipe('blame', '--porcelain', @ARGV); -my ($commit, $group, $printed, %abbrev, %summary, %body); +my ($commit, $nr, $group, $printed, %abbrev, %summary, %body, %nrs); while (<$pipe>) { chomp; - if (/^([[:xdigit:]]+) \d+ \d+ (\d+)/) { - ($commit, $group, $printed) = ($1, $2, 0); + if (/^([[:xdigit:]]+) \d+ (\d+) (\d+)/) { + ($commit, $nr, $group, $printed) = ($1, $2, $3, 0); next if $abbrev{$commit}; my @body = $repo->command( 'show', '--no-patch', '--pretty=format:%h%n%b', $commit @@ -50,12 +60,20 @@ while (<$pipe>) { $summary{$commit} = $1; } elsif (/^\t(\s*)(.*)/) { my ($indent, $line) = ($1, $2); - if (@{$body{$commit}} && $group > $threshold && !$printed) { - printComment( - $indent, $abbrev{$commit}, $summary{$commit}, - @{$body{$commit}} - ); + unless ($printed) { $printed = 1; + if ( + $group >= $minGroup && + !($noRepeat && $nrs{$commit}) && + !($nrs{$commit} && $nr < $nrs{$commit} + $minRepeat) && + ($all || @{$body{$commit}}) + ) { + $nrs{$commit} = $nr; + printComment( + $indent, $abbrev{$commit}, $summary{$commit}, + @{$body{$commit}} + ); + } } print "$indent$line\n"; } -- cgit 1.4.1