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

Re: [PATCHv6 1/5] gitweb: parse project/action/hash_base:filename PATH_INFO

From
Jakub Narebski <jnareb@gmail.com>
Date
Oct 18, 2008, 22:41 UTC
Message-ID
<200810190041.44711.jnareb@gmail.com>
In-Reply-To
<1224188831-17767-2-git-send-email-giuseppe.bilotta@gmail.com>
On Thu, 16 Oct 2008, Giuseppe Bilotta wrote:
Show 8 quoted lines
> This patch enables gitweb to parse URLs with more information embedded
> in PATH_INFO, reducing the need for CGI parameters. The typical gitweb
> path is now $project/$action/$hash_base:$file_name or
> $project/$action/$hash
> 
> This is mostly backwards compatible with the old-style gitweb paths,
> $project/$branch[:$filename], except when it was used to access a branch
> whose name matches a gitweb action.

...in which case old code would access branch, and new code would treat name as action. This shouldn't matter in practice, unless there are branches named exactly as gitweb actions.

[But I think current commit description is enough. Just in case...]
> 
> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
I like it. For what it is worth:
Acked-by: Jakub Narebski <jnareb@gmail.com>
Show 21 quoted lines
> ---
>  gitweb/gitweb.perl |   37 +++++++++++++++++++++++++++++++------
>  1 files changed, 31 insertions(+), 6 deletions(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index c5254af..6d0dc26 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -534,23 +534,48 @@ sub evaluate_path_info {
>  	return if $input_params{'action'};
>  	$path_info =~ s,^\Q$project\E/*,,;
>  
> +	# next, check if we have an action
> +	my $action = $path_info;
> +	$action =~ s,/.*$,,;
> +	if (exists $actions{$action}) {
> +		$path_info =~ s,^$action/*,,;
> +		$input_params{'action'} = $action;
> +	}
> +
> +	# list of actions that want hash_base instead of hash
...and can have no file_name ('f') parameter.
> +	my @wants_base = (
> +		'tree',
> +		'history',
> +	);

I like this solution. It makes path_info URL unambiguous: it is <project>/log/<hash> (where <hash> is usually refname), and <project>/tree/<hash_base> which is just shortcut for <project>/tree/<hash_base>:/

It means that the @wants_base list contains actions which require / use $hash_base and $file_name, but $file_name might be not set, which denotes top directory (root tree).

Show 6 quoted lines
> +
>  	my ($refname, $pathname) = split(/:/, $path_info, 2);
>  	if (defined $pathname) {
> -		# we got "project.git/branch:filename" or "project.git/branch:dir/"
> +		# we got "branch:filename" or "branch:dir/"
>  		# we could use git_get_type(branch:pathname), but it needs $git_dir

Well, this comment was there... but actually I think we avoid git_get_type("branch:pathname") because currently it is additional fork. And with convention that filename part of path_info ends in '/' for directories (quite sensible I think) it is not needed. Moreso after next patch in series, when we state action explicitly, and the only difference _might_ be for 'history' view (which is for directories and for files both).

Show 16 quoted lines
>  		$pathname =~ s,^/+,,;
>  		if (!$pathname || substr($pathname, -1) eq "/") {
> -			$input_params{'action'} = "tree";
> +			$input_params{'action'} ||= "tree";
>  			$pathname =~ s,/$,,;
>  		} else {
> -			$input_params{'action'} = "blob_plain";
> +			$input_params{'action'} ||= "blob_plain";
>  		}
>  		$input_params{'hash_base'} ||= $refname;
>  		$input_params{'file_name'} ||= $pathname;
>  	} elsif (defined $refname) {
> -		# we got "project.git/branch"
> -		$input_params{'action'} = "shortlog";
> -		$input_params{'hash'} ||= $refname;
> +		# we got "branch". in this case we have to choose if we have to
                                 ^ ^
                                 |-|-- ??? (typo?)
Show 7 quoted lines
> +		# set hash or hash_base.
> +		#
> +		# Most of the actions without a pathname only want hash to be
> +		# set, except for the ones specified in @wants_base that want
> +		# hash_base instead. It should also be noted that hand-crafted
> +		# links having 'history' as an action and no pathname or hash
> +		# set will fail, but that happens regardless of PATH_INFO.

Ah, I see that the comment about what makes action to be put into @wants_base is here.

> +		$input_params{'action'} ||= "shortlog";
> +		if (grep {$input_params{'action'} eq $_} @wants_base) {
Style: I would use here (but perhaps it is just me) for better 
readibility
+		if (grep { $input_params{'action'} eq $_ } @wants_base) {
Show 11 quoted lines
> +			$input_params{'hash_base'} ||= $refname;
> +		} else {
> +			$input_params{'hash'} ||= $refname;
> +		}
>  	}
>  }
>  evaluate_path_info();
> -- 
> 1.5.6.5
> 
> 
-- 
Jakub Narebski
Poland
Previous: Jakub Narebski
Message 26 of 26 in “[PATCHv6 0/5] gitweb: PATH_INFO enhancement”
  1. Giuseppe BilottaOct 16, 2008
  2. 1/5 gitweb: parse project/action/hash_base:filename PATH_INFOGiuseppe Bilotta, Oct 16, 2008
  3. 2/5 gitweb: generate project/action/hash URLsGiuseppe Bilotta, Oct 16, 2008
  4. 3/5 gitweb: use_pathinfo filenames start with /Giuseppe Bilotta, Oct 16, 2008
  5. 4/5 gitweb: parse parent..current syntax from PATH_INFOGiuseppe Bilotta, Oct 16, 2008
  6. 5/5 gitweb: generate parent..current URLsGiuseppe Bilotta, Oct 16, 2008
  7. 6/6 gitweb: retrieve snapshot format from PATH_INFOGiuseppe Bilotta, Oct 19, 2008
  8. 6/8 gitweb: retrieve snapshot format from PATH_INFOGiuseppe Bilotta, Oct 19, 2008
  9. 7/8 gitweb: embed snapshot format parameter in PATH_INFOGiuseppe Bilotta, Oct 19, 2008
  10. 8/8 gitweb: make the supported snapshot formats array globalGiuseppe Bilotta, Oct 19, 2008
  11. Jakub NarebskiNov 2, 2008
  12. Junio C HamanoNov 2, 2008
  13. Jakub NarebskiNov 1, 2008
  14. Giuseppe BilottaNov 1, 2008
  15. Jakub NarebskiOct 21, 2008
  16. Giuseppe BilottaOct 21, 2008
  17. Junio C HamanoOct 21, 2008
  18. Jakub NarebskiOct 20, 2008
  19. Giuseppe BilottaOct 20, 2008
  20. Jakub NarebskiOct 20, 2008
  21. Giuseppe BilottaOct 20, 2008
  22. Jakub NarebskiOct 18, 2008
  23. Giuseppe BilottaOct 18, 2008
  24. Jakub NarebskiOct 19, 2008
  25. Jakub NarebskiOct 18, 2008
  26. Jakub NarebskiOct 18, 2008

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.