@matheusbsbs / matheus-bagliano / commits / b0be3838bb
Fork 0

gitweb: parse parent..current syntax from PATH_INFO

This patch makes it possible to use an URL such as project/action/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 (e.g. 'shortlog') can now get all of their parameters from PATH_INFO Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Acked-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Giuseppe Bilotta committed Oct 21, 2008 at 21:34 UTC b0be3838bb75e8b3be04310cc379142c3ef65703
1 file changed +34 -2
gitweb/gitweb.perl
+34 -2
@@ -549,7 +549,12 @@ sub evaluate_path_info {
549 'history',
550 );
551
552 - my ($refname, $pathname) = split(/:/, $path_info, 2);
552 + # we want to catch
553 + # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
554 + my ($parentrefname, $parentpathname, $refname, $pathname) =
555 + ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
556 +
557 + # first, analyze the 'current' part
558 if (defined $pathname) {
559 # we got "branch:filename" or "branch:dir/"
560 # we could use git_get_type(branch:pathname), but:
@@ -564,7 +569,13 @@ sub evaluate_path_info {
569 $input_params{'action'} ||= "tree";
570 $pathname =~ s,/$,,;
571 } else {
567 - $input_params{'action'} ||= "blob_plain";
572 + # the default action depends on whether we had parent info
573 + # or not
574 + if ($parentrefname) {
575 + $input_params{'action'} ||= "blobdiff_plain";
576 + } else {
577 + $input_params{'action'} ||= "blob_plain";
578 + }
579 }
580 $input_params{'hash_base'} ||= $refname;
581 $input_params{'file_name'} ||= $pathname;
@@ -584,6 +595,27 @@ sub evaluate_path_info {
595 $input_params{'hash'} ||= $refname;
596 }
597 }
598 +
599 + # next, handle the 'parent' part, if present
600 + if (defined $parentrefname) {
601 + # a missing pathspec defaults to the 'current' filename, allowing e.g.
602 + # someproject/blobdiff/oldrev..newrev:/filename
603 + if ($parentpathname) {
604 + $parentpathname =~ s,^/+,,;
605 + $parentpathname =~ s,/$,,;
606 + $input_params{'file_parent'} ||= $parentpathname;
607 + } else {
608 + $input_params{'file_parent'} ||= $input_params{'file_name'};
609 + }
610 + # we assume that hash_parent_base is wanted if a path was specified,
611 + # or if the action wants hash_base instead of hash
612 + if (defined $input_params{'file_parent'} ||
613 + grep { $_ eq $input_params{'action'} } @wants_base) {
614 + $input_params{'hash_parent_base'} ||= $parentrefname;
615 + } else {
616 + $input_params{'hash_parent'} ||= $parentrefname;
617 + }
618 + }
619 }
620 evaluate_path_info();
621