676
## ......................................................................
677
## git utility functions, directly accessing git repository
678
679
-# assumes that PATH is not symref
680
-sub git_get_hash_by_ref {
681
- my $path = shift;
682
-
683
- open my $fd, "$projectroot/$path" or return undef;
684
- my $head = <$fd>;
685
- close $fd;
686
- chomp $head;
687
- if ($head =~ m/^[0-9a-fA-F]{40}$/) {
688
- return $head;
689
- }
690
-}
691
-
679
sub git_get_project_description {
680
my $path = shift;
681
1085
my @reflist;
1086
1087
my @refs;
1101
- my $pfxlen = length("$projectroot/$project/$ref_dir");
1102
- File::Find::find(sub {
1103
- return if (/^\./);
1104
- if (-f $_) {
1105
- push @refs, substr($File::Find::name, $pfxlen + 1);
1088
+ open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1089
+ or return;
1090
+ while (my $line = <$fd>) {
1091
+ chomp $line;
1092
+ if ($line =~ m/^([0-9a-fA-F]{40})\t$ref_dir\/?([^\^]+)$/) {
1093
+ push @refs, { hash => $1, name => $2 };
1094
+ } elsif ($line =~ m/^[0-9a-fA-F]{40}\t$ref_dir\/?(.*)\^\{\}$/ &&
1095
+ $1 eq $refs[-1]{'name'}) {
1096
+ # most likely a tag is followed by its peeled
1097
+ # (deref) one, and when that happens we know the
1098
+ # previous one was of type 'tag'.
1099
+ $refs[-1]{'type'} = "tag";
1100
}
1107
- }, "$projectroot/$project/$ref_dir");
1101
+ }
1102
+ close $fd;
1103
+
1104
+ foreach my $ref (@refs) {
1105
+ my $ref_file = $ref->{'name'};
1106
+ my $ref_id = $ref->{'hash'};
1107
1109
- foreach my $ref_file (@refs) {
1110
- my $ref_id = git_get_hash_by_ref("$project/$ref_dir/$ref_file");
1111
- my $type = git_get_type($ref_id) || next;
1108
+ my $type = $ref->{'type'} || git_get_type($ref_id) || next;
1109
my %ref_item = parse_ref($ref_file, $ref_id, $type);
1110
1111
push @reflist, \%ref_item;