{"thread":{"id":"12567","subject":"[PATCH 3/3] gitweb: Make 'object' action implicit by using no action URL","startedAt":"2008-03-07T21:03:17Z","lastAt":"2008-03-07T21:03:20Z","messageCount":4,"participants":["Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"71380","messageId":"1204923800-5923-1-git-send-email-jnareb@gmail.com","threadId":"12567","inReplyTo":null,"subject":"[PATCH 0/3] gitweb: Improved treatment of links with unknown object type","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-07T21:03:17Z","receivedAt":"2008-03-07T21:03:17Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"This series of patches make gitweb URLs without a= parameter to use\n'object' view, which finds type of requested onject and redirects\n(HTTP redirect) to proper view, instead of just displaying this view.\ngit_object() in turn is simplified to use git_get_type() subroutine,\nas was used for URLs without a=.  As 'object' view is just internal\nimplementation use no a= parameter instead of a=object for gitweb URLs\nfor which type of object (and therefore view to be used) is not known.\n\nI guess that this series of patches can be squashed into single\ncommit, but I think that having them split into parts makes reviewing\nthem easier; it also makes possible to drop indivisual commits, for\nexample dropping second commit would leave gitweb with modified\nfinding type of an object.\n\nShortlog:\n=========\nJakub Narebski (3):\n  gitweb: Redirect to appropriate view if 'a=' parameter is missing\n  gitweb: Simplify object type detection in git_object()\n  gitweb: Make 'object' action implicit by using no action URL\n\nDiffstat:\n=========\n gitweb/gitweb.perl |   45 +++++++++++----------------------------------\n 1 files changed, 11 insertions(+), 34 deletions(-)\n\nThis series removes more than adds mainly thanks to second patch in\nthe series which simplifies git_object() type detection code.\n\n-- \nJakub Narebski\nShadeHawk on #git\nPoland\n"},{"id":"71379","messageId":"1204923800-5923-2-git-send-email-jnareb@gmail.com","threadId":"12567","inReplyTo":"1204923800-5923-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 1/3] gitweb: Redirect to appropriate view if 'a=' parameter is missing","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-07T21:03:18Z","receivedAt":"2008-03-07T21:03:18Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Instead of finding the type of object specified by 'h',\nor 'hb' and 'f' parameters and substituting it for action\n(view), as it was done since commit 7f9778b by Gerrit Pape,\nuse 'object' view which would find type and REDIRECT to URL\nwith 'a' parameter filled in.\n\nThis way user will have URL with action filled in the browser\nhistory, or when adding bookmark. This hopefully would make\nserver get less requests without 'a' parameter set, thus\nreducing a bit load on server.\n\n\nNote that the code to find object type in git_object() subroutine\nis a bit more complicated than was used for URL without 'a='\nparameter.\n\nCc: Gerrit Pape <pape@smarden.org>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThe fact that using 'object' view changes a bit behavior is addressed\nin second commit in this series, where git_commit() is made to do what\ndispatch for URL without a=, but with h= or hb= and f= did before.\n\n gitweb/gitweb.perl |    7 +++----\n 1 files changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex ec73cb1..a76c4ac 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -564,10 +564,9 @@ my %actions = (\n );\n \n if (!defined $action) {\n-\tif (defined $hash) {\n-\t\t$action = git_get_type($hash);\n-\t} elsif (defined $hash_base && defined $file_name) {\n-\t\t$action = git_get_type(\"$hash_base:$file_name\");\n+\tif (defined $hash ||\n+\t    (defined $hash_base && defined $file_name)) {\n+\t\t$action = 'object';\n \t} elsif (defined $project) {\n \t\t$action = 'summary';\n \t} else {\n-- \n1.5.4.3.453.gc1ad83\n\n"},{"id":"71381","messageId":"1204923800-5923-3-git-send-email-jnareb@gmail.com","threadId":"12567","inReplyTo":"1204923800-5923-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 2/3] gitweb: Simplify object type detection in git_object()","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-07T21:03:19Z","receivedAt":"2008-03-07T21:03:19Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Taken from commit 7f9778b19b07601ae8134fc4ff23b7bf7cac28bd by Gerrit Pape\n  \"gitweb: choose appropriate view for file type if a= parameter missing\"\n\nContrary to previous version it does not find 'h' (hash) parameter\nvalue if it is not set, and only 'hb' (hash_base) and 'f' (file_name)\nparameters are provided, resulting perhaps in slightly less efficient\nURLs, but also one which more closely follow what was requested.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\n gitweb/gitweb.perl |   34 ++++++----------------------------\n 1 files changed, 6 insertions(+), 28 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex a76c4ac..f507a5a 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -4768,42 +4768,20 @@ sub git_object {\n \n \t# - hash or hash_base alone\n \tif ($hash || ($hash_base && !defined $file_name)) {\n-\t\tmy $object_id = $hash || $hash_base;\n-\n-\t\tmy $git_command = git_cmd_str();\n-\t\topen my $fd, \"-|\", \"$git_command cat-file -t $object_id 2>/dev/null\"\n-\t\t\tor die_error('404 Not Found', \"Object does not exist\");\n-\t\t$type = <$fd>;\n-\t\tchomp $type;\n-\t\tclose $fd\n-\t\t\tor die_error('404 Not Found', \"Object does not exist\");\n+\t\t$type = git_get_type($hash || $hash_base);\n \n \t# - hash_base and file_name\n \t} elsif ($hash_base && defined $file_name) {\n-\t\t$file_name =~ s,/+$,,;\n+\t\t$type = git_get_type(\"$hash_base:$file_name\");\n \n-\t\tsystem(git_cmd(), \"cat-file\", '-e', $hash_base) == 0\n-\t\t\tor die_error('404 Not Found', \"Base object does not exist\");\n-\n-\t\t# here errors should not hapen\n-\t\topen my $fd, \"-|\", git_cmd(), \"ls-tree\", $hash_base, \"--\", $file_name\n-\t\t\tor die_error(undef, \"Open git-ls-tree failed\");\n-\t\tmy $line = <$fd>;\n-\t\tclose $fd;\n"},{"id":"71378","messageId":"1204923800-5923-4-git-send-email-jnareb@gmail.com","threadId":"12567","inReplyTo":"1204923800-5923-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 3/3] gitweb: Make 'object' action implicit by using no action URL","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-07T21:03:20Z","receivedAt":"2008-03-07T21:03:20Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"In format_log_line_html() subroutine gitweb makes (shortened) SHA-1\nof an object into hyperlink, as a very simple comittags support.\nUsually, but not always this link is to 'commit' object.\n\nIn git_print_tree_entry() subroutine gitweb provides link to the\ntarget of symbolic link, for easier navigation, if it looks like it\nleads inside tree.  Gitweb doesn't know if it leads to directory\n('tree' object), or an ordinary file ('blob' object), or if it is\nbroken.  (It cn also in rare cases lead to submodule, which now\nwill result in the 'commit' view).\n\nBoth of those cases used generic 'object' action to find correct view\non request, only when link were followed.  Now we make use of the fact\nthat gitweb tries to find correct action if none provided; it uses\n'object' action if action is not provided, but project and either hash\nor hash_base and filename are.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nHmmmm... isn't this commit message too long for such a simple change?\n\n gitweb/gitweb.perl |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex f507a5a..a5df2fe 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1072,7 +1072,7 @@ sub format_log_line_html {\n \tif ($line =~ m/([0-9a-fA-F]{8,40})/) {\n \t\tmy $hash_text = $1;\n \t\tmy $link =\n-\t\t\t$cgi->a({-href => href(action=>\"object\", hash=>$hash_text),\n+\t\t\t$cgi->a({-href => href(hash=>$hash_text),\n \t\t\t        -class => \"text\"}, $hash_text);\n \t\t$line =~ s/$hash_text/$link/;\n \t}\n@@ -2912,7 +2912,7 @@ sub git_print_tree_entry {\n \t\t\t\tmy $norm_target = normalize_link_target($link_target, $basedir, $hash_base);\n \t\t\t\tif (defined $norm_target) {\n \t\t\t\t\tprint \" -> \" .\n-\t\t\t\t\t      $cgi->a({-href => href(action=>\"object\", hash_base=>$hash_base,\n+\t\t\t\t\t      $cgi->a({-href => href(hash_base=>$hash_base,\n \t\t\t\t\t                             file_name=>$norm_target),\n \t\t\t\t\t               -title => $norm_target}, esc_path($link_target));\n \t\t\t\t} else {\n-- \n1.5.4.3.453.gc1ad83\n\n"}]}