--- gitweb.cgi 2006-10-22 20:32:54.000000000 -0700 +++ gitweb.cgi 2006-10-22 20:38:40.000000000 -0700 @@ -30,6 +31,10 @@ #our $projectroot = "/pub/scm"; our $projectroot = "/home/kay/public_html/pub/scm"; +# paths to gzip/bzip2 commands +our $gzip = "/bin/gzip"; +our $bzip2 = "/usr/bin/bzip2"; + # version of the core git binary our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown"; @@ -184,6 +190,9 @@ } elsif ($action eq "tags") { git_tags(); exit; +} elsif ($action eq "gz" || $action eq "bz2" || $action eq "zip") { + git_archive($action); + exit; } elsif ($action eq "blob") { git_blob(); exit; @@ -1150,6 +1159,9 @@ print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log"); } + print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=gz;h=$tag{'id'}")}, "gz"); + print " | " .$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=bz2;h=$tag{'id'}")}, "bz2"); + print " | " .$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=zip;h=$tag{'id'}")}, "zip"); print "\n" . ""; } else { @@ -1469,6 +1481,9 @@ print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log"); } + print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=gz;h=$tag{'id'}")}, "gz"); + print " | " .$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=bz2;h=$tag{'id'}")}, "bz2"); + print " | " .$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=zip;h=$tag{'id'}")}, "zip"); print "\n" . ""; } @@ -1477,6 +1492,41 @@ git_footer_html(); } +sub git_archive() { + my $archive_action = shift; + my %tag = git_read_tag($hash); + my $tagname = $tag{'name'}; + if(!defined $tagname) { + $tagname = $hash; + } + my $buffer = ""; + if ($archive_action eq "gz") { + $compression = "gzip"; + $compression_cmd = "| $gzip"; + $extension = ".tar.gz"; + $format = "tar"; + } elsif ($archive_action eq "bz2") { + $compression = "bzip2"; + $compression_cmd = "| $bzip2"; + $extension = ".tar.bz2"; + $format = "tar"; + } elsif ($archive_action eq "zip") { + $compression = "zip-compressed"; + $compression_cmd = ""; + $extension = ".zip"; + $format = "zip"; + } + #print "Content-Type: multipart/x-$compression\n\n"; + #print "Content-Disposition: attachment; filename=\"$project-$tagname$extension\" \n\n"; + print $cgi->header(-type => "application/x-$compression", '-content-disposition' => "inline; filename=\"$project-$tagname$extension\""); + open my $fd, "-|", "$GIT archive --format=$format --prefix=$project-$tagname/ $hash $compression_cmd" or die_error(undef, "Open git archive failed"); + binmode STDOUT; + while(read($fd, $buffer, 1024) != 0) { + print $buffer; + } + close(FD); +} + sub git_heads { my $head = git_read_head($project); git_header_html();