Skip to content

Commit b0be383

Browse files
Oblomovgitster
authored andcommitted
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>
1 parent 3550ea7 commit b0be383

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

gitweb/gitweb.perl

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,12 @@ sub evaluate_path_info {
549549
'history',
550550
);
551551

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
553558
if (defined $pathname) {
554559
# we got "branch:filename" or "branch:dir/"
555560
# we could use git_get_type(branch:pathname), but:
@@ -564,7 +569,13 @@ sub evaluate_path_info {
564569
$input_params{'action'} ||= "tree";
565570
$pathname =~ s,/$,,;
566571
} 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+
}
568579
}
569580
$input_params{'hash_base'} ||= $refname;
570581
$input_params{'file_name'} ||= $pathname;
@@ -584,6 +595,27 @@ sub evaluate_path_info {
584595
$input_params{'hash'} ||= $refname;
585596
}
586597
}
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+
}
587619
}
588620
evaluate_path_info();
589621

0 commit comments

Comments
 (0)