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

gitweb: Move git-ls-tree output parsing to parse_ls_tree_line

Add new subroutine parse_ls_tree_line and use it in git_tree. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Aug 31, 2006 at 00:32 UTC cb849b46ac68feea716a45fd1de99cfdd71123d0
1 file changed +43 -19
gitweb/gitweb.perl
+43 -19
@@ -1034,6 +1034,27 @@ sub parse_difftree_raw_line {
1034 return wantarray ? %res : \%res;
1035 }
1036
1037 +# parse line of git-ls-tree output
1038 +sub parse_ls_tree_line ($;%) {
1039 + my $line = shift;
1040 + my %opts = @_;
1041 + my %res;
1042 +
1043 + #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1044 + $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1045 +
1046 + $res{'mode'} = $1;
1047 + $res{'type'} = $2;
1048 + $res{'hash'} = $3;
1049 + if ($opts{'-z'}) {
1050 + $res{'name'} = $4;
1051 + } else {
1052 + $res{'name'} = unquote($4);
1053 + }
1054 +
1055 + return wantarray ? %res : \%res;
1056 +}
1057 +
1058 ## ......................................................................
1059 ## parse to array of hashes functions
1060
@@ -2512,51 +2533,54 @@ sub git_tree {
2533 print "<table cellspacing=\"0\">\n";
2534 my $alternate = 0;
2535 foreach my $line (@entries) {
2515 - #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2516 - $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2517 - my $t_mode = $1;
2518 - my $t_type = $2;
2519 - my $t_hash = $3;
2520 - my $t_name = validate_input($4);
2536 + my %t = parse_ls_tree_line($line, -z => 1);
2537 +
2538 if ($alternate) {
2539 print "<tr class=\"dark\">\n";
2540 } else {
2541 print "<tr class=\"light\">\n";
2542 }
2543 $alternate ^= 1;
2527 - print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
2528 - if ($t_type eq "blob") {
2544 +
2545 + print "<td class=\"mode\">" . mode_str($t{'mode'}) . "</td>\n";
2546 + if ($t{'type'} eq "blob") {
2547 print "<td class=\"list\">" .
2530 - $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key),
2531 - -class => "list"}, esc_html($t_name)) .
2548 + $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'},
2549 + file_name=>"$base$t{'name'}", %base_key),
2550 + -class => "list"}, esc_html($t{'name'})) .
2551 "</td>\n" .
2552 "<td class=\"link\">" .
2534 - $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2553 + $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'},
2554 + file_name=>"$base$t{'name'}", %base_key)},
2555 "blob");
2556 if ($have_blame) {
2557 print " | " .
2538 - $cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2558 + $cgi->a({-href => href(action=>"blame", hash=>$t{'hash'},
2559 + file_name=>"$base$t{'name'}", %base_key)},
2560 "blame");
2561 }
2562 print " | " .
2563 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2543 - hash=>$t_hash, file_name=>"$base$t_name")},
2564 + hash=>$t{'hash'}, file_name=>"$base$t{'name'}")},
2565 "history") .
2566 " | " .
2567 $cgi->a({-href => href(action=>"blob_plain",
2547 - hash=>$t_hash, file_name=>"$base$t_name")},
2568 + hash=>$t{'hash'}, file_name=>"$base$t{'name'}")},
2569 "raw") .
2570 "</td>\n";
2550 - } elsif ($t_type eq "tree") {
2571 + } elsif ($t{'type'} eq "tree") {
2572 print "<td class=\"list\">" .
2552 - $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2553 - esc_html($t_name)) .
2573 + $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'},
2574 + file_name=>"$base$t{'name'}", %base_key)},
2575 + esc_html($t{'name'})) .
2576 "</td>\n" .
2577 "<td class=\"link\">" .
2556 - $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
2578 + $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'},
2579 + file_name=>"$base$t{'name'}", %base_key)},
2580 "tree") .
2581 " | " .
2559 - $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")},
2582 + $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2583 + file_name=>"$base$t{'name'}")},
2584 "history") .
2585 "</td>\n";
2586 }