allow working in repositories with textual symref HEAD
Junio C Hamano committed
Jan 9, 2006 at 13:13 UTC
df2c37a5a1087b445589e366f6673ded8fdef7f0
1 file changed
+33
-16
gitweb.cgi
+33
-16
@@ -396,6 +396,23 @@ sub git_get_type {
396
return $type;
397
}
398
399
+sub git_read_head {
400
+ my $project = shift;
401
+ my $oENV = $ENV{'GIT_DIR'};
402
+ my $retval = undef;
403
+ $ENV{'GIT_DIR'} = "$projectroot/$project";
404
+ if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
405
+ my $head = <$fd>;
406
+ close $fd;
407
+ chomp $head;
408
+ if ($head =~ m/^[0-9a-fA-F]{40}$/) {
409
+ $retval = $head;
410
+ }
411
+ }
412
+ $ENV{'GIT_DIR'} = $oENV;
413
+ return $retval;
414
+}
415
+
416
sub git_read_hash {
417
my $path = shift;
418
@@ -823,7 +840,7 @@ sub git_project_list {
840
die_error(undef, "No project found.");
841
}
842
foreach my $pr (@list) {
826
- my $head = git_read_hash("$pr->{'path'}/HEAD");
843
+ my $head = git_read_head($pr->{'path'});
844
if (!defined $head) {
845
next;
846
}
@@ -994,7 +1011,7 @@ sub git_read_refs {
1011
1012
sub git_summary {
1013
my $descr = git_read_description($project) || "none";
997
- my $head = git_read_hash("$project/HEAD");
1014
+ my $head = git_read_head($project);
1015
my %co = git_read_commit($head);
1016
my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1017
@@ -1034,7 +1051,7 @@ sub git_summary {
1051
"<tr><td>owner</td><td>$owner</td></tr>\n" .
1052
"<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1053
"</table>\n";
1037
- open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
1054
+ open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head($project) or die_error(undef, "Open failed.");
1055
my (@revlist) = map { chomp; $_ } <$fd>;
1056
close $fd;
1057
print "<div>\n" .
@@ -1172,7 +1189,7 @@ sub git_summary {
1189
}
1190
1191
sub git_tag {
1175
- my $head = git_read_hash("$project/HEAD");
1192
+ my $head = git_read_head($project);
1193
git_header_html();
1194
print "<div class=\"page_nav\">\n" .
1195
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
@@ -1211,7 +1228,7 @@ sub git_tag {
1228
}
1229
1230
sub git_tags {
1214
- my $head = git_read_hash("$project/HEAD");
1231
+ my $head = git_read_head($project);
1232
git_header_html();
1233
print "<div class=\"page_nav\">\n" .
1234
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
@@ -1270,7 +1287,7 @@ sub git_tags {
1287
}
1288
1289
sub git_heads {
1273
- my $head = git_read_hash("$project/HEAD");
1290
+ my $head = git_read_head($project);
1291
git_header_html();
1292
print "<div class=\"page_nav\">\n" .
1293
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
@@ -1343,7 +1360,7 @@ sub git_get_hash_by_path {
1360
1361
sub git_blob {
1362
if (!defined $hash && defined $file_name) {
1346
- my $base = $hash_base || git_read_hash("$project/HEAD");
1363
+ my $base = $hash_base || git_read_head($project);
1364
$hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
1365
}
1366
open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
@@ -1407,13 +1424,13 @@ sub git_blob_plain {
1424
1425
sub git_tree {
1426
if (!defined $hash) {
1410
- $hash = git_read_hash("$project/HEAD");
1427
+ $hash = git_read_head($project);
1428
if (defined $file_name) {
1412
- my $base = $hash_base || git_read_hash("$project/HEAD");
1429
+ my $base = $hash_base || $hash;
1430
$hash = git_get_hash_by_path($base, $file_name, "tree");
1431
}
1432
if (!defined $hash_base) {
1416
- $hash_base = git_read_hash("$project/HEAD");
1433
+ $hash_base = $hash;
1434
}
1435
}
1436
$/ = "\0";
@@ -1497,7 +1514,7 @@ sub git_tree {
1514
1515
sub git_rss {
1516
# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1500
- open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
1517
+ open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed.");
1518
my (@revlist) = map { chomp; $_ } <$fd>;
1519
close $fd or die_error(undef, "Reading rev-list failed.");
1520
print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
@@ -1566,7 +1583,7 @@ sub git_opml {
1583
1584
foreach my $pr (@list) {
1585
my %proj = %$pr;
1569
- my $head = git_read_hash("$proj{'path'}/HEAD");
1586
+ my $head = git_read_head($proj{'path'});
1587
if (!defined $head) {
1588
next;
1589
}
@@ -1587,7 +1604,7 @@ sub git_opml {
1604
}
1605
1606
sub git_log {
1590
- my $head = git_read_hash("$project/HEAD");
1607
+ my $head = git_read_head($project);
1608
if (!defined $hash) {
1609
$hash = $head;
1610
}
@@ -2083,7 +2100,7 @@ sub git_commitdiff_plain {
2100
2101
sub git_history {
2102
if (!defined $hash) {
2086
- $hash = git_read_hash("$project/HEAD");
2103
+ $hash = git_read_head($project);
2104
}
2105
my %co = git_read_commit($hash);
2106
if (!%co) {
@@ -2159,7 +2176,7 @@ sub git_search {
2176
die_error("", "Text field empty.");
2177
}
2178
if (!defined $hash) {
2162
- $hash = git_read_hash("$project/HEAD");
2179
+ $hash = git_read_head($project);
2180
}
2181
my %co = git_read_commit($hash);
2182
if (!%co) {
@@ -2300,7 +2317,7 @@ sub git_search {
2317
}
2318
2319
sub git_shortlog {
2303
- my $head = git_read_hash("$project/HEAD");
2320
+ my $head = git_read_head($project);
2321
if (!defined $hash) {
2322
$hash = $head;
2323
}