Index: trunk/app/controllers/repositories_controller.rb
===================================================================
--- trunk/app/controllers/repositories_controller.rb	(revision 946)
+++ trunk/app/controllers/repositories_controller.rb	(revision 947)
@@ -95,6 +95,11 @@
     end
   end
   
+  def annotate
+    @annotate = @repository.scm.annotate(@path, @rev)
+    show_error and return if @annotate.nil? || @annotate.empty?
+  end
+  
   def revision
     @changeset = @repository.changesets.find_by_revision(@rev)
     raise ChangesetNotFound unless @changeset
Index: trunk/app/models/repository.rb
===================================================================
--- trunk/app/models/repository.rb	(revision 946)
+++ trunk/app/models/repository.rb	(revision 947)
@@ -33,6 +33,10 @@
   def supports_cat?
     scm.supports_cat?
   end
+
+  def supports_annotate?
+    scm.supports_annotate?
+  end
   
   def entries(path=nil, identifier=nil)
     scm.entries(path, identifier)
Index: trunk/app/views/repositories/annotate.rhtml
===================================================================
--- trunk/app/views/repositories/annotate.rhtml	(nonexistent)
+++ trunk/app/views/repositories/annotate.rhtml	(revision 947)
@@ -0,0 +1,26 @@
+<h2><%= render :partial => 'navigation', :locals => { :path => @path, :kind => 'file', :revision => @rev } %></h2>
+
+<% colors = Hash.new {|k,v| k[v] = (k.size % 12) } %>
+
+<div class="autoscroll">
+<table class="filecontent annotate CodeRay">
+  <tbody>
+    <% line_num = 1 %>
+    <% syntax_highlight(@path, to_utf8(@annotate.content)).each_line do |line| %>
+    <% revision = @annotate.revisions[line_num-1] %>
+    <tr class="bloc-<%= revision.nil? ? 0 : colors[revision.identifier || revision.revision] %>">
+      <th class="line-num"><%= line_num %></th>
+      <td class="revision">
+      <%= (revision.identifier ? link_to(revision.identifier, :action => 'revision', :id => @project, :rev => revision.identifier) : revision.revision) if revision %></td>
+      <td class="author"><%= h(revision.author) if revision %></td>
+      <td class="line-code"><pre><%= line %></pre></td>
+    </tr>
+    <% line_num += 1 %>
+    <% end %>
+  <tbody>
+</table>
+</div>
+
+<% content_for :header_tags do %>
+<%= stylesheet_link_tag 'scm' %>
+<% end %>

Property changes on: trunk/app/views/repositories/annotate.rhtml
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: trunk/app/views/repositories/changes.rhtml
===================================================================
--- trunk/app/views/repositories/changes.rhtml	(revision 946)
+++ trunk/app/views/repositories/changes.rhtml	(revision 947)
@@ -2,14 +2,17 @@
 
 <h3><%=h @entry.name %></h3>
 
-<% if @repository.supports_cat? %>
 <p>
 <% if @entry.is_text? %>
-<%= link_to l(:button_view), {:action => 'entry', :id => @project, :path => @path, :rev => @rev } %> |
+    <% if @repository.supports_cat? %>
+        <%= link_to l(:button_view), {:action => 'entry', :id => @project, :path => @path, :rev => @rev } %> |
+    <% end %>
+    <% if @repository.supports_annotate? %>
+        <%= link_to l(:button_annotate), {:action => 'annotate', :id => @project, :path => @path, :rev => @rev } %> |
+    <% end %>
 <% end %>
-<%= link_to l(:button_download), {:action => 'entry', :id => @project, :path => @path, :rev => @rev, :format => 'raw' } %>
+<%= link_to(l(:button_download), {:action => 'entry', :id => @project, :path => @path, :rev => @rev, :format => 'raw' }) if @repository.supports_cat? %>
 <%= "(#{number_to_human_size(@entry.size)})" if @entry.size %>
 </p>
-<% end %>
 
 <%= render :partial => 'revisions', :locals => {:project => @project, :path => @path, :revisions => @changesets, :entry => @entry }%>
Index: trunk/app/views/repositories/entry.rhtml
===================================================================
--- trunk/app/views/repositories/entry.rhtml	(revision 946)
+++ trunk/app/views/repositories/entry.rhtml	(revision 947)
@@ -2,11 +2,6 @@
 
 <div class="autoscroll">
 <table class="filecontent CodeRay">
