summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 954a618)
raw | patch | inline | side by side (parent: 954a618)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 3 Oct 2006 09:30:47 +0000 (02:30 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 3 Oct 2006 09:30:47 +0000 (02:30 -0700) |
When a repository is initialized long time ago with symbolic
HEAD, and "git-pack-refs --prune" is run, HEAD will be a
dangling symlink to refs/heads/ somewhere.
Running -e "$dir/HEAD" to guess if $dir is a git repository does
not give us the right answer anymore in such a case.
Also factor out two places that checked if the repository can be
exported with similar code into a call to a new function,
check_export_ok.
Signed-off-by: Junio C Hamano <junkio@cox.net>
HEAD, and "git-pack-refs --prune" is run, HEAD will be a
dangling symlink to refs/heads/ somewhere.
Running -e "$dir/HEAD" to guess if $dir is a git repository does
not give us the right answer anymore in such a case.
Also factor out two places that checked if the repository can be
exported with similar code into a call to a new function,
check_export_ok.
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 55d1b2c35529ad73260e3d395f7b2bdba39d0bfc..671a4e6e6f51b569a897a852e288c2a3c1f52bc4 100644 (file)
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
return ($_[0]);
}
+# checking HEAD file with -e is fragile if the repository was
+# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
+# and then pruned.
+sub check_head_link {
+ my ($dir) = @_;
+ my $headfile = "$dir/HEAD";
+ return ((-e $headfile) ||
+ (-l $headfile && readlink($headfile) =~ /^refs\/heads\//));
+}
+
+sub check_export_ok {
+ my ($dir) = @_;
+ return (check_head_link($dir) &&
+ (!$export_ok || -e "$dir/$export_ok"));
+}
+
# rename detection options for git-diff and git-diff-tree
# - default is '-M', with the cost proportional to
# (number of removed files) * (number of new files).
if (defined $project) {
if (!validate_pathname($project) ||
!(-d "$projectroot/$project") ||
- !(-e "$projectroot/$project/HEAD") ||
+ !check_head_link("$projectroot/$project") ||
($export_ok && !(-e "$projectroot/$project/$export_ok")) ||
($strict_export && !project_in_list($project))) {
undef $project;
# find which part of PATH_INFO is project
$project = $path_info;
$project =~ s,/+$,,;
- while ($project && !-e "$projectroot/$project/HEAD") {
+ while ($project && !check_head_link("$projectroot/$project")) {
$project =~ s,/*[^/]*$,,;
}
# validate project
my $subdir = substr($File::Find::name, $pfxlen + 1);
# we check related file in $projectroot
- if (-e "$projectroot/$subdir/HEAD" && (!$export_ok ||
- -e "$projectroot/$subdir/$export_ok")) {
+ if (check_export_ok("$projectroot/$subdir")) {
push @list, { path => $subdir };
$File::Find::prune = 1;
}
if (!defined $path) {
next;
}
- if (-e "$projectroot/$path/HEAD" && (!$export_ok ||
- -e "$projectroot/$path/$export_ok")) {
+ if (check_export_ok("$projectroot/$path")) {
my $pr = {
path => $path,
owner => decode("utf8", $owner, Encode::FB_DEFAULT),