Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot improvements #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion ISSUES
Expand Up @@ -4,4 +4,3 @@
* Gitweb compat URIs are borked - there were some I just wholesale ripped out. Put back.. * Gitweb compat URIs are borked - there were some I just wholesale ripped out. Put back..
* Sort out commitdiff so conflicted merges have an equivalent display to gitweb (d7f39bebabeb31ce9a7b4f1b6f3db9f391b78c3e as a reference) * Sort out commitdiff so conflicted merges have an equivalent display to gitweb (d7f39bebabeb31ce9a7b4f1b6f3db9f391b78c3e as a reference)
* Need to sanitise the input ... * Need to sanitise the input ...
* The snapshot action does not properly support tgz - requests for this format will receive a tar. tbz2 is not supported at all (yet).
5 changes: 5 additions & 0 deletions gitalist.conf
Expand Up @@ -20,3 +20,8 @@ sitename "A Gitalist"
<patches> <patches>
max = 16 max = 16
</patches> </patches>

<snapshot>
format = tar.bz2
tmpdir = /tmp/gitalist/snapshot
</snapshot>
11 changes: 7 additions & 4 deletions lib/Gitalist/Controller/Ref.pm
Expand Up @@ -49,15 +49,18 @@ Provides a snapshot of a given commit.


sub snapshot : Chained('find') PathPart('snapshot') Args() { sub snapshot : Chained('find') PathPart('snapshot') Args() {
my ($self, $c, $format) = @_; my ($self, $c, $format) = @_;
$format ||= 'tgz'; $format ||= Gitalist->config->{snapshot}{format} || "tar.bz2";
my @snap = $c->stash->{Repository}->snapshot( my @snap = $c->stash->{Repository}->snapshot(
sha1 => $c->stash->{Commit}->sha1, sha1 => $c->stash->{Commit}->sha1,
format => $format format => $format
); );
$c->response->status(200); $c->response->status(200);
$c->response->headers->header( 'Content-Disposition' => $c->response->content_type($snap[0]);
"attachment; filename=$snap[0]"); $c->response->content_length(-s $snap[2]);
$c->response->body($snap[1]); $c->response->headers->header('Content-Disposition' =>
"attachment; filename=$snap[1]");
open(my $fh, '<', $snap[2]);
$c->response->body($fh);
} }


