{"thread":{"id":"5414","subject":"[PATCH/RFC] gitweb: Make git_print_log generic; git_print_simplified_log uses it","startedAt":"2006-08-27T21:55:07Z","lastAt":"2006-08-27T23:11:51Z","messageCount":2,"participants":["Jakub Narebski","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"26007","messageId":"200608272355.07625.jnareb@gmail.com","threadId":"5414","inReplyTo":null,"subject":"[PATCH/RFC] gitweb: Make git_print_log generic; git_print_simplified_log uses it","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-08-27T21:55:07Z","receivedAt":"2006-08-27T21:55:07Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Collapse git_print_log and git_print_simplified_log into one\nsubroutine git_print_log.  git_print_simplified_log now simply calls\ngit_print_log with proper options.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThis patch doesn't change output any, but it makes it easy\nto add signoff lines (to not remove them) to commitdiff and log views\n(as requested by Linus).\n\nThe RFC is about style of git_print_log function. Is it a good idea\nand good implementation to pass miscelaneus options as hash values\ninstead of using fixed order of parameters, and passing 1 or undef?\nIs it a good naming of parameters like '-remove_title', or would\n'remove_title' or 'remove-title' be better?\n\n\n gitweb/gitweb.perl |   63 ++++++++++++++++++++++++++--------------------------\n 1 files changed, 31 insertions(+), 32 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex ae18c27..b6c1620 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1364,9 +1364,15 @@ sub git_print_page_path {\n \t}\n }\n \n-sub git_print_log {\n+# sub git_print_log (\\@;%) {\n+sub git_print_log ($;%) {\n \tmy $log = shift;\n+\tmy %opts = @_;\n \n+\tif ($opts{'-remove_title'}) {\n+\t\t# remove title, i.e. first line of log\n+\t\tshift @$log;\n+\t}\n \t# remove leading empty lines\n \twhile (defined $log->[0] && $log->[0] eq \"\") {\n \t\tshift @$log;\n@@ -1376,6 +1382,19 @@ sub git_print_log {\n \tmy $signoff = 0;\n \tmy $empty = 0;\n \tforeach my $line (@$log) {\n+\t\tif ($line =~ m/^ *(signed[ \\-]off[ \\-]by[ :]|acked[ \\-]by[ :]|cc[ :])/i) {\n+\t\t\t$signoff = 1;\n+\t\t\tif (! $opts{'-remove_signoff'}) {\n+\t\t\t\tprint \"<span class=\\\"signoff\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n+\t\t\t\tnext;\n+\t\t\t} else {\n+\t\t\t\t# remove signoff lines\n+\t\t\t\tnext;\n+\t\t\t}\n+\t\t} else {\n+\t\t\t$signoff = 0;\n+\t\t}\n+\n \t\t# print only one empty line\n \t\t# do not print empty line after signoff\n \t\tif ($line eq \"\") {\n@@ -1384,13 +1403,13 @@ sub git_print_log {\n \t\t} else {\n \t\t\t$empty = 0;\n \t\t}\n-\t\tif ($line =~ m/^ *(signed[ \\-]off[ \\-]by[ :]|acked[ \\-]by[ :]|cc[ :])/i) {\n-\t\t\t$signoff = 1;\n-\t\t\tprint \"<span class=\\\"signoff\\\">\" . esc_html($line) . \"</span><br/>\\n\";\n-\t\t} else {\n-\t\t\t$signoff = 0;\n-\t\t\tprint format_log_line_html($line) . \"<br/>\\n\";\n-\t\t}\n+\n+\t\tprint format_log_line_html($line) . \"<br/>\\n\";\n+\t}\n+\n+\tif ($opts{'-final_empty_line'}) {\n+\t\t# end with single empty line\n+\t\tprint \"<br/>\\n\" unless $empty;\n \t}\n }\n \n@@ -1398,30 +1417,10 @@ sub git_print_simplified_log {\n \tmy $log = shift;\n \tmy $remove_title = shift;\n \n-\tshift @$log if $remove_title;\n-\t# remove leading empty lines\n-\twhile (defined $log->[0] && $log->[0] eq \"\") {\n-\t\tshift @$log;\n-\t}\n-\n-\t# simplify and print log\n-\tmy $empty = 0;\n-\tforeach my $line (@$log) {\n-\t\t# remove signoff lines\n-\t\tif ($line =~ m/^ *(signed[ \\-]off[ \\-]by[ :]|acked[ \\-]by[ :]|cc[ :])/i) {\n-\t\t\tnext;\n-\t\t}\n-\t\t# print only one empty line\n-\t\tif ($line eq \"\") {\n-\t\t\tnext if $empty;\n-\t\t\t$empty = 1;\n-\t\t} else {\n-\t\t\t$empty = 0;\n-\t\t}\n-\t\tprint format_log_line_html($line) . \"<br/>\\n\";\n-\t}\n-\t# end with single empty line\n-\tprint \"<br/>\\n\" unless $empty;\n+\tgit_print_log($log,\n+\t\t-final_empty_line=> 1,\n+\t\t-remove_signoff => 1,\n+\t\t-remove_title => $remove_title);\n }\n \n ## ......................................................................\n-- \n1.4.1.1\n"},{"id":"26016","messageId":"7v4pvxvknc.fsf@assigned-by-dhcp.cox.net","threadId":"5414","inReplyTo":"200608272355.07625.jnareb@gmail.com","subject":"Re: [PATCH/RFC] gitweb: Make git_print_log generic; git_print_simplified_log uses it","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-08-27T23:11:51Z","receivedAt":"2006-08-27T23:11:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> The RFC is about style of git_print_log function. Is it a good idea\n> and good implementation to pass miscelaneus options as hash values\n> instead of using fixed order of parameters, and passing 1 or undef?\n> Is it a good naming of parameters like '-remove_title', or would\n> 'remove_title' or 'remove-title' be better?\n\nI do not personally like the line-noise sub prototypes, since I\nhave not seen it buys you much in real programs.  Although some\ncute hacks like rolling your own control structure lookalikes\ncannot be done without them, they are just that -- cute hacks --\nand tends to obfuscate what is really happening behind the scene\n(not that writing anything in Perl is not already obfuscating\nthings ;-)).  But maybe it is just me.\n\nI think you already use CGI.pm and the argument passing style\nusing things like \"-remove_title\" is the norm there, so I do not\nhave objections against it.  You might even be able to lift the\ncode CGI.pm uses to implement the hash-style passing with\ndefaults.\n"}]}