From 47fde0f16d620dbf8670133ef32db6e65565914c Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 8 Sep 2021 19:05:36 -0400 Subject: Add group threshold to git-comment Only add comments for blame groups larger than 1 line by default. --- bin/git-comment.pl | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/bin/git-comment.pl b/bin/git-comment.pl index 53a0c1d5..17b9da64 100644 --- a/bin/git-comment.pl +++ b/bin/git-comment.pl @@ -10,22 +10,36 @@ use Git; my $repo = Git->repository(); -my $comment_start = $repo->config('comment.start') // "/*"; -my $comment_lead = $repo->config('comment.lead') // " *"; -my $comment_end = $repo->config('comment.end') // " */"; +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; GetOptions( - 'comment-start=s' => \$comment_start, - 'comment-lead=s' => \$comment_lead, - 'comment-end:s' => \$comment_end, + 'comment-start=s' => \$commentStart, + 'comment-lead=s' => \$commentLead, + 'comment-end:s' => \$commentEnd, + 'group-threshold=i' => \$threshold, ) 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$commentEnd\n" if $commentEnd; +} + my ($pipe, $ctx) = $repo->command_output_pipe('blame', '--porcelain', @ARGV); -my ($commit, %abbrev, %summary, %body, %printed); +my ($commit, $group, $printed, %abbrev, %summary, %body); while (<$pipe>) { chomp; - if (/^([[:xdigit:]]+) \d+ \d+ \d+/) { - $commit = $1; + if (/^([[:xdigit:]]+) \d+ \d+ (\d+)/) { + ($commit, $group, $printed) = ($1, $2, 0); next if $abbrev{$commit}; my @body = $repo->command( 'show', '--no-patch', '--pretty=format:%h%n%b', $commit @@ -36,16 +50,12 @@ while (<$pipe>) { $summary{$commit} = $1; } elsif (/^\t(\s*)(.*)/) { my ($indent, $line) = ($1, $2); - if (@{$body{$commit}} && !$printed{$commit}) { - print "$indent$comment_start $abbrev{$commit} $summary{$commit}\n"; - print "$indent$comment_lead\n"; - foreach (@{$body{$commit}}) { - print "$indent$comment_lead"; - print " $_" if $_; - print "\n"; - } - print "$indent$comment_end\n" if $comment_end; - $printed{$commit} = 1; + if (@{$body{$commit}} && $group > $threshold && !$printed) { + printComment( + $indent, $abbrev{$commit}, $summary{$commit}, + @{$body{$commit}} + ); + $printed = 1; } print "$indent$line\n"; } -- cgit 1.4.1 >Commit message (Expand)Author 2019-01-10Replace sys_nsig with NSIGJune McEnroe 2019-01-10Replace cash MakefileJune McEnroe 2019-01-10Move bltin out of subdirectoryJune McEnroe/torus/commit/snapshot.sh?id=759c95e445ad33416bc8b692ce4b7fd5d8c7b522&follow=1'>Copy CSVs to web directory from snapshot.shJune McEnroe 2021-09-27Extract chroot.tar with -p, install to WEBROOTJune McEnroe 2021-09-26OpenBSD: Copy appropriate files for chrootJune McEnroe 2021-09-26OpenBSD: pledge(2) imageJune McEnroe 2021-09-26OpenBSD: pledge(2) clientJune McEnroe 2021-09-26OpenBSD: pledge(2) serverJune McEnroe 2021-09-24Link with -lncurseswJune McEnroe 2021-09-20Replace strlcpy with snprintfJune McEnroe 2021-09-20Replace kqueue with poll, remove libutil dependencyJune McEnroe 2021-02-04Update play@ascii.town descriptionJune McEnroe 2021-02-04Replace donation button with LiberapayJune McEnroe 2020-06-25Use DisableForwarding in sshd_configJune McEnroe 2019-12-19Remove READMEJune McEnroe 2019-12-15Update git URLsJune McEnroe 2019-08-05Add buymeacoffee linkJune McEnroe 2019-07-27Use braces in MakefileJune McEnroe 2019-07-08Remove NetHack from indexJune McEnroe 2019-04-08Don't install rc.kfcgi eitherJune McEnroe 2019-03-28Remove rc.kfcgiJune McEnroe 2019-01-16Reformat index.html with explore linkJune McEnroe 2019-01-16Return false from keydown handler in exploreJune McEnroe 2019-01-08Draw lines to tile edgeJune McEnroe 2019-01-08Factor out default pathsJune McEnroe 2019-01-08Remove incorrect default coordinatesJune McEnroe 2019-01-07Set img src when explore fragment changesJune McEnroe 2019-01-07Compress PNG data in imageJune McEnroe 2019-01-07madvise MADV_NOCORE in imageJune McEnroe 2019-01-07Add license notice to explore JavaScriptJune McEnroe 2019-01-07Add Q/Home binding in exploreJune McEnroe 2019-01-07Fix explore image URLJune McEnroe 2019-01-07Add HOME button, ssh link, AGPL notice to exploreJune McEnroe 2019-01-06Add meta viewport to exploreJune McEnroe 2019-01-06Set background and max-width in exploreJune McEnroe 2019-01-06Swallow writes after the connection is closedJune McEnroe 2019-01-06Handle KCGI_HUPJune McEnroe 2019-01-06Install html filesJune McEnroe