-  <thead>
-    <tr>
-      <th colspan="2" class="filename"><%= @path %></th>
-    </tr>
-  </thead>
   <tbody>
     <% line_num = 1 %>
     <% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %>
Index: trunk/config/routes.rb
===================================================================
--- trunk/config/routes.rb	(revision 946)
+++ trunk/config/routes.rb	(revision 947)
@@ -24,6 +24,7 @@
     omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes'
     omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff'
     omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry'
+    omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate'
   end
   
   # Allow downloading Web Service WSDL as a file with an extension
Index: trunk/lang/bg.yml
===================================================================
--- trunk/lang/bg.yml	(revision 946)
+++ trunk/lang/bg.yml	(revision 947)
@@ -547,3 +547,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/cs.yml
===================================================================
--- trunk/lang/cs.yml	(revision 946)
+++ trunk/lang/cs.yml	(revision 947)
@@ -547,3 +547,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/de.yml
===================================================================
--- trunk/lang/de.yml	(revision 946)
+++ trunk/lang/de.yml	(revision 947)
@@ -547,3 +547,4 @@
 field_time_zone: Zeitzone
 text_caracters_minimum: Muss mindestens %d Zeichen lang sein.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/en.yml
===================================================================
--- trunk/lang/en.yml	(revision 946)
+++ trunk/lang/en.yml	(revision 947)
@@ -489,6 +489,7 @@
 button_rename: Rename
 button_change_password: Change password
 button_copy: Copy
+button_annotate: Annotate
 
 status_active: active
 status_registered: registered
Index: trunk/lang/es.yml
===================================================================
--- trunk/lang/es.yml	(revision 946)
+++ trunk/lang/es.yml	(revision 947)
@@ -550,3 +550,4 @@
 notice_account_pending: "Su cuenta ha sido creada y está pendiende de la aprobación por parte de administrador"
 setting_time_format: Formato de hora
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/fr.yml
===================================================================
--- trunk/lang/fr.yml	(revision 946)
+++ trunk/lang/fr.yml	(revision 947)
@@ -489,6 +489,7 @@
 button_rename: Renommer
 button_change_password: Changer de mot de passe
 button_copy: Copier
+button_annotate: Annoter
 
 status_active: actif
 status_registered: enregistré
Index: trunk/lang/he.yml
===================================================================
--- trunk/lang/he.yml	(revision 946)
+++ trunk/lang/he.yml	(revision 947)
@@ -547,3 +547,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/it.yml
===================================================================
--- trunk/lang/it.yml	(revision 946)
+++ trunk/lang/it.yml	(revision 947)
@@ -547,3 +547,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/ja.yml
===================================================================
--- trunk/lang/ja.yml	(revision 946)
+++ trunk/lang/ja.yml	(revision 947)
@@ -548,3 +548,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/ko.yml
===================================================================
--- trunk/lang/ko.yml	(revision 946)
+++ trunk/lang/ko.yml	(revision 947)
@@ -547,3 +547,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/nl.yml
===================================================================
--- trunk/lang/nl.yml	(revision 946)
+++ trunk/lang/nl.yml	(revision 947)
@@ -548,3 +548,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/pl.yml
===================================================================
--- trunk/lang/pl.yml	(revision 946)
+++ trunk/lang/pl.yml	(revision 947)
@@ -547,3 +547,4 @@
 field_time_zone: Strefa czasowa
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/pt-br.yml
===================================================================
--- trunk/lang/pt-br.yml	(revision 946)
+++ trunk/lang/pt-br.yml	(revision 947)
@@ -547,3 +547,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/pt.yml
===================================================================
--- trunk/lang/pt.yml	(revision 946)
+++ trunk/lang/pt.yml	(revision 947)
@@ -547,3 +547,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/ro.yml
===================================================================
--- trunk/lang/ro.yml	(revision 946)
+++ trunk/lang/ro.yml	(revision 947)
@@ -547,3 +547,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/ru.yml
===================================================================
--- trunk/lang/ru.yml	(revision 946)
+++ trunk/lang/ru.yml	(revision 947)
@@ -547,3 +547,4 @@
 field_time_zone: Часовой пояс
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/sr.yml
===================================================================
--- trunk/lang/sr.yml	(revision 946)
+++ trunk/lang/sr.yml	(revision 947)
@@ -548,3 +548,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/sv.yml
===================================================================
--- trunk/lang/sv.yml	(revision 946)
+++ trunk/lang/sv.yml	(revision 947)
@@ -548,3 +548,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lang/zh.yml
===================================================================
--- trunk/lang/zh.yml	(revision 946)
+++ trunk/lang/zh.yml	(revision 947)
@@ -550,3 +550,4 @@
 field_time_zone: Time zone
 text_caracters_minimum: Must be at least %d characters long.
 setting_bcc_recipients: Blind carbon copy recipients (bcc)
