gitweb: Allow forks with project list file
Make it possible to use the forks feature even when reading the list of projects from a file, by creating a list of known prefixes as we go. Forks have to be listed after the main project in order to be recognised as such. Signed-off-by: Frank Lichtenheld <frank@lichtenheld.de> Acked-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>
Frank Lichtenheld committed
Apr 6, 2007 at 23:58 UTC
c2b8b13494f3de6bd9a22162973e4df32665a966
1 file changed
+27
-7
gitweb/gitweb.perl
+27
-7
@@ -176,8 +176,8 @@ our %feature = (
176
# projects matching $projname/*.git will not be shown in the main
177
# projects list, instead a '+' mark will be added to $projname
178
# there and a 'forks' view will be enabled for the project, listing
179
- # all the forks. This feature is supported only if project list
180
- # is taken from a directory, not file.
179
+ # all the forks. If project list is taken from a file, forks have
180
+ # to be listed after the main project.
181
182
# To enable system wide have in $GITWEB_CONFIG
183
# $feature{'forks'}{'default'} = [1];
@@ -1047,6 +1047,8 @@ sub git_get_projects_list {
1047
$filter ||= '';
1048
$filter =~ s/\.git$//;
1049
1050
+ my ($check_forks) = gitweb_check_feature('forks');
1051
+
1052
if (-d $projects_list) {
1053
# search in directory
1054
my $dir = $projects_list . ($filter ? "/$filter" : '');
@@ -1054,8 +1056,6 @@ sub git_get_projects_list {
1056
$dir =~ s!/+$!!;
1057
my $pfxlen = length("$dir");
1058
1057
- my ($check_forks) = gitweb_check_feature('forks');
1058
-
1059
File::Find::find({
1060
follow_fast => 1, # follow symbolic links
1061
dangling_symlinks => 0, # ignore dangling symlinks, silently
@@ -1081,7 +1081,9 @@ sub git_get_projects_list {
1081
# 'git%2Fgit.git Linus+Torvalds'
1082
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1083
# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1084
+ my %paths;
1085
open my ($fd), $projects_list or return;
1086
+ PROJECT:
1087
while (my $line = <$fd>) {
1088
chomp $line;
1089
my ($path, $owner) = split ' ', $line;
@@ -1094,11 +1096,27 @@ sub git_get_projects_list {
1096
# looking for forks;
1097
my $pfx = substr($path, 0, length($filter));
1098
if ($pfx ne $filter) {
1097
- next;
1099
+ next PROJECT;
1100
}
1101
my $sfx = substr($path, length($filter));
1102
if ($sfx !~ /^\/.*\.git$/) {
1101
- next;
1103
+ next PROJECT;
1104
+ }
1105
+ } elsif ($check_forks) {
1106
+ PATH:
1107
+ foreach my $filter (keys %paths) {
1108
+ # looking for forks;
1109
+ my $pfx = substr($path, 0, length($filter));
1110
+ if ($pfx ne $filter) {
1111
+ next PATH;
1112
+ }
1113
+ my $sfx = substr($path, length($filter));
1114
+ if ($sfx !~ /^\/.*\.git$/) {
1115
+ next PATH;
1116
+ }
1117
+ # is a fork, don't include it in
1118
+ # the list
1119
+ next PROJECT;
1120
}
1121
}
1122
if (check_export_ok("$projectroot/$path")) {
@@ -1106,7 +1124,9 @@ sub git_get_projects_list {
1124
path => $path,
1125
owner => to_utf8($owner),
1126
};
1109
- push @list, $pr
1127
+ push @list, $pr;
1128
+ (my $forks_path = $path) =~ s/\.git$//;
1129
+ $paths{$forks_path}++;
1130
}
1131
}
1132
close $fd;