threads / patch / 12567

patch, 3 partsgitweb: Make 'object' action implicit by using no action URL

Subject: [PATCH 3/3] gitweb: Make 'object' action implicit by using no action URL

## tl;dr

4 messages between Mar 7, 2008 and Mar 7, 2008. Diffs are folded; open one to read it.

replies: 3people: 1as markdown or json

Jakub Narebski· Mar 7, 2008, 21:03 UTC · lore

[PATCH 0/3] gitweb: Improved treatment of links with unknown object type

This series of patches make gitweb URLs without a= parameter to use 'object' view, which finds type of requested onject and redirects (HTTP redirect) to proper view, instead of just displaying this view. git_object() in turn is simplified to use git_get_type() subroutine, as was used for URLs without a=. As 'object' view is just internal implementation use no a= parameter instead of a=object for gitweb URLs for which type of object (and therefore view to be used) is not known.

I guess that this series of patches can be squashed into single commit, but I think that having them split into parts makes reviewing them easier; it also makes possible to drop indivisual commits, for example dropping second commit would leave gitweb with modified finding type of an object.

Shortlog:
=========
Jakub Narebski (3):
  gitweb: Redirect to appropriate view if 'a=' parameter is missing
  gitweb: Simplify object type detection in git_object()
  gitweb: Make 'object' action implicit by using no action URL
Diffstat:
=========
 gitweb/gitweb.perl |   45 +++++++++++----------------------------------
 1 files changed, 11 insertions(+), 34 deletions(-)

This series removes more than adds mainly thanks to second patch in the series which simplifies git_object() type detection code.

-- 
Jakub Narebski
ShadeHawk on #git
Poland
Jakub Narebski· Mar 7, 2008, 21:03 UTC · re: Jakub Narebski · lore

[PATCH 1/3] gitweb: Redirect to appropriate view if 'a=' parameter is missing

Instead of finding the type of object specified by 'h', or 'hb' and 'f' parameters and substituting it for action (view), as it was done since commit 7f9778b by Gerrit Pape, use 'object' view which would find type and REDIRECT to URL with 'a' parameter filled in.

This way user will have URL with action filled in the browser history, or when adding bookmark. This hopefully would make server get less requests without 'a' parameter set, thus reducing a bit load on server.

Note that the code to find object type in git_object() subroutine is a bit more complicated than was used for URL without 'a=' parameter.

Cc: Gerrit Pape <pape@smarden.org>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
The fact that using 'object' view changes a bit behavior is addressed
in second commit in this series, where git_commit() is made to do what
dispatch for URL without a=, but with h= or hb= and f= did before.
 gitweb/gitweb.perl |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
Show changes to gitweb/gitweb.perl +3 −4
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index ec73cb1..a76c4ac 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -564,10 +564,9 @@ my %actions = (
 );
 
 if (!defined $action) {
-	if (defined $hash) {
-		$action = git_get_type($hash);
-	} elsif (defined $hash_base && defined $file_name) {
-		$action = git_get_type("$hash_base:$file_name");
+	if (defined $hash ||
+	    (defined $hash_base && defined $file_name)) {
+		$action = 'object';
 	} elsif (defined $project) {
 		$action = 'summary';
 	} else {
-- 
1.5.4.3.453.gc1ad83
Jakub Narebski· Mar 7, 2008, 21:03 UTC · re: Jakub Narebski · lore

[PATCH 2/3] gitweb: Simplify object type detection in git_object()

Taken from commit 7f9778b19b07601ae8134fc4ff23b7bf7cac28bd by Gerrit Pape
  "gitweb: choose appropriate view for file type if a= parameter missing"

Contrary to previous version it does not find 'h' (hash) parameter value if it is not set, and only 'hb' (hash_base) and 'f' (file_name) parameters are provided, resulting perhaps in slightly less efficient URLs, but also one which more closely follow what was requested.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |   34 ++++++----------------------------
 1 files changed, 6 insertions(+), 28 deletions(-)
Show changes to gitweb/gitweb.perl +2 −18
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index a76c4ac..f507a5a 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -4768,42 +4768,20 @@ sub git_object {
 
 	# - hash or hash_base alone
 	if ($hash || ($hash_base && !defined $file_name)) {
-		my $object_id = $hash || $hash_base;
-
-		my $git_command = git_cmd_str();
-		open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
-			or die_error('404 Not Found', "Object does not exist");
-		$type = <$fd>;
-		chomp $type;
-		close $fd
-			or die_error('404 Not Found', "Object does not exist");
+		$type = git_get_type($hash || $hash_base);
 
 	# - hash_base and file_name
 	} elsif ($hash_base && defined $file_name) {
-		$file_name =~ s,/+$,,;
+		$type = git_get_type("$hash_base:$file_name");
 
-		system(git_cmd(), "cat-file", '-e', $hash_base) == 0
-			or die_error('404 Not Found', "Base object does not exist");
-
-		# here errors should not hapen
-		open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name
-			or die_error(undef, "Open git-ls-tree failed");
-		my $line = <$fd>;
-		close $fd;
Jakub Narebski· Mar 7, 2008, 21:03 UTC · re: Jakub Narebski · lore

In format_log_line_html() subroutine gitweb makes (shortened) SHA-1 of an object into hyperlink, as a very simple comittags support. Usually, but not always this link is to 'commit' object.

In git_print_tree_entry() subroutine gitweb provides link to the target of symbolic link, for easier navigation, if it looks like it leads inside tree. Gitweb doesn't know if it leads to directory ('tree' object), or an ordinary file ('blob' object), or if it is broken. (It cn also in rare cases lead to submodule, which now will result in the 'commit' view).

Both of those cases used generic 'object' action to find correct view on request, only when link were followed. Now we make use of the fact that gitweb tries to find correct action if none provided; it uses 'object' action if action is not provided, but project and either hash or hash_base and filename are.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Hmmmm... isn't this commit message too long for such a simple change?
 gitweb/gitweb.perl |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Show changes to gitweb/gitweb.perl +2 −2
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index f507a5a..a5df2fe 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1072,7 +1072,7 @@ sub format_log_line_html {
 	if ($line =~ m/([0-9a-fA-F]{8,40})/) {
 		my $hash_text = $1;
 		my $link =
-			$cgi->a({-href => href(action=>"object", hash=>$hash_text),
+			$cgi->a({-href => href(hash=>$hash_text),
 			        -class => "text"}, $hash_text);
 		$line =~ s/$hash_text/$link/;
 	}
@@ -2912,7 +2912,7 @@ sub git_print_tree_entry {
 				my $norm_target = normalize_link_target($link_target, $basedir, $hash_base);
 				if (defined $norm_target) {
 					print " -> " .
-					      $cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
+					      $cgi->a({-href => href(hash_base=>$hash_base,
 					                             file_name=>$norm_target),
 					               -title => $norm_target}, esc_path($link_target));
 				} else {
-- 
1.5.4.3.453.gc1ad83

← back to recent threads