git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH gitweb] Visually indicating patch size with horizontal bars
@ 2005-10-27 20:39 Chris Shoemaker
  2005-10-27 22:02 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Chris Shoemaker @ 2005-10-27 20:39 UTC (permalink / raw)
  To: git


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" .

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2005-12-05  1:03 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-27 20:39 [PATCH gitweb] Visually indicating patch size with horizontal bars Chris Shoemaker
2005-10-27 22:02 ` Junio C Hamano
2005-10-27 23:48   ` Chris Shoemaker
2005-10-28  0:12     ` Linus Torvalds
2005-10-28  0:50       ` Chris Shoemaker
2005-10-28  1:08         ` Martin Langhoff
2005-10-28  1:13         ` H. Peter Anvin
2005-10-28  8:29           ` Andreas Ericsson
2005-10-28  9:31         ` Junio C Hamano
2005-10-28  1:16   ` Martin Langhoff
2005-10-28  2:38     ` Linus Torvalds
2005-10-28  3:52       ` Junio C Hamano
2005-10-28 16:02         ` Linus Torvalds
2005-10-28  1:56 ` Kay Sievers
2005-10-28  2:38   ` Chris Shoemaker
2005-11-01 23:30     ` Petr Baudis
2005-11-01 23:33       ` Martin Langhoff
2005-11-01 23:43         ` Petr Baudis
2005-11-02  8:08           ` Andreas Ericsson
2005-11-02 10:37             ` Johannes Schindelin
2005-11-02 12:19               ` Andreas Ericsson
2005-11-02 12:43                 ` Johannes Schindelin
2005-11-02  0:12         ` Chris Shoemaker
2005-11-02  0:26           ` Kay Sievers
2005-12-05  0:04           ` Petr Baudis
2005-12-05  1:03             ` Chris Shoemaker
2005-10-28  9:16 ` Josef Weidendorfer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).