git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH gitweb] Visually indicating patch size with horizontal bars

From
CSChris Shoemaker <c.shoemaker@cox.net>
Date
Oct 27, 2005, 20:39 UTC
Message-ID
<20051027203945.GC1622@pe.Belkin>

I really like gitweb (thanks Kay!), but I thought it would be nice to have a visual indication of patch size. I found this helpful when scanning though the shortlogs.

To see what it looks like with the gitweb for gitweb (meta-gitweb?) goto:

http://www.codesifter.com/cgi-bin/gitweb.cgi?p=gitweb.git;a=shortlog

I rather like the look of what I've hacked up (the enclosed patch), but it should be considered as just a prototype: it only affects the shortlog, it's horribly inefficient, and I don't really do perl. :)

If anyone thinks this is a good feature, then please tell me an efficient way to get some heuristic of the patch size.

Right now, I'm using: 
GIT_DIFF_OPTS='-U 0' $gitbin/git-diff-tree -p $hash | wc -l
which is pretty slow.  Any suggestions?
-chris
Subject: [PATCH] initial hack at horizontal bars indicating patch size
---
 gitweb.cgi |   38 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 37 insertions(+), 1 deletions(-)
c8d45f9a3cfdd7080a57e0de315f3ab9475f60bf
diff --git a/gitweb.cgi b/gitweb.cgi
--- a/gitweb.cgi
+++ b/gitweb.cgi
@@ -53,6 +53,9 @@ if (defined $action) {
 	} elsif ($action eq "opml") {
 		git_opml();
 		exit;
+	} elsif ($action eq "bar.png") {
+	    git_bar_png();
+	    exit;
 	}
 }
 
@@ -358,6 +361,16 @@ sub git_get_type {
 	return $type;
 }
 
+sub git_get_commit_size {
+	my $hash = shift;
+
+	open my $fd, "-|", "GIT_DIFF_OPTS='-U 0' $gitbin/git-diff-tree -p $hash | wc -l" or return;
+	my $size = <$fd>;
+	close $fd or return;
+	chomp $size;
+	return $size;
+}
+
 sub git_read_hash {
 	my $path = shift;
 
@@ -719,6 +732,21 @@ sub git_logo {
 		"\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
 }
 
+# git_bar_png (cached in browser for one day)
+sub git_bar_png {
+	print $cgi->header(-type => 'image/png', -expires => '+1d');
+        # cat bar.png | hexdump -e '"q" 16/1 "w%02x"  "q . \n"' | 
+        #    sed 's/w/\\x/g' | sed 's/q/"/g'
+print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
+"\x00\x00\x00\x01\x00\x00\x00\x0c\x08\x02\x00\x00\x00\x2c\xe9\x40" .
+"\x00\x00\x00\x00\x3b\x49\x44\x41\x54\x08\x1d\x01\x30\x00\xcf\xff" .
+"\x00\xba\xba\xff\x02\xf1\xf1\x00\x02\xf2\xf2\x00\x02\xf1\xf2\x00" .
+"\x02\xf2\xf1\x00\x02\xf1\xf1\x00\x02\xf2\xf1\x00\x02\xf1\xf1\x00" .
+"\x02\xf1\xf2\x00\x02\xf1\xf1\x00\x02\xf2\xf2\x00\x02\xf2\xf1\x00" .
+"\x45\x85\x17\x49\x14\x70\x67\xdb\x00\x00\x00\x00\x49\x45\x4e\x44" .
+"\xae\x42\x60\x82";
+}
+
 sub get_file_owner {
 	my $path = shift;
 
@@ -2280,8 +2308,16 @@ sub git_shortlog {
 		      "<td class=\"link\">" .
 		      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
 		      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
-		      "</td>\n" .
+		      "</td>\n";
+		my $scale = 100;
+		my $stretch = 32;
+		# commits of size 1.7*$scale will be $stretch pixels wide 
+		my $size = int(log((git_get_commit_size($commit)+$scale)/$scale)*$stretch);
+		print "<td class=\"bar\">" .
+		      "<img src=\"$my_uri?a=bar.png\" width=\"$size\" height=\"12\"/>" .
+		      "</td>" .
 		      "</tr>";
+
 	}
 	if ($#revlist >= (100 * ($page+1)-1)) {
 		print "<tr>\n" .
Next: Junio C Hamano
Message 1 of 27 in “Visually indicating patch size with horizontal bars”
  1. Visually indicating patch size with horizontal barsChris Shoemaker, Oct 27, 2005
  2. Junio C HamanoOct 27, 2005
  3. Chris ShoemakerOct 27, 2005
  4. Linus TorvaldsOct 28, 2005
  5. Chris ShoemakerOct 28, 2005
  6. Martin LanghoffOct 28, 2005
  7. H. Peter AnvinOct 28, 2005
  8. Andreas EricssonOct 28, 2005
  9. Junio C HamanoOct 28, 2005
  10. Martin LanghoffOct 28, 2005
  11. Linus TorvaldsOct 28, 2005
  12. Junio C HamanoOct 28, 2005
  13. Linus TorvaldsOct 28, 2005
  14. Kay SieversOct 28, 2005
  15. Chris ShoemakerOct 28, 2005
  16. Petr BaudisNov 1, 2005
  17. Martin LanghoffNov 1, 2005
  18. Petr BaudisNov 1, 2005
  19. Andreas EricssonNov 2, 2005
  20. Johannes SchindelinNov 2, 2005
  21. Andreas EricssonNov 2, 2005
  22. Johannes SchindelinNov 2, 2005
  23. Chris ShoemakerNov 2, 2005
  24. Kay SieversNov 2, 2005
  25. Petr BaudisDec 5, 2005
  26. Chris ShoemakerDec 5, 2005
  27. Josef WeidendorferOct 28, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.