=head2 patch =head2 patch
Expand Down
45 changes: 38 additions & 7 deletions lib/Gitalist/Git/Repository.pm
Expand Up @@ -12,6 +12,9 @@ class Gitalist::Git::Repository with (Gitalist::Git::HasUtils, Gitalist::Git::Se
use aliased 'DateTime' => 'DT'; use aliased 'DateTime' => 'DT';
use List::MoreUtils qw/any zip/; use List::MoreUtils qw/any zip/;
use Encode qw/decode/; use Encode qw/decode/;
use IPC::Run qw/run/;
use File::Spec qw/catfile/;
use File::Path qw/mkpath/;


use if $^O ne 'MSWin32' => 'I18N::Langinfo', qw/langinfo CODESET/; use if $^O ne 'MSWin32' => 'I18N::Langinfo', qw/langinfo CODESET/;


Expand Down Expand Up @@ -150,20 +153,48 @@ class Gitalist::Git::Repository with (Gitalist::Git::HasUtils, Gitalist::Git::Se
NonEmptySimpleStr :$format NonEmptySimpleStr :$format
) { ) {
# TODO - only valid formats are 'tar' and 'zip' # TODO - only valid formats are 'tar' and 'zip'
my $formats = { tgz => 'tar', zip => 'zip' }; my $formats = {
'tar.gz' => 'tar',
'tar.bz2' => 'tar',
zip => 'zip',
};
my $compressors = {
'tar.gz' => 'gzip',
'tar.bz2' => 'bzip2',
'tar.xz' => 'xz',
};
my $mimetypes = {
'tar.gz' => 'application/x-gzip',
'tar.bz2' => 'application/x-bzip2',
'tar.xz' => 'application/octet-stream',
};
unless ($formats->exists($format)) { unless ($formats->exists($format)) {
die("No such format: $format"); die("No such format: $format");
} }
$format = $formats->{$format}; my $ga_format = $formats->{$format};
my $name = $self->name; my $name = $self->name;
$name =~ s,([^/])/*\.git$,$1,; $name =~ s,([^/])/*\.git$,$1,;
my $filename = $name; my $sha1_abbrev = $self->run_cmd(('log', '--pretty=format:%h', '-1', $sha1));
$filename .= "-$sha1.$format"; my $filename = "$name-$sha1_abbrev.$format";
my $ga_filename = "$name-$sha1_abbrev.$ga_format";
$name =~ s/\047/\047\\\047\047/g; $name =~ s/\047/\047\\\047\047/g;


my @cmd = ('archive', "--format=$format", "--prefix=$name/", $sha1); my $local_dir = Gitalist->config->{snapshot}{tmpdir} || "/tmp/gitalist/snapshot";
return ($filename, $self->run_cmd_fh(@cmd)); $local_dir = File::Spec->catfile($local_dir, substr($sha1,0,2), substr($sha1,0,4));
# TODO - support compressed archives my $local_filename = File::Spec->catfile($local_dir, $filename);
my $local_ga_filename = File::Spec->catfile($local_dir, $ga_filename);
if(!-e $local_filename) {
if(! -e $local_dir) {
mkpath($local_dir, 0, 0755);
}
my @cmd = ('archive', "--format=$ga_format", "--prefix=$name-$sha1_abbrev/", $sha1, "--output=$local_ga_filename");
$self->run_cmd(@cmd);
if($compressors->exists($format)) {
run [$compressors->{$format}, $local_ga_filename];
}
}

return ($mimetypes->{$format}, $filename, $local_filename);
} }


method reflog (@logargs) { method reflog (@logargs) {
Expand Down
1 change: 1 addition & 0 deletions root/fragment/repository/shortlog.tt2
Expand Up @@ -33,6 +33,7 @@
<a href="[% c.uri_for_action("/ref/commit", [Repository.name, line.sha1]) %]" title="Commit details" class="button commit">commit</a> <a href="[% c.uri_for_action("/ref/commit", [Repository.name, line.sha1]) %]" title="Commit details" class="button commit">commit</a>
<a href="[% c.uri_for_action("/ref/diff_fancy", [Repository.name, line.sha1]) %]" title="Commit difference" class="button diff">commitdiff</a> <a href="[% c.uri_for_action("/ref/diff_fancy", [Repository.name, line.sha1]) %]" title="Commit difference" class="button diff">commitdiff</a>
<a href="[% c.uri_for_action("/ref/tree", [Repository.name, line.sha1]) %]" title="Tree" class="button tree">tree</a> <a href="[% c.uri_for_action("/ref/tree", [Repository.name, line.sha1]) %]" title="Tree" class="button tree">tree</a>
<a href="[% c.uri_for_action("/ref/snapshot", [Repository.name, line.sha1]) %]" title="Snapshot" class="button snapshot">snapshot</a>
</td> </td>
</tr> </tr>
[% END %] [% END %]
Expand Down
5 changes: 4 additions & 1 deletion root/static/css/core.css
Expand Up @@ -258,6 +258,9 @@ a.longlog{
a.blob{ a.blob{
background:transparent url([% c.uri_for('/static/i/icons/blob.png') %]) no-repeat; background:transparent url([% c.uri_for('/static/i/icons/blob.png') %]) no-repeat;
} }
a.snapshot{
background:transparent url([% c.uri_for('/static/i/icons/blob.png') %]) no-repeat;
}
a.blame{ a.blame{
background:transparent url([% c.uri_for('/static/i/icons/blame.png') %]) no-repeat; background:transparent url([% c.uri_for('/static/i/icons/blame.png') %]) no-repeat;
} }
Expand Down Expand Up @@ -444,7 +447,7 @@ BUT the final width needs to be set with javascript based on the parent element
*/ */


.action-list{ .action-list{
width:120px; width:160px;
} }


.diff-tree{ .diff-tree{
Expand Down