diff options
-rwxr-xr-x | gitweb/gitweb.perl | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 08e0472c6..b964302a5 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -749,6 +749,58 @@ 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; + my $firstref; + + foreach my $commit (@commits) { + foreach my $ref (@{$refs->{$commit}}) { + $firstref = $ref unless $firstref; + push @reflist, $ref; + } + } + + return wantarray ? @reflist : $firstref; +} + ## ---------------------------------------------------------------------- ## parse to hash functions |