summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 157e43b)
raw | patch | inline | side by side (parent: 157e43b)
author | Jakub Narebski <jnareb@gmail.com> | |
Thu, 24 Aug 2006 17:37:04 +0000 (19:37 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sat, 26 Aug 2006 02:39:34 +0000 (19:39 -0700) |
Adds git_get_following_references function, based on code which was
used in git_commitdiff_plain to generate X-Git-Tag: header,
and companion git_get_preceding_references function.
Both functions return array of all references of given type (as
returned by git_get_references) following/preceding given commit in
array (list) context, and last following/first preceding ref in scalar
context.
Stripping ref (list of refs) of "$type/" (e.g. "tags/") is left to
caller.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
used in git_commitdiff_plain to generate X-Git-Tag: header,
and companion git_get_preceding_references function.
Both functions return array of all references of given type (as
returned by git_get_references) following/preceding given commit in
array (list) context, and last following/first preceding ref in scalar
context.
Stripping ref (list of refs) of "$type/" (e.g. "tags/") is left to
caller.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
gitweb/gitweb.perl | patch | blob | history |
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 08e0472c6111d6e922a3ba6fc8d611abed96ac73..b964302a5aa9a24cedc39bb3ffcabb9bc91b6f50 100755 (executable)
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
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