Git development
 help / color / mirror / Atom feed
* [PATCHv5 0/5] *** SUBJECT HERE ***
@ 2008-10-13 10:19 Giuseppe Bilotta
  2008-10-13 10:19 ` [PATCHv5 1/5] gitweb: parse project/action/hash_base:filename PATH_INFO Giuseppe Bilotta
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Giuseppe Bilotta @ 2008-10-13 10:19 UTC (permalink / raw)
  To: git
  Cc: Jakub Narebski, Petr Baudis, Shawn O. Pearce, Junio C Hamano,
	Giuseppe Bilotta

Fifth attempt for my gitweb PATH_INFO patchset, whose purpose is to
reduce the use of CGI parameters by embedding as many parameters as
possible in the URL path itself, provided the pathinfo feature is
enabled.

The new typical gitweb URL is therefore in the form

$project/$action/$parent:$file..$hash:$file

(with useless parts stripped). Backwards compatibility for old-style
$project/$hash[:$file] URLs is kept, as long as $hash is not a refname whose
name happens to match a git action.

The main implementation is provided by paired patches (#1#2, #4#5)
that implement parsing and generation of the new style URLs.

Patch #3 is a minor improvement to the URL syntax that allows web
sites to be properly browsable in raw mode.

The patchset depends on my previous input parameter handling patch currently
waiting in 'next'.

Giuseppe Bilotta (5):
  gitweb: parse project/action/hash_base:filename PATH_INFO
  gitweb: generate project/action/hash URLs
  gitweb: use_pathinfo filenames start with /
  gitweb: parse parent..current syntax from PATH_INFO
  gitweb: generate parent..current URLs

 gitweb/gitweb.perl |  124 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 114 insertions(+), 10 deletions(-)

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

* [PATCHv5 1/5] gitweb: parse project/action/hash_base:filename PATH_INFO
  2008-10-13 10:19 [PATCHv5 0/5] *** SUBJECT HERE *** Giuseppe Bilotta
@ 2008-10-13 10:19 ` Giuseppe Bilotta
  2008-10-13 10:19   ` [PATCHv5 2/5] gitweb: generate project/action/hash URLs Giuseppe Bilotta
  2008-10-13 10:52 ` [PATCHv5 0/5] *** SUBJECT HERE *** Ondrej Certik
  2008-10-13 11:00 ` Jakub Narebski
  2 siblings, 1 reply; 9+ messages in thread
From: Giuseppe Bilotta @ 2008-10-13 10:19 UTC (permalink / raw)
  To: git
  Cc: Jakub Narebski, Petr Baudis, Shawn O. Pearce, Junio C Hamano,
	Giuseppe Bilotta

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.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 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
+	my @wants_base = (
+		'tree',
+		'history',
+	);
+
 	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
 		$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
+		# 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.
+		$input_params{'action'} ||= "shortlog";
+		if (grep($input_params{'action'},@wants_base)) {
+			$input_params{'hash_base'} ||= $refname;
+		} else {
+			$input_params{'hash'} ||= $refname;
+		}
 	}
 }
 evaluate_path_info();
-- 
1.5.6.5

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

* [PATCHv5 2/5] gitweb: generate project/action/hash URLs
  2008-10-13 10:19 ` [PATCHv5 1/5] gitweb: parse project/action/hash_base:filename PATH_INFO Giuseppe Bilotta
@ 2008-10-13 10:19   ` Giuseppe Bilotta
  2008-10-13 10:19     ` [PATCHv5 3/5] gitweb: use_pathinfo filenames start with / Giuseppe Bilotta
  0 siblings, 1 reply; 9+ messages in thread
From: Giuseppe Bilotta @ 2008-10-13 10:19 UTC (permalink / raw)
  To: git
  Cc: Jakub Narebski, Petr Baudis, Shawn O. Pearce, Junio C Hamano,
	Giuseppe Bilotta

