From 7c105ec9e93b73f5c11f2d5cc240e2b15344ec98 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 10 Jun 2012 18:32:09 +0000 Subject: [PATCH] Adds a method to load changesets for repository entries. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9805 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/repository.rb | 14 +++++++++++++- app/models/repository/bazaar.rb | 2 ++ app/models/repository/cvs.rb | 1 + app/models/repository/darcs.rb | 1 + app/models/repository/filesystem.rb | 4 ---- app/models/repository/git.rb | 6 +++--- app/views/repositories/_dir_list_content.html.erb | 7 +++---- lib/redmine/scm/adapters/abstract_adapter.rb | 3 ++- 8 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 592729d22..1f8820868 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -167,7 +167,9 @@ class Repository < ActiveRecord::Base end def entries(path=nil, identifier=nil) - scm.entries(path, identifier) + entries = scm.entries(path, identifier) + load_entries_changesets(entries) + entries end def branches @@ -380,6 +382,16 @@ class Repository < ActiveRecord::Base end end + def load_entries_changesets(entries) + if entries + entries.each do |entry| + if entry.lastrev && entry.lastrev.identifier + entry.changeset = find_changeset_by_name(entry.lastrev.identifier) + end + end + end + end + private # Deletes repository data diff --git a/app/models/repository/bazaar.rb b/app/models/repository/bazaar.rb index 441b4b739..649bb4722 100644 --- a/app/models/repository/bazaar.rb +++ b/app/models/repository/bazaar.rb @@ -63,6 +63,8 @@ class Repository::Bazaar < Repository end end end + load_entries_changesets(entries) + entries end def fetch_changesets diff --git a/app/models/repository/cvs.rb b/app/models/repository/cvs.rb index 1ad7fb65d..ebfceb6ab 100644 --- a/app/models/repository/cvs.rb +++ b/app/models/repository/cvs.rb @@ -66,6 +66,7 @@ class Repository::Cvs < Repository end end end + load_entries_changesets(entries) entries end diff --git a/app/models/repository/darcs.rb b/app/models/repository/darcs.rb index 18eb3a2f7..995a65597 100644 --- a/app/models/repository/darcs.rb +++ b/app/models/repository/darcs.rb @@ -66,6 +66,7 @@ class Repository::Darcs < Repository end end end + load_entries_changesets(entries) entries end diff --git a/app/models/repository/filesystem.rb b/app/models/repository/filesystem.rb index c0b6ec44f..e93009045 100644 --- a/app/models/repository/filesystem.rb +++ b/app/models/repository/filesystem.rb @@ -44,10 +44,6 @@ class Repository::Filesystem < Repository false end - def entries(path=nil, identifier=nil) - scm.entries(path, identifier) - end - def fetch_changesets nil end diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index 43c826562..a9a666c28 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -94,9 +94,9 @@ class Repository::Git < Repository end def entries(path=nil, identifier=nil) - scm.entries(path, - identifier, - options = {:report_last_commit => extra_report_last_commit}) + entries = scm.entries(path, identifier, :report_last_commit => extra_report_last_commit) + load_entries_changesets(entries) + entries end # With SCMs that have a sequential commit numbering, diff --git a/app/views/repositories/_dir_list_content.html.erb b/app/views/repositories/_dir_list_content.html.erb index 779cb7923..9cca38fe5 100644 --- a/app/views/repositories/_dir_list_content.html.erb +++ b/app/views/repositories/_dir_list_content.html.erb @@ -29,12 +29,11 @@ :class => (entry.is_dir? ? 'icon icon-folder' : "icon icon-file #{Redmine::MimeType.css_class_of(ent_name)}")%> <%= (entry.size ? number_to_human_size(entry.size) : "?") unless entry.is_dir? %> -<% changeset = @repository.find_changeset_by_name(entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %> <% if @repository.report_last_commit %> -<%= link_to_revision(changeset, @repository) if changeset %> +<%= link_to_revision(entry.changeset, @repository) if entry.changeset %> <%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %> -<%= changeset.nil? ? h(Redmine::CodesetUtil.replace_invalid_utf8(entry.lastrev.author.to_s.split('<').first)) : h(changeset.author) if entry.lastrev %> -<%=h truncate(changeset.comments, :length => 50) unless changeset.nil? %> +<%= entry.changeset.nil? ? h(Redmine::CodesetUtil.replace_invalid_utf8(entry.lastrev.author.to_s.split('<').first)) : h(entry.changeset.author) if entry.lastrev %> +<%=h truncate(entry.changeset.comments, :length => 50) if entry.changeset %> <% end %> <% end %> diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb index d487a0f30..345aeba20 100644 --- a/lib/redmine/scm/adapters/abstract_adapter.rb +++ b/lib/redmine/scm/adapters/abstract_adapter.rb @@ -301,7 +301,8 @@ module Redmine end class Entry - attr_accessor :name, :path, :kind, :size, :lastrev + attr_accessor :name, :path, :kind, :size, :lastrev, :changeset + def initialize(attributes={}) self.name = attributes[:name] if attributes[:name] self.path = attributes[:path] if attributes[:path]