From 9a3d665919218ebe30fd1b10a70e75db16675bff Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Mon, 10 Feb 2014 21:46:46 +0200
Subject: [PATCH] Show last commit for Blob#show

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
---
 app/assets/stylesheets/sections/tree.scss   | 18 ++++++++++++++++++
 app/controllers/projects/refs_controller.rb |  2 +-
 app/models/repository.rb                    |  4 ++++
 app/views/projects/blob/_blob.html.haml     |  4 ++++
 app/views/projects/blob/show.html.haml      |  1 +
 5 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/app/assets/stylesheets/sections/tree.scss b/app/assets/stylesheets/sections/tree.scss
index dfdcbb59b..f72c66071 100644
--- a/app/assets/stylesheets/sections/tree.scss
+++ b/app/assets/stylesheets/sections/tree.scss
@@ -133,3 +133,21 @@
     color: #777;
   }
 }
+
+.blob-commit-info {
+  list-style: none;
+  margin: 0;
+  padding: 0;
+  margin-bottom: 10px;
+
+  .commit {
+    .commit-row-title {
+      font-size: 13px;
+
+      .commit-row-message {
+        font-weight: normal;
+        color: #555;
+      }
+    }
+  }
+}
diff --git a/app/controllers/projects/refs_controller.rb b/app/controllers/projects/refs_controller.rb
index 16621c037..7b8026cff 100644
--- a/app/controllers/projects/refs_controller.rb
+++ b/app/controllers/projects/refs_controller.rb
@@ -34,7 +34,7 @@ class Projects::RefsController < Projects::ApplicationController
     contents = tree.entries
     @logs = contents.map do |content|
       file = params[:path] ? File.join(params[:path], content.name) : content.name
-      last_commit = @repo.commits(@commit.id, file, 1).last
+      last_commit = @repo.last_commit_for_path(@commit.id, file)
       {
         file_name: content.name,
         commit: last_commit
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 527dff519..2c2bf242b 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -204,4 +204,8 @@ class Repository
       end
     end
   end
+
+  def last_commit_for_path(sha, path)
+    commits(sha, path, 1).last
+  end
 end
diff --git a/app/views/projects/blob/_blob.html.haml b/app/views/projects/blob/_blob.html.haml
index 32ea96710..e59d970bf 100644
--- a/app/views/projects/blob/_blob.html.haml
+++ b/app/views/projects/blob/_blob.html.haml
@@ -15,6 +15,10 @@
       - else
         = link_to title, '#'
 
+%ul.blob-commit-info.bs-callout.bs-callout-info
+  - blob_commit = @repository.last_commit_for_path(@commit.id, @blob.path)
+  = render blob_commit, project: @project
+
 %div#tree-content-holder.tree-content-holder
   .file-holder
     .file-title
diff --git a/app/views/projects/blob/show.html.haml b/app/views/projects/blob/show.html.haml
index 56220e520..69167654c 100644
--- a/app/views/projects/blob/show.html.haml
+++ b/app/views/projects/blob/show.html.haml
@@ -1,5 +1,6 @@
 %div.tree-ref-holder
   = render 'shared/ref_switcher', destination: 'blob', path: @path
+
 %div#tree-holder.tree-holder
   = render 'blob', blob: @blob
 
-- 
2.30.9