When generating path info URLs, reduce the number of CGI parameters by
embedding action and hash_parent:filename or hash in the path.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 gitweb/gitweb.perl |   33 ++++++++++++++++++++++++++++++---
 1 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 6d0dc26..5337d40 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -724,14 +724,41 @@ sub href (%) {
 
 	my ($use_pathinfo) = gitweb_check_feature('pathinfo');
 	if ($use_pathinfo) {
-		# use PATH_INFO for project name
+		# try to put as many parameters as possible in PATH_INFO:
+		#   - project name
+		#   - action
+		#   - hash or hash_base:filename
+
+		# When the script is the root DirectoryIndex for the domain,
+		# $href here would be something like http://gitweb.example.com/
+		# Thus, we strip any trailing / from $href, to spare us double
+		# slashes in the final URL
+		$href =~ s,/$,,;
+
+		# Then add the project name, if present
 		$href .= "/".esc_url($params{'project'}) if defined $params{'project'};
 		delete $params{'project'};
 
-		# Summary just uses the project path URL
-		if (defined $params{'action'} && $params{'action'} eq 'summary') {
+		# Summary just uses the project path URL, any other action is
+		# added to the URL
+		if (defined $params{'action'}) {
+			$href .= "/".esc_url($params{'action'}) unless $params{'action'} eq 'summary';
 			delete $params{'action'};
 		}
+
+		# Finally, we put either hash_base:file_name or hash
+		if (defined $params{'hash_base'}) {
+			$href .= "/".esc_url($params{'hash_base'});
+			if (defined $params{'file_name'}) {
+				$href .= ":".esc_url($params{'file_name'});
+				delete $params{'file_name'};
+			}
+			delete $params{'hash'};
+			delete $params{'hash_base'};
+		} elsif (defined $params{'hash'}) {
+			$href .= "/".esc_url($params{'hash'});
+			delete $params{'hash'};
+		}
 	}
 
 	# now encode the parameters explicitly
-- 
1.5.6.5

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

* [PATCHv5 3/5] gitweb: use_pathinfo filenames start with /
  2008-10-13 10:19   ` [PATCHv5 2/5] gitweb: generate project/action/hash URLs Giuseppe Bilotta
@ 2008-10-13 10:19     ` Giuseppe Bilotta
  2008-10-13 10:19       ` [PATCHv5 4/5] gitweb: parse parent..current syntax from PATH_INFO Giuseppe Bilotta
  0 siblings, 1 reply; 9+ messages in thread
From: Giuseppe Bilotta @ 2008-10-13 10:19 UTC (permalink / raw)
  To: git
  Cc: Jakub Narebski, Petr Baudis, Shawn O. Pearce, Junio C Hamano,
	Giuseppe Bilotta

When using path info, make filenames start with a / (right after the :
that separates them from the hash base). This minimal change allows
relative navigation to work properly when viewing HTML files in raw
('blob_plain') mode.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 gitweb/gitweb.perl |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 5337d40..49730f3 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -727,7 +727,7 @@ sub href (%) {
 		# try to put as many parameters as possible in PATH_INFO:
 		#   - project name
 		#   - action
-		#   - hash or hash_base:filename
+		#   - hash or hash_base:/filename
 
 		# When the script is the root DirectoryIndex for the domain,
 		# $href here would be something like http://gitweb.example.com/
@@ -746,11 +746,11 @@ sub href (%) {
 			delete $params{'action'};
 		}
 
-		# Finally, we put either hash_base:file_name or hash
+		# Finally, we put either hash_base:/file_name or hash
 		if (defined $params{'hash_base'}) {
 			$href .= "/".esc_url($params{'hash_base'});
 			if (defined $params{'file_name'}) {
-				$href .= ":".esc_url($params{'file_name'});
+				$href .= ":/".esc_url($params{'file_name'});
 				delete $params{'file_name'};
 			}
 			delete $params{'hash'};
-- 
1.5.6.5

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

* [PATCHv5 4/5] gitweb: parse parent..current syntax from PATH_INFO
  2008-10-13 10:19     ` [PATCHv5 3/5] gitweb: use_pathinfo filenames start with / Giuseppe Bilotta
@ 2008-10-13 10:19       ` Giuseppe Bilotta
  2008-10-13 10:19         ` [PATCHv5 5/5] gitweb: generate parent..current URLs Giuseppe Bilotta
  0 siblings, 1 reply; 9+ messages in thread
From: Giuseppe Bilotta @ 2008-10-13 10:19 UTC (permalink / raw)
  To: git
  Cc: Jakub Narebski, Petr Baudis, Shawn O. Pearce, Junio C Hamano,
	Giuseppe Bilotta

This patch makes it possible to use an URL such as
$project/somebranch..otherbranch:/filename to get a diff between
different version of a file. Paths like
$project/$action/somebranch:/somefile..otherbranch:/otherfile are parsed
as well.

All '*diff' actions and in general actions that use $hash_parent[_base]
and $file_parent can now get all of their parameters from PATH_INFO

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 gitweb/gitweb.perl |   36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 49730f3..1a7b0b9 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -548,7 +548,12 @@ sub evaluate_path_info {
 		'history',
 	);
 
-	my ($refname, $pathname) = split(/:/, $path_info, 2);
+	# horrible regexp to catch
+	# [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
+	my ($parentrefname, $parentpathname, $refname, $pathname) = 
+		($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
+
+	# first, analyze the 'current' part
 	if (defined $pathname) {
 		# we got "branch:filename" or "branch:dir/"
 		# we could use git_get_type(branch:pathname), but it needs $git_dir
@@ -557,7 +562,13 @@ sub evaluate_path_info {
 			$input_params{'action'} ||= "tree";
 			$pathname =~ s,/$,,;
 		} else {
-			$input_params{'action'} ||= "blob_plain";
+			# the default action depends on whether we had parent info
+			# or not
+			if ($parentrefname) {
+				$input_params{'action'} ||= "blobdiff_plain";
+			} else {
+				$input_params{'action'} ||= "blob_plain";
+			}
 		}
 		$input_params{'hash_base'} ||= $refname;
 		$input_params{'file_name'} ||= $pathname;
@@ -577,6 +588,27 @@ sub evaluate_path_info {
 			$input_params{'hash'} ||= $refname;
 		}
 	}
+
+	# next, handle the 'parent' part, if present
+	if (defined $parentrefname) {
+		# a missing pathspec defaults to the 'current' filename, allowing e.g.
+		# someproject/blobdiff/oldrev..newrev:/filename
+		if ($parentpathname) {
+			$parentpathname =~ s,^/+,,;
+			$parentpathname =~ s,/$,,;
+			$input_params{'file_parent'} ||= $parentpathname;
+		} else {
+			$input_params{'file_parent'} ||= $input_params{'file_name'};
+		}
+		# we assume that hash_parent_base is wanted if a path was specified,
+		# or if the action wants hash_base instead of hash
+		if (defined $input_params{'file_parent'} ||
+			grep($input_params{'action'}, @wants_base)) {
+			$input_params{'hash_parent_base'} ||= $parentrefname;
+		} else {
+			$input_params{'hash_parent'} ||= $parentrefname;
+		}
+	}
 }
 evaluate_path_info();
 
-- 
1.5.6.5

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

* [PATCHv5 5/5] gitweb: generate parent..current URLs
  2008-10-13 10:19       ` [PATCHv5 4/5] gitweb: parse parent..current syntax from PATH_INFO Giuseppe Bilotta
@ 2008-10-13 10:19         ` Giuseppe Bilotta
  0 siblings, 0 replies; 9+ messages in thread
From: Giuseppe Bilotta @ 2008-10-13 10:19 UTC (permalink / raw)
  To: git
  Cc: Jakub Narebski, Petr Baudis, Shawn O. Pearce, Junio C Hamano,
	Giuseppe Bilotta

If use_pathinfo is enabled, href now creates links that contain paths in
the form $project/$action/oldhash:/oldname..newhash:/newname for actions
that use hash_parent etc.

If any of the filename contains two consecutive dots, it's kept as a CGI
parameter since the resulting path would otherwise be ambiguous.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 gitweb/gitweb.perl |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 1a7b0b9..f4642e7 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -759,7 +759,8 @@ sub href (%) {
 		# try to put as many parameters as possible in PATH_INFO:
 		#   - project name
 		#   - action
-		#   - hash or hash_base:/filename
+		#   - hash_parent or hash_parent_base:/file_parent
+		#   - hash or hash_base:/file_name
 
 		# When the script is the root DirectoryIndex for the domain,
 		# $href here would be something like http://gitweb.example.com/
@@ -778,17 +779,36 @@ sub href (%) {
 			delete $params{'action'};
 		}
 
-		# Finally, we put either hash_base:/file_name or hash
+		# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
+		# stripping nonexistent or useless pieces
+		$href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
+			|| $params{'hash_parent'} || $params{'hash'});
 		if (defined $params{'hash_base'}) {
-			$href .= "/".esc_url($params{'hash_base'});
-			if (defined $params{'file_name'}) {
+			if (defined $params{'hash_parent_base'}) {
+				$href .= esc_url($params{'hash_parent_base'});
+				# skip the file_parent if it's the same as the file_name
+				delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
+				if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
+					$href .= ":/".esc_url($params{'file_parent'});
+					delete $params{'file_parent'};
+				}
+				$href .= "..";
+				delete $params{'hash_parent'};
+				delete $params{'hash_parent_base'};
+			} elsif (defined $params{'hash_parent'}) {
+				$href .= esc_url($params{'hash_parent'}). "..";
+				delete $params{'hash_parent'};
+			}
+
+			$href .= esc_url($params{'hash_base'});
+			if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
 				$href .= ":/".esc_url($params{'file_name'});
 				delete $params{'file_name'};
 			}
 			delete $params{'hash'};
 			delete $params{'hash_base'};
 		} elsif (defined $params{'hash'}) {
-			$href .= "/".esc_url($params{'hash'});
+			$href .= esc_url($params{'hash'});
 			delete $params{'hash'};
 		}
 	}
