summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-09-08 21:05:33 -0400
committerJune McEnroe <june@causal.agency>2021-09-08 21:05:33 -0400
commit9ee84006e78a59631bf889bdd7631e73da480614 (patch)
treed2ac3123c5cb58955b6eb4ac0dacbf806aa8fd84
parentAdd group threshold to git-comment (diff)
downloadsrc-9ee84006e78a59631bf889bdd7631e73da480614.tar.gz
src-9ee84006e78a59631bf889bdd7631e73da480614.zip
Add repeat and all options to git-comment
-rw-r--r--bin/git-comment.pl52
1 files 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";
 	}