@matheusbsbs / matheus-bagliano / commits / 2172ce4b01
Fork 0

gitweb: prepare for repositories with packed refs.

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>

Junio C Hamano committed Oct 3, 2006 at 02:30 UTC 2172ce4b01c862e66e3d581282dc92223cbd28fa
1 file changed +20 -6
gitweb/gitweb.perl
+20 -6
@@ -180,6 +180,22 @@ sub feature_pickaxe {
180 return ($_[0]);
181 }
182
183 +# checking HEAD file with -e is fragile if the repository was
184 +# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
185 +# and then pruned.
186 +sub check_head_link {
187 + my ($dir) = @_;
188 + my $headfile = "$dir/HEAD";
189 + return ((-e $headfile) ||
190 + (-l $headfile && readlink($headfile) =~ /^refs\/heads\//));
191 +}
192 +
193 +sub check_export_ok {
194 + my ($dir) = @_;
195 + return (check_head_link($dir) &&
196 + (!$export_ok || -e "$dir/$export_ok"));
197 +}
198 +
199 # rename detection options for git-diff and git-diff-tree
200 # - default is '-M', with the cost proportional to
201 # (number of removed files) * (number of new files).
@@ -212,7 +228,7 @@ our $project = $cgi->param('p');
228 if (defined $project) {
229 if (!validate_pathname($project) ||
230 !(-d "$projectroot/$project") ||
215 - !(-e "$projectroot/$project/HEAD") ||
231 + !check_head_link("$projectroot/$project") ||
232 ($export_ok && !(-e "$projectroot/$project/$export_ok")) ||
233 ($strict_export && !project_in_list($project))) {
234 undef $project;
@@ -289,7 +305,7 @@ sub evaluate_path_info {
305 # find which part of PATH_INFO is project
306 $project = $path_info;
307 $project =~ s,/+$,,;
292 - while ($project && !-e "$projectroot/$project/HEAD") {
308 + while ($project && !check_head_link("$projectroot/$project")) {
309 $project =~ s,/*[^/]*$,,;
310 }
311 # validate project
@@ -816,8 +832,7 @@ sub git_get_projects_list {
832
833 my $subdir = substr($File::Find::name, $pfxlen + 1);
834 # we check related file in $projectroot
819 - if (-e "$projectroot/$subdir/HEAD" && (!$export_ok ||
820 - -e "$projectroot/$subdir/$export_ok")) {
835 + if (check_export_ok("$projectroot/$subdir")) {
836 push @list, { path => $subdir };
837 $File::Find::prune = 1;
838 }
@@ -838,8 +853,7 @@ sub git_get_projects_list {
853 if (!defined $path) {
854 next;
855 }
841 - if (-e "$projectroot/$path/HEAD" && (!$export_ok ||
842 - -e "$projectroot/$path/$export_ok")) {
856 + if (check_export_ok("$projectroot/$path")) {
857 my $pr = {
858 path => $path,
859 owner => decode("utf8", $owner, Encode::FB_DEFAULT),