-- 
1.5.6.5

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

* Re: [PATCHv5 0/5] *** SUBJECT HERE ***
  2008-10-13 10:19 [PATCHv5 0/5] *** SUBJECT HERE *** Giuseppe Bilotta
  2008-10-13 10:19 ` [PATCHv5 1/5] gitweb: parse project/action/hash_base:filename PATH_INFO Giuseppe Bilotta
@ 2008-10-13 10:52 ` Ondrej Certik
  2008-10-13 11:00 ` Jakub Narebski
  2 siblings, 0 replies; 9+ messages in thread
From: Ondrej Certik @ 2008-10-13 10:52 UTC (permalink / raw)
  To: Giuseppe Bilotta; +Cc: git

On Mon, Oct 13, 2008 at 12:19 PM, Giuseppe Bilotta
<giuseppe.bilotta@gmail.com> wrote:
> Fifth attempt for my gitweb PATH_INFO patchset, whose purpose is to
> reduce the use of CGI parameters by embedding as many parameters as
> possible in the URL path itself, provided the pathinfo feature is
> enabled.
>
> The new typical gitweb URL is therefore in the form
>
> $project/$action/$parent:$file..$hash:$file
>
> (with useless parts stripped). Backwards compatibility for old-style
> $project/$hash[:$file] URLs is kept, as long as $hash is not a refname whose
> name happens to match a git action.

Thanks Giuseppe for doing this. I just switched from Mercurial to git
recently and this is one thing that I was missing a lot in git.

Ondrej

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

* Re: [PATCHv5 0/5] *** SUBJECT HERE ***
  2008-10-13 10:19 [PATCHv5 0/5] *** SUBJECT HERE *** Giuseppe Bilotta
  2008-10-13 10:19 ` [PATCHv5 1/5] gitweb: parse project/action/hash_base:filename PATH_INFO Giuseppe Bilotta
  2008-10-13 10:52 ` [PATCHv5 0/5] *** SUBJECT HERE *** Ondrej Certik
@ 2008-10-13 11:00 ` Jakub Narebski
  2008-10-13 11:42   ` Giuseppe Bilotta
  2 siblings, 1 reply; 9+ messages in thread
From: Jakub Narebski @ 2008-10-13 11:00 UTC (permalink / raw)
  To: Giuseppe Bilotta; +Cc: git, Petr Baudis, Shawn O. Pearce, Junio C Hamano

Err... "*** SUBJECT HERE ***"? Not that it matters...

On Mon, 13 Oct 2008, Giuseppe Bilotta wrote:

> Fifth attempt for my gitweb PATH_INFO patchset, whose purpose is to
> reduce the use of CGI parameters by embedding as many parameters as
> possible in the URL path itself, provided the pathinfo feature is
> enabled.
[...]

> Giuseppe Bilotta (5):
>   gitweb: parse project/action/hash_base:filename PATH_INFO
>   gitweb: generate project/action/hash URLs
>   gitweb: use_pathinfo filenames start with /
>   gitweb: parse parent..current syntax from PATH_INFO
>   gitweb: generate parent..current URLs

I like it, and with the exception of the last patch (which looks like
it doesn't check if $file_name contains '..', even as it checks if
$file_parent contains '..', and which probably should not esc_url)
it looks OK. from (superficial) browsing through patches.

I'll try to review them soon.
-- 
Jakub Narebski
Poland

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

* Re: [PATCHv5 0/5] *** SUBJECT HERE ***
  2008-10-13 11:00 ` Jakub Narebski
