+sub get_file_owner {
+ my $path = shift;
+
+ my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
+ my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
+ if (!defined $gcos) {
+ return undef;
+ }
+ my $owner = $gcos;
+ $owner =~ s/[,;].*$//;
+ return $owner;
+}
+
+sub git_read_projects {
+ my @list;
+
+ if (-d $projects_list) {
+ # search in directory
+ my $dir = $projects_list;
+ opendir my $dh, $dir or return undef;
+ while (my $dir = readdir($dh)) {
+ if (-e "$projectroot/$dir/HEAD") {
+ my $pr = {
+ path => $dir,
+ };
+ push @list, $pr
+ }
+ }
+ closedir($dh);
+ } elsif (-f $projects_list) {
+ # read from file(url-encoded):
+ # 'git%2Fgit.git Linus+Torvalds'
+ # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
+ # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
+ open my $fd , $projects_list or return undef;
+ while (my $line = <$fd>) {
+ chomp $line;
+ my ($path, $owner) = split ' ', $line;
+ $path = unescape($path);
+ $owner = unescape($owner);
+ if (!defined $path) {
+ next;
+ }
+ if (-e "$projectroot/$path/HEAD") {
+ my $pr = {
+ path => $path,
+ owner => $owner,
+ };
+ push @list, $pr
+ }
+ }
+ close $fd;
+ }
+ @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
+ return @list;
+}
+
+sub git_project_list {
+ my @list = git_read_projects();
+ if (!@list) {
+ die_error(undef, "No project found.");
+ }
+ git_header_html();
+ if (-f $home_text) {
+ print "<div class=\"index_include\">\n";
+ open (my $fd, $home_text);
+ print <$fd>;
+ close $fd;
+ print "</div>\n";
+ }
+ print "<table cellspacing=\"0\">\n" .
+ "<tr>\n" .
+ "<th>Project</th>\n" .
+ "<th>Description</th>\n" .
+ "<th>Owner</th>\n" .
+ "<th>last change</th>\n" .
+ "<th></th>\n" .
+ "</tr>\n";
+ my $alternate = 0;
+ foreach my $pr (@list) {
+ my %proj = %$pr;
+ my $head = git_read_hash("$proj{'path'}/HEAD");
+ if (!defined $head) {
+ next;
+ }
+ $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
+ my %co = git_read_commit($head);
+ if (!%co) {
+ next;
+ }
+ my $descr = git_read_description($proj{'path'}) || "";
+ $descr = chop_str($descr, 25, 5);
+ # get directory owner if not already specified
+ if (!defined $proj{'owner'}) {
+ $proj{'owner'} = get_file_owner("$projectroot/$proj{'path'}") || "";
+ }
+ if ($alternate) {
+ print "<tr class=\"dark\">\n";
+ } else {
+ print "<tr class=\"light\">\n";
+ }
+ $alternate ^= 1;
+ print "<td>" . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary", -class => "list"}, escapeHTML($proj{'path'})) . "</td>\n" .
+ "<td>$descr</td>\n" .
+ "<td><i>" . chop_str($proj{'owner'}, 15) . "</i></td>\n";
+ my $colored_age;
+ if ($co{'age'} < 60*60*2) {
+ $colored_age = "<span style =\"color: #009900;\"><b><i>$co{'age_string'}</i></b></span>";
+ } elsif ($co{'age'} < 60*60*24*2) {
+ $colored_age = "<span style =\"color: #009900;\"><i>$co{'age_string'}</i></span>";
+ } else {
+ $colored_age = "<i>$co{'age_string'}</i>";
+ }
+ print "<td>$colored_age</td>\n" .
+ "<td class=\"link\">" .
+ $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary"}, "summary") .
+ " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=shortlog"}, "shortlog") .
+ " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=log"}, "log") .
+ "</td>\n" .
+ "</tr>\n";
+ }
+ print "</table>\n";
+ git_footer_html();
+}
+
+sub git_read_refs {
+ my $ref_dir = shift;
+ my @reflist;
+
+ my @refs;
+ opendir my $dh, "$projectroot/$project/$ref_dir";
+ while (my $dir = readdir($dh)) {
+ if ($dir =~ m/^\./) {
+ next;
+ }
+ if (-d "$projectroot/$project/$ref_dir/$dir") {
+ opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
+ my @subdirs = grep !m/^\./, readdir $dh2;
+ closedir($dh2);
+ foreach my $subdir (@subdirs) {
+ push @refs, "$dir/$subdir"
+ }
+ next;
+ }
+ push @refs, $dir;
+ }
+ closedir($dh);
+ foreach my $ref_file (@refs) {
+ my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
+ my $type = git_get_type($ref_id) || next;
+ my %ref_item;
+ my %co;
+ if ($type eq "tag") {
+ my %tag = git_read_tag($ref_id);
+ if ($tag{'type'} eq "commit") {
+ %co = git_read_commit($tag{'object'});
+ }
+ $ref_item{'type'} = $tag{'type'};
+ $ref_item{'name'} = $tag{'name'};
+ $ref_item{'id'} = $tag{'object'};
+ } elsif ($type eq "commit"){
+ %co = git_read_commit($ref_id);
+ $ref_item{'type'} = "commit";
+ $ref_item{'name'} = $ref_file;
+ $ref_item{'title'} = $co{'title'};
+ $ref_item{'id'} = $ref_id;
+ }
+ $ref_item{'epoch'} = $co{'committer_epoch'} || 0;
+ $ref_item{'age'} = $co{'age_string'} || "unknown";
+
+ push @reflist, \%ref_item;
+ }
+ # sort tags by age
+ @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
+ return \@reflist;