gitweb: Support for snapshot
This adds snapshort support in gitweb. To enable one need to set gitweb.snapshot = true in the config file. Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@hp.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Aneesh Kumar K.V committed
Aug 17, 2006 at 20:59 UTC
cb9c6e5b0a3772a979aff10f58a2b7fcd0fbe7d9
1 file changed
+37
-4
gitweb/gitweb.perl
+37
-4
@@ -15,6 +15,7 @@ use CGI::Carp qw(fatalsToBrowser);
15
use Encode;
16
use Fcntl ':mode';
17
use File::Find qw();
18
+use File::Basename qw(basename);
19
binmode STDOUT, ':utf8';
20
21
our $cgi = new CGI;
@@ -183,6 +184,7 @@ my %actions = (
184
"tag" => \&git_tag,
185
"tags" => \&git_tags,
186
"tree" => \&git_tree,
187
+ "snapshot" => \&git_snapshot,
188
);
189
190
$action = 'summary' if (!defined($action));
@@ -1389,6 +1391,7 @@ sub git_difftree_body {
1391
sub git_shortlog_body {
1392
# uses global variable $project
1393
my ($revlist, $from, $to, $refs, $extra) = @_;
1394
+ my $have_snapshot = git_get_project_config_bool('snapshot');
1395
$from = 0 unless defined $from;
1396
$to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1397
@@ -1413,8 +1416,11 @@ sub git_shortlog_body {
1416
print "</td>\n" .
1417
"<td class=\"link\">" .
1418
$cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
1416
- $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
1417
- "</td>\n" .
1419
+ $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
1420
+ if ($have_snapshot) {
1421
+ print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
1422
+ }
1423
+ print "</td>\n" .
1424
"</tr>\n";
1425
}
1426
if (defined $extra) {
@@ -2181,6 +2187,29 @@ sub git_tree {
2187
git_footer_html();
2188
}
2189
2190
+sub git_snapshot {
2191
+
2192
+ if (!defined $hash) {
2193
+ $hash = git_get_head_hash($project);
2194
+ }
2195
+
2196
+ my $filename = basename($project) . "-$hash.tar.gz";
2197
+
2198
+ print $cgi->header(-type => 'application/x-tar',
2199
+ -content-encoding => 'gzip',
2200
+ '-content-disposition' => "inline; filename=\"$filename\"",
2201
+ -status => '200 OK');
2202
+
2203
+ open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | gzip" or
2204
+ die_error(undef, "Execute git-tar-tree failed.");
2205
+ binmode STDOUT, ':raw';
2206
+ print <$fd>;
2207
+ binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
2208
+ close $fd;
2209
+
2210
+
2211
+}
2212
+
2213
sub git_log {
2214
my $head = git_get_head_hash($project);
2215
if (!defined $hash) {
@@ -2258,6 +2287,7 @@ sub git_commit {
2287
}
2288
my $refs = git_get_references();
2289
my $ref = format_ref_marker($refs, $co{'id'});
2290
+ my $have_snapshot = git_get_project_config_bool('snapshot');
2291
my $formats_nav = '';
2292
if (defined $file_name && defined $co{'parent'}) {
2293
my $parent = $co{'parent'};
@@ -2293,8 +2323,11 @@ sub git_commit {
2323
"<td class=\"sha1\">" .
2324
$cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash), class => "list"}, $co{'tree'}) .
2325
"</td>" .
2296
- "<td class=\"link\">" . $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, "tree") .
2297
- "</td>" .
2326
+ "<td class=\"link\">" . $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, "tree");
2327
+ if ($have_snapshot) {
2328
+ print " | " . $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
2329
+ }
2330
+ print "</td>" .
2331
"</tr>\n";
2332
my $parents = $co{'parents'};
2333
foreach my $par (@$parents) {