@ 2008-10-13 11:42   ` Giuseppe Bilotta
  0 siblings, 0 replies; 9+ messages in thread
From: Giuseppe Bilotta @ 2008-10-13 11:42 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git, Petr Baudis, Shawn O. Pearce, Junio C Hamano

On Mon, Oct 13, 2008 at 1:00 PM, Jakub Narebski <jnareb@gmail.com> wrote:
> Err... "*** SUBJECT HERE ***"? Not that it matters...

Yeah, I realized that as soon as I sent the thing 8-(

> I like it, and with the exception of the last patch (which looks like
> it doesn't check if $file_name contains '..', even as it checks if
> $file_parent contains '..', and which probably should not esc_url)

Oopsie. I'll get to fix that.

-- 
Giuseppe "Oblomov" Bilotta

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

end of thread, other threads:[~2008-10-13 11:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-13 10:19 [PATCHv5 0/5] *** SUBJECT HERE *** Giuseppe Bilotta
2008-10-13 10:19 ` [PATCHv5 1/5] gitweb: parse project/action/hash_base:filename PATH_INFO Giuseppe Bilotta
2008-10-13 10:19   ` [PATCHv5 2/5] gitweb: generate project/action/hash URLs Giuseppe Bilotta
2008-10-13 10:19     ` [PATCHv5 3/5] gitweb: use_pathinfo filenames start with / Giuseppe Bilotta
2008-10-13 10:19       ` [PATCHv5 4/5] gitweb: parse parent..current syntax from PATH_INFO Giuseppe Bilotta
2008-10-13 10:19         ` [PATCHv5 5/5] gitweb: generate parent..current URLs Giuseppe Bilotta
2008-10-13 10:52 ` [PATCHv5 0/5] *** SUBJECT HERE *** Ondrej Certik
2008-10-13 11:00 ` Jakub Narebski
2008-10-13 11:42   ` Giuseppe Bilotta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox