Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
gitweb: Move git-ls-tree output parsing to parse_ls_tree_line
author
Jakub Narebski
<jnareb@gmail.com>
Wed, 30 Aug 2006 22:32:15 +0000
(
00:32
+0200)
committer
Junio C Hamano
<junkio@cox.net>
Thu, 31 Aug 2006 19:57:52 +0000
(12:57 -0700)
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>
gitweb/gitweb.perl
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
4b5dc98
)
diff --git
a/gitweb/gitweb.perl
b/gitweb/gitweb.perl
index 7922c3ce547d7f7d861f9fbde926c32b3d50136b..758032af64a0ce5a54b87dec449e8b1ed7d65dc6 100755
(executable)
--- a/
gitweb/gitweb.perl
+++ b/
gitweb/gitweb.perl
@@
-1034,6
+1034,27
@@
sub parse_difftree_raw_line {
return wantarray ? %res : \%res;
}
return wantarray ? %res : \%res;
}
+# parse line of git-ls-tree output
+sub parse_ls_tree_line ($;%) {
+ my $line = shift;
+ my %opts = @_;
+ my %res;
+
+ #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
+ $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
+
+ $res{'mode'} = $1;
+ $res{'type'} = $2;
+ $res{'hash'} = $3;
+ if ($opts{'-z'}) {
+ $res{'name'} = $4;
+ } else {
+ $res{'name'} = unquote($4);
+ }
+
+ return wantarray ? %res : \%res;
+}
+
## ......................................................................
## parse to array of hashes functions
## ......................................................................
## parse to array of hashes functions
@@
-2512,51
+2533,54
@@
sub git_tree {
print "<table cellspacing=\"0\">\n";
my $alternate = 0;
foreach my $line (@entries) {
print "<table cellspacing=\"0\">\n";
my $alternate = 0;
foreach my $line (@entries) {
- #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
- $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
- my $t_mode = $1;
- my $t_type = $2;
- my $t_hash = $3;
- my $t_name = validate_input($4);
+ my %t = parse_ls_tree_line($line, -z => 1);
+
if ($alternate) {
print "<tr class=\"dark\">\n";
} else {
print "<tr class=\"light\">\n";
}
$alternate ^= 1;
if ($alternate) {
print "<tr class=\"dark\">\n";
} else {
print "<tr class=\"light\">\n";
}
$alternate ^= 1;
- print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
- if ($t_type eq "blob") {
+
+ print "<td class=\"mode\">" . mode_str($t{'mode'}) . "</td>\n";
+ if ($t{'type'} eq "blob") {
print "<td class=\"list\">" .
print "<td class=\"list\">" .
- $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key),
- -class => "list"}, esc_html($t_name)) .
+ $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'},
+ file_name=>"$base$t{'name'}", %base_key),
+ -class => "list"}, esc_html($t{'name'})) .
"</td>\n" .
"<td class=\"link\">" .
"</td>\n" .
"<td class=\"link\">" .
- $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
+ $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'},
+ file_name=>"$base$t{'name'}", %base_key)},
"blob");
if ($have_blame) {
print " | " .
"blob");
if ($have_blame) {
print " | " .
- $cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
+ $cgi->a({-href => href(action=>"blame", hash=>$t{'hash'},
+ file_name=>"$base$t{'name'}", %base_key)},
"blame");
}
print " | " .
$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
"blame");
}
print " | " .
$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
- hash=>$t
_hash, file_name=>"$base$t_name
")},
+ hash=>$t
{'hash'}, file_name=>"$base$t{'name'}
")},
"history") .
" | " .
$cgi->a({-href => href(action=>"blob_plain",
"history") .
" | " .
$cgi->a({-href => href(action=>"blob_plain",
- hash=>$t
_hash, file_name=>"$base$t_name
")},
+ hash=>$t
{'hash'}, file_name=>"$base$t{'name'}
")},
"raw") .
"</td>\n";
"raw") .
"</td>\n";
- } elsif ($t
_type
eq "tree") {
+ } elsif ($t
{'type'}
eq "tree") {
print "<td class=\"list\">" .
print "<td class=\"list\">" .
- $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
- esc_html($t_name)) .
+ $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'},
+ file_name=>"$base$t{'name'}", %base_key)},
+ esc_html($t{'name'})) .
"</td>\n" .
"<td class=\"link\">" .
"</td>\n" .
"<td class=\"link\">" .
- $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
+ $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'},
+ file_name=>"$base$t{'name'}", %base_key)},
"tree") .
" | " .
"tree") .
" | " .
- $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")},
+ $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
+ file_name=>"$base$t{'name'}")},
"history") .
"</td>\n";
}
"history") .
"</td>\n";
}