+button_annotate: Annotate
Index: trunk/lib/redmine/scm/adapters/abstract_adapter.rb
===================================================================
--- trunk/lib/redmine/scm/adapters/abstract_adapter.rb	(revision 946)
+++ trunk/lib/redmine/scm/adapters/abstract_adapter.rb	(revision 947)
@@ -38,6 +38,10 @@
         def supports_cat?
           true
         end
+
+        def supports_annotate?
+          respond_to?('annotate')
+        end
         
         def root_url
           @root_url
@@ -76,7 +80,7 @@
         def cat(path, identifier=nil)
           return nil
         end
-
+        
         def with_leading_slash(path)
           path ||= ''
           (path[0,1]!="/") ? "/#{path}" : path
@@ -237,7 +241,7 @@
     
         # Initialize with a Diff file and the type of Diff View
         # The type view must be inline or sbs (side_by_side)
-        def initialize (type="inline")
+        def initialize(type="inline")
           @parsing = false
           @nb_line = 1
           @start = false
@@ -312,7 +316,7 @@
             CGI.escapeHTML(line)
         end
     
-        def parse_line (line, type="inline")
+        def parse_line(line, type="inline")
           if line[0, 1] == "+"
             diff = sbs? type, 'add'
             @before = 'add'
@@ -348,6 +352,28 @@
           end
         end
       end
+    
+      class Annotate
+        attr_reader :lines, :revisions
+        
+        def initialize
+          @lines = []
+          @revisions = []
+        end
+        
+        def add_line(line, revision)
+          @lines << line
+          @revisions << revision
+        end
+        
+        def content
+          content = lines.join("\n")
+        end
+        
+        def empty?
+          lines.empty?
+        end
+      end
     end
   end
 end
Index: trunk/lib/redmine/scm/adapters/cvs_adapter.rb
===================================================================
--- trunk/lib/redmine/scm/adapters/cvs_adapter.rb	(revision 946)
+++ trunk/lib/redmine/scm/adapters/cvs_adapter.rb	(revision 947)
@@ -268,7 +268,25 @@
         rescue Errno::ENOENT => e
           raise CommandFailed    
         end  
-        
+
+        def annotate(path, identifier=nil)
+          identifier = (identifier) ? identifier : "HEAD"
+          logger.debug "<cvs> annotate path:'#{path}',identifier #{identifier}"
+          path_with_project="#{url}#{with_leading_slash(path)}"
+          cmd = "#{CVS_BIN} -d #{root_url} rannotate -r#{identifier} #{path_with_project}"
+          blame = Annotate.new
+          shellout(cmd) do |io|
+            io.each_line do |line|
+              next unless line =~ %r{^([\d\.]+)\s+\(([^\)]+)\s+[^\)]+\):\s(.*)$}
+              blame.add_line($3.rstrip, Revision.new(:revision => $1, :author => $2.strip))
+            end
+          end
+          return nil if $? && $?.exitstatus != 0
+          blame
+        rescue Errno::ENOENT => e
+          raise CommandFailed    
+        end
+         
         private
 
         # convert a date/time into the CVS-format
Index: trunk/lib/redmine/scm/adapters/mercurial_adapter.rb
===================================================================
--- trunk/lib/redmine/scm/adapters/mercurial_adapter.rb	(revision 946)
+++ trunk/lib/redmine/scm/adapters/mercurial_adapter.rb	(revision 947)
@@ -157,6 +157,25 @@
         rescue Errno::ENOENT => e
           raise CommandFailed
         end
+        
+        def annotate(path, identifier=nil)
+          path ||= ''
+          cmd = "#{HG_BIN} -R #{target('')}"
+          cmd << " annotate -n -u"
+          cmd << " -r #{identifier.to_i}" if identifier
+          cmd << " #{target(path)}"
+          blame = Annotate.new
+          shellout(cmd) do |io|
+            io.each_line do |line|
+              next unless line =~ %r{^([^:]+)\s(\d+):(.*)$}
+              blame.add_line($3.rstrip, Revision.new(:identifier => $2.to_i, :author => $1.strip))
+            end
+          end
+          return nil if $? && $?.exitstatus != 0
+          blame
+        rescue Errno::ENOENT => e
+          raise CommandFailed
+        end
       end
     end
   end
Index: trunk/lib/redmine/scm/adapters/subversion_adapter.rb
===================================================================
--- trunk/lib/redmine/scm/adapters/subversion_adapter.rb	(revision 946)
+++ trunk/lib/redmine/scm/adapters/subversion_adapter.rb	(revision 947)
@@ -173,6 +173,23 @@
           raise CommandFailed    
         end
         
+        def annotate(path, identifier=nil)
+          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
+          cmd = "#{SVN_BIN} blame #{target(path)}@#{identifier}"
+          cmd << credentials_string
+          blame = Annotate.new
+          shellout(cmd) do |io|
+            io.each_line do |line|
+              next unless line =~ %r{^\s*(\d+)\s*(\S+)\s(.*)$}
+              blame.add_line($3.rstrip, Revision.new(:identifier => $1.to_i, :author => $2.strip))
+            end
+          end
+          return nil if $? && $?.exitstatus != 0
+          blame
+        rescue Errno::ENOENT => e
+          raise CommandFailed
+        end
+        
         private
         
         def credentials_string
Index: trunk/lib/redmine.rb
===================================================================
--- trunk/lib/redmine.rb	(revision 946)
+++ trunk/lib/redmine.rb	(revision 947)
@@ -76,7 +76,7 @@
     
   map.project_module :repository do |map|
     map.permission :manage_repository, {:repositories => [:edit, :destroy]}, :require => :member
-    map.permission :browse_repository, :repositories => [:show, :browse, :entry, :changes, :diff, :stats, :graph]
+    map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph]
     map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
   end
 
Index: trunk/public/stylesheets/scm.css
===================================================================
--- trunk/public/stylesheets/scm.css	(revision 946)
+++ trunk/public/stylesheets/scm.css	(revision 947)
@@ -2,20 +2,52 @@
 table.filecontent { border: 1px solid #ccc;  border-collapse: collapse; width:98%; }
 table.filecontent th { border: 1px solid #ccc; background-color: #eee; }
 table.filecontent th.filename {	background-color: #ddc;	text-align: left; }
-div.action_M { background: #fd8 }
-div.action_D { background: #f88 }
-div.action_A { background: #bfb }
-
 table.filecontent tr.spacing { border: 1px solid #d7d7d7; }
-
-table.filecontent .line-num {
+table.filecontent th.line-num {
     border: 1px solid #d7d7d7;
 	font-size: 0.8em;
 	text-align: right;
-	width: 3em;
+	width: 2%;
 	padding-right: 3px;
 }
 
+/* 12 different colors for the annonate view */
+table.annotate tr.bloc-0 {background: #FFFFBF;}
+table.annotate tr.bloc-1 {background: #EABFFF;}
+table.annotate tr.bloc-2 {background: #BFFFFF;}
+table.annotate tr.bloc-3 {background: #FFD9BF;}
+table.annotate tr.bloc-4 {background: #E6FFBF;}
+table.annotate tr.bloc-5 {background: #BFCFFF;}
+table.annotate tr.bloc-6 {background: #FFBFEF;}
+table.annotate tr.bloc-7 {background: #FFE6BF;}
+table.annotate tr.bloc-8 {background: #FFE680;}
+table.annotate tr.bloc-9 {background: #AA80FF;}
+table.annotate tr.bloc-10 {background: #FFBFDC;}
+table.annotate tr.bloc-11 {background: #BFE4FF;}
+
+table.annotate td.revision {
+    text-align: center;
+    width: 2%;
+    padding-left: 1em;
+    background: inherit;
+}
+    
+table.annotate td.author {
+    text-align: center;
+    border-right: 1px solid #d7d7d7;
+    white-space: nowrap;
+    padding-left: 1em;
+    padding-right: 1em;
+    width: 3%;
+    background: inherit;
+}
+
+table.annotate td.line-code { background-color: #fafafa; }
+
+div.action_M { background: #fd8 }
+div.action_D { background: #f88 }
+div.action_A { background: #bfb }
+
 /************* Coderay styles *************/
 
 table.CodeRay {
