X-Git-Url: https://git.ladys.computer/Gitweb/blobdiff_plain/c49206138169eb63c4b143ff6c380cb6f3581a845b032f5934846317d68d2dab..9c9d435689da11f7e28170a9499e203e9cce56bb61c0846b9adb4e62091435f4:/gitweb.perl diff --git a/gitweb.perl b/gitweb.perl index 87806ac..b063714 100755 --- a/gitweb.perl +++ b/gitweb.perl @@ -749,6 +749,73 @@ sub git_get_references { return \%refs; } +sub git_get_following_references { + my $hash = shift || return undef; + my $type = shift; + my $base = shift || $hash_base || "HEAD"; + + my $refs = git_get_references($type); + open my $fd, "-|", $GIT, "rev-list", $base + or return undef; + my @commits = map { chomp; $_ } <$fd>; + close $fd + or return undef; + + my @reflist; + my $lastref; + + foreach my $commit (@commits) { + foreach my $ref (@{$refs->{$commit}}) { + $lastref = $ref; + push @reflist, $lastref; + } + if ($commit eq $hash) { + last; + } + } + + return wantarray ? @reflist : $lastref; +} + +sub git_get_preceding_references { + my $hash = shift || return undef; + my $type = shift; + + my $refs = git_get_references($type); + open my $fd, "-|", $GIT, "rev-list", $hash + or return undef; + my @commits = map { chomp; $_ } <$fd>; + close $fd + or return undef; + + my @reflist; + + foreach my $commit (@commits) { + foreach my $ref (@{$refs->{$commit}}) { + return $ref unless wantarray; + push @reflist, $ref; + } + } + + return @reflist; +} + +sub git_get_rev_name_tags { + my $hash = shift || return undef; + + open my $fd, "-|", $GIT, "name-rev", "--tags", $hash + or return; + my $name_rev = <$fd>; + close $fd; + + if ($name_rev =~ m|^$hash tags/(.*)$|) { + return $1; + } else { + # catches also '$hash undefined' output + return undef; + } +} + ## ---------------------------------------------------------------------- ## parse to hash functions @@ -1539,7 +1606,7 @@ sub git_difftree_body { } sub git_patchset_body { - my ($patchset, $difftree, $hash, $hash_parent) = @_; + my ($fd, $difftree, $hash, $hash_parent) = @_; my $patch_idx = 0; my $in_header = 0; @@ -1548,7 +1615,9 @@ sub git_patchset_body { print "
\n"; - LINE: foreach my $patch_line (@$patchset) { + LINE: + while (my $patch_line @$fd>) { + chomp $patch_line; if ($patch_line =~ m/^diff /) { # "git diff" header # beginning of patch (in patchset) @@ -2727,7 +2796,6 @@ sub git_commitdiff { # read commitdiff my $fd; my @difftree; - my @patchset; if ($format eq 'html') { open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', "--patch-with-raw", "--full-index", $hash_parent, $hash @@ -2738,13 +2806,11 @@ sub git_commitdiff { last unless $line; push @difftree, $line; } - @patchset = map { chomp; $_ } <$fd>; - close $fd - or die_error(undef, "Reading git-diff-tree failed"); } elsif ($format eq 'plain') { open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash or die_error(undef, "Open git-diff-tree failed"); + } else { die_error(undef, "Unknown commitdiff format"); } @@ -2774,10 +2840,7 @@ sub git_commitdiff { } elsif ($format eq 'plain') { my $refs = git_get_references("tags"); - my @tagnames; - if (exists $refs->{$hash}) { - @tagnames = map { s|^tags/|| } $refs->{$hash}; - } + my $tagname = git_get_rev_name_tags($hash); my $filename = basename($project) . "-$hash.patch"; print $cgi->header( @@ -2791,10 +2854,9 @@ From: $co{'author'} Date: $ad{'rfc2822'} ($ad{'tz_local'}) Subject: $co{'title'} TEXT - foreach my $tag (@tagnames) { - print "X-Git-Tag: $tag\n"; - } + print "X-Git-Tag: $tagname\n" if $tagname; print "X-Git-Url: " . $cgi->self_url() . "\n\n"; + foreach my $line (@{$co{'comment'}}) { print "$line\n"; } @@ -2806,8 +2868,8 @@ TEXT #git_difftree_body(\@difftree, $hash, $hash_parent); #print "
\n"; - git_patchset_body(\@patchset, \@difftree, $hash, $hash_parent); - + git_patchset_body($fd, \@difftree, $hash, $hash_parent); + close $fd; print "
\n"; # class="page_body" git_footer_html();