gitweb: simplify git_get_hash_by_path
Simplify git_get_hash_by_path by using git-ls-tree to do path limiting, instead of finding correct ttree and parsing unconstrained git-ls-tree output. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jakub Narebski committed
Jul 29, 2006 at 22:55 UTC
dda754f7d4fa1bccd9f3349d73304856144a7cd2
1 file changed
+9
-23
gitweb/gitweb.cgi
+9
-23
@@ -1525,29 +1525,15 @@ sub git_get_hash_by_path {
1525
my $path = shift || return undef;
1526
1527
my $tree = $base;
1528
- my @parts = split '/', $path;
1529
- while (my $part = shift @parts) {
1530
- open my $fd, "-|", $GIT, "ls-tree", $tree or die_error(undef, "Open git-ls-tree failed.");
1531
- my (@entries) = map { chomp; $_ } <$fd>;
1532
- close $fd or return undef;
1533
- foreach my $line (@entries) {
1534
- #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1535
- $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1536
- my $t_mode = $1;
1537
- my $t_type = $2;
1538
- my $t_hash = $3;
1539
- my $t_name = validate_input(unquote($4));
1540
- if ($t_name eq $part) {
1541
- if (!(@parts)) {
1542
- return $t_hash;
1543
- }
1544
- if ($t_type eq "tree") {
1545
- $tree = $t_hash;
1546
- }
1547
- last;
1548
- }
1549
- }
1550
- }
1528
+
1529
+ open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
1530
+ or die_error(undef, "Open git-ls-tree failed.");
1531
+ my $line = <$fd>;
1532
+ close $fd or return undef;
1533
+
1534
+ #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1535
+ $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1536
+ return $3;
1537
}
1538
1539
sub mimetype_guess_file {