Skip to content

Commit

Permalink
gitweb: Allow forks with project list file
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Frank Lichtenheld authored and Junio C Hamano committed Apr 11, 2007
1 parent f8ce182 commit c2b8b13
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ BEGIN
# projects matching $projname/*.git will not be shown in the main
# projects list, instead a '+' mark will be added to $projname
# there and a 'forks' view will be enabled for the project, listing
# all the forks. This feature is supported only if project list
# is taken from a directory, not file.
# all the forks. If project list is taken from a file, forks have
# to be listed after the main project.

# To enable system wide have in $GITWEB_CONFIG
# $feature{'forks'}{'default'} = [1];
Expand Down Expand Up @@ -1047,15 +1047,15 @@ sub git_get_projects_list {
$filter ||= '';
$filter =~ s/\.git$//;

my ($check_forks) = gitweb_check_feature('forks');

if (-d $projects_list) {
# search in directory
my $dir = $projects_list . ($filter ? "/$filter" : '');
# remove the trailing "/"
$dir =~ s!/+$!!;
my $pfxlen = length("$dir");

my ($check_forks) = gitweb_check_feature('forks');

File::Find::find({
follow_fast => 1, # follow symbolic links
dangling_symlinks => 0, # ignore dangling symlinks, silently
Expand All @@ -1081,7 +1081,9 @@ sub git_get_projects_list {
# 'git%2Fgit.git Linus+Torvalds'
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
my %paths;
open my ($fd), $projects_list or return;
PROJECT:
while (my $line = <$fd>) {
chomp $line;
my ($path, $owner) = split ' ', $line;
Expand All @@ -1094,19 +1096,37 @@ sub git_get_projects_list {
# looking for forks;
my $pfx = substr($path, 0, length($filter));
if ($pfx ne $filter) {
next;
next PROJECT;
}
my $sfx = substr($path, length($filter));
if ($sfx !~ /^\/.*\.git$/) {
next;
next PROJECT;
}
} elsif ($check_forks) {
PATH:
foreach my $filter (keys %paths) {
# looking for forks;
my $pfx = substr($path, 0, length($filter));
if ($pfx ne $filter) {
next PATH;
}
my $sfx = substr($path, length($filter));
if ($sfx !~ /^\/.*\.git$/) {
next PATH;
}
# is a fork, don't include it in
# the list
next PROJECT;
}
}
if (check_export_ok("$projectroot/$path")) {
my $pr = {
path => $path,
owner => to_utf8($owner),
};
push @list, $pr
push @list, $pr;
(my $forks_path = $path) =~ s/\.git$//;
$paths{$forks_path}++;
}
}
close $fd;
Expand Down

0 comments on commit c2b8b13

Please sign in to comment.