... | ... |
@@ -12,9 +12,6 @@ sub raw { |
12 | 12 |
|
13 | 13 |
# Git |
14 | 14 |
my $git = $self->app->git; |
15 |
- |
|
16 |
- # Commit |
|
17 |
- my $commit_log = $git->latest_commit_log($user, $project, $rev, $file); |
|
18 | 15 |
|
19 | 16 |
# Blob raw |
20 | 17 |
my $blob_raw = $git->blob_raw($user, $project, $rev, $file); |
... | ... |
@@ -339,15 +339,6 @@ sub commits_number { |
339 | 339 |
return $commits_num; |
340 | 340 |
} |
341 | 341 |
|
342 |
-sub delete_project { |
|
343 |
- my ($self, $user, $project) = @_; |
|
344 |
- |
|
345 |
- croak "Invalid user name or project" |
|
346 |
- unless defined $user && defined $project; |
|
347 |
- my $rep = $self->rep($user, $project); |
|
348 |
- rmtree($rep); |
|
349 |
-} |
|
350 |
- |
|
351 | 342 |
sub description { |
352 | 343 |
my ($self, $user, $project, $description) = @_; |
353 | 344 |
|
... | ... |
@@ -369,6 +360,28 @@ sub description { |
369 | 360 |
} |
370 | 361 |
} |
371 | 362 |
|
363 |
+sub blob_mode { |
|
364 |
+ my ($self, $user, $project, $rev, $file) = @_; |
|
365 |
+ |
|
366 |
+ # Mode |
|
367 |
+ $file =~ s#/+$##; |
|
368 |
+ my @cmd = $self->cmd( |
|
369 |
+ $user, |
|
370 |
+ $project, |
|
371 |
+ 'ls-tree', |
|
372 |
+ $rev, |
|
373 |
+ '--', |
|
374 |
+ $file |
|
375 |
+ ); |
|
376 |
+ open my $fh, '-|', @cmd |
|
377 |
+ or croak 'Open git-ls-tree failed'; |
|
378 |
+ my $line = $self->_dec(scalar <$fh>); |
|
379 |
+ close $fh or return; |
|
380 |
+ my ($mode) = ($line || '') =~ m/^([0-9]+) /; |
|
381 |
+ |
|
382 |
+ return $mode; |
|
383 |
+} |
|
384 |
+ |
|
372 | 385 |
sub file_type { |
373 | 386 |
my ($self, $mode) = @_; |
374 | 387 |
|
... | ... |
@@ -390,11 +403,11 @@ sub file_type_long { |
390 | 403 |
# File type |
391 | 404 |
if ($mode !~ m/^[0-7]+$/) { return $mode } |
392 | 405 |
else { $mode = oct $mode } |
393 |
- if (S_ISGITLINK($mode)) { return 'submodule' } |
|
406 |
+ if ($self->_s_isgitlink($mode)) { return 'submodule' } |
|
394 | 407 |
elsif (S_ISDIR($mode & S_IFMT)) { return 'directory' } |
395 | 408 |
elsif (S_ISLNK($mode)) { return 'symlink' } |
396 | 409 |
elsif (S_ISREG($mode)) { |
397 |
- if ($mode & S_IXUSR) { return 'executable' } |
|
410 |
+ if ($mode & S_IXUSR) { return 'executable file' } |
|
398 | 411 |
else { return 'file' } |
399 | 412 |
} |
400 | 413 |
else { return 'unknown' } |
... | ... |
@@ -594,13 +607,13 @@ sub path_by_id { |
594 | 607 |
|
595 | 608 |
# Command "git ls-tree" |
596 | 609 |
my @cmd = $self->cmd($user, $project, 'ls-tree', '-r', '-t', '-z', $base); |
597 |
- open my $fh, '-|' or return; |
|
610 |
+ open my $fh, '-|', @cmd or return; |
|
598 | 611 |
|
599 | 612 |
# Get path |
600 | 613 |
local $/ = "\0"; |
601 | 614 |
while (my $line = <$fh>) { |
602 |
- $line = d$line; |
|
603 | 615 |
chomp $line; |
616 |
+ $line = $self->_dec($line); |
|
604 | 617 |
|
605 | 618 |
if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) { |
606 | 619 |
close $fh; |
... | ... |
@@ -851,49 +864,6 @@ sub id_set_multi { |
851 | 864 |
else { push @{$cid->{$key}}, $value } |
852 | 865 |
} |
853 | 866 |
|
854 |
-sub latest_commit_log { |
|
855 |
- my ($self, $user, $project, $rev, $file) = @_; |
|
856 |
- |
|
857 |
- my $commit_log = {}; |
|
858 |
- $file = '' unless defined $file; |
|
859 |
- |
|
860 |
- my @cmd = $self->cmd( |
|
861 |
- $user, |
|
862 |
- $project, |
|
863 |
- '--no-pager', |
|
864 |
- 'log', |
|
865 |
- '-n', |
|
866 |
- '1', |
|
867 |
- '--pretty=format:%H - %an - %ar : %s', |
|
868 |
- $rev, |
|
869 |
- '--', |
|
870 |
- $file |
|
871 |
- ); |
|
872 |
- open my $fh, '-|', @cmd |
|
873 |
- or croak 'Open git-log failed'; |
|
874 |
- |
|
875 |
- local $/; |
|
876 |
- my $commit_log_text = $self->_dec(scalar <$fh>); |
|
877 |
- |
|
878 |
- if ($commit_log_text =~ /^([0-9a-zA-Z]+) - (.+) - (.+?) : (.+)/) { |
|
879 |
- $commit_log->{commit} = $1; |
|
880 |
- $commit_log->{author} = $2; |
|
881 |
- $commit_log->{author_date} = $3; |
|
882 |
- my $comment = $4; |
|
883 |
- my $comment_short |
|
884 |
- = length $comment > 60 |
|
885 |
- ? substr($comment, 0, 60) . '...' |
|
886 |
- : $comment; |
|
887 |
- $commit_log->{comment} = $comment_short; |
|
888 |
- } |
|
889 |
- |
|
890 |
- $commit_log->{author_date} =~ s/,.*$//; |
|
891 |
- $commit_log->{author_date} =~ s/ +ago.*$//; |
|
892 |
- $commit_log->{author_date} .= ' ago'; |
|
893 |
- |
|
894 |
- return $commit_log; |
|
895 |
-} |
|
896 |
- |
|
897 | 867 |
sub last_change_commit { |
898 | 868 |
my ($self, $user, $project, $rev, $file) = @_; |
899 | 869 |
|
... | ... |
@@ -11,11 +11,8 @@ |
11 | 11 |
# Git |
12 | 12 |
my $git = $self->app->git; |
13 | 13 |
|
14 |
- # Commit log |
|
15 |
- my $commit_log = $git->latest_commit_log($user, $project, $rev, $file); |
|
16 |
- |
|
17 | 14 |
# Commit |
18 |
- my $commit = $git->get_commit($user, $project, $rev); |
|
15 |
+ my $commit = $git->last_change_commit($user, $project, $rev, $file); |
|
19 | 16 |
|
20 | 17 |
# Authors |
21 | 18 |
my $authors = $git->authors($user, $project, $rev, $file); |
... | ... |
@@ -26,6 +23,10 @@ |
26 | 23 |
# File size |
27 | 24 |
my $file_size = $git->blob_size_kb($user, $project, $rev, $file); |
28 | 25 |
|
26 |
+ # File mode |
|
27 |
+ my $mode = $git->blob_mode($user, $project, $rev, $file); |
|
28 |
+ my $file_type = $git->file_type_long($mode); |
|
29 |
+ |
|
29 | 30 |
# MIME type |
30 | 31 |
my $mimetype = $git->blob_mimetype($user, $project, $rev, $file); |
31 | 32 |
|
... | ... |
@@ -43,28 +44,29 @@ |
43 | 44 |
%= include '/include/page_path', type => 'blob', Path => $file; |
44 | 45 |
|
45 | 46 |
<div class="border-gray" style="margin-bottom:20px"> |
46 |
- <div class="bk-blue-light padding5"> |
|
47 |
- <%= $commit_log->{author} %> |
|
48 |
- <span class="muted"><%= $commit_log->{author_date} %></span> |
|
49 |
- <a href="<%= url_for("/$user/$project/commit/$rev") %>"> |
|
47 |
+ <div class="bk-blue-light" style="padding:5px"> |
|
48 |
+ <a style="color:#333;font-weight:bold" href="#" title="<%= $commit->{author_email} %>"><%= $commit->{author_name} %></a> |
|
49 |
+ <span class="muted" title="<%= $commit->{age_string_date} %>"><%= $commit->{age_string} %></span> |
|
50 |
+ <a style="color:#666" href="<%= url_for("/$user/$project/commit/$rev") %>"> |
|
50 | 51 |
<%= $commit->{title} %> |
51 | 52 |
</a> |
52 | 53 |
</div> |
53 |
- <div class="padding5"> |
|
54 |
- <%= @$authors %> contributor |
|
54 |
+ <div style="padding:5px"> |
|
55 |
+ <b><%= @$authors %></b> <span class="muted">contributor</span> |
|
55 | 56 |
</div> |
56 | 57 |
</div> |
57 | 58 |
|
58 |
- <div class="border-gray bk-gray-light padding5"> |
|
59 |
+ <div class="border-gray bk-gray-light" style="padding:5px"> |
|
59 | 60 |
<div class="row"> |
60 | 61 |
<div class="span7" style="padding-top:5px"> |
61 | 62 |
<i class="icon-file icon-white"></i> |
62 |
- <span style="color:gray">|</span> |
|
63 |
+ <%= $file_type %> |
|
64 |
+ <span class="muted">|</span> |
|
63 | 65 |
<%= @$lines %> lines |
64 |
- <span style="color:gray">|</span> |
|
66 |
+ <span class="muted">|</span> |
|
65 | 67 |
<%= $file_size %>kb |
66 | 68 |
</div> |
67 |
- <div class="span4 offset1-mini text-right"> |
|
69 |
+ <div class="text-right"> |
|
68 | 70 |
<a class="btn" href="<%= url_for("/$user/$project/raw/$rev/$file") %>">Raw</a><a class="btn" href="<%= url_for("/$user/$project/commits/$rev/$file") %>">History</a> |
69 | 71 |
</div> |
70 | 72 |
</div> |