diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 201845fa573438c3e581db89ed256d8612a9f2f3..bddaa77d87e6567a5bf9244ef5c02170171547f8 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -64,31 +64,26 @@ class RepositoriesController < ApplicationController redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository' end - def show - # check if new revisions have been committed in the repository - @repository.fetch_changesets if Setting.autofetch_changesets? - # root entries - @entries = @repository.entries('', @rev) - # latest changesets - @changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC") - show_error_not_found unless @entries || @changesets.any? - end - - def browse + def show + @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty? + @entries = @repository.entries(@path, @rev) if request.xhr? @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) else show_error_not_found and return unless @entries + @changesets = @repository.latest_changesets(@path, @rev) @properties = @repository.properties(@path, @rev) - render :action => 'browse' + render :action => 'show' end end + + alias_method :browse, :show def changes @entry = @repository.entry(@path, @rev) show_error_not_found and return unless @entry - @changesets = @repository.changesets_for_path(@path, :limit => Setting.repository_log_display_limit.to_i) + @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i) @properties = @repository.properties(@path, @rev) end @@ -135,7 +130,7 @@ class RepositoriesController < ApplicationController end def revision - @changeset = @repository.changesets.find_by_revision(@rev) + @changeset = @repository.changesets.find(:first, :conditions => ["revision LIKE ?", @rev + '%']) raise ChangesetNotFound unless @changeset respond_to do |format| @@ -199,17 +194,14 @@ private render_404 end - REV_PARAM_RE = %r{^[a-f0-9]*$} - def find_repository @project = Project.find(params[:id]) @repository = @project.repository render_404 and return false unless @repository @path = params[:path].join('/') unless params[:path].nil? @path ||= '' - @rev = params[:rev] + @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip @rev_to = params[:rev_to] - raise InvalidRevisionParam unless @rev.to_s.match(REV_PARAM_RE) && @rev.to_s.match(REV_PARAM_RE) rescue ActiveRecord::RecordNotFound render_404 rescue InvalidRevisionParam diff --git a/app/models/repository.rb b/app/models/repository.rb index bf181bfadc418306de8df2a0f4af6b00cdb3062e..860395b5cd2a7a713d9b4aee761d2252b2ee8e8d 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -62,6 +62,18 @@ class Repository < ActiveRecord::Base def entries(path=nil, identifier=nil) scm.entries(path, identifier) end + + def branches + scm.branches + end + + def tags + scm.tags + end + + def default_branch + scm.default_branch + end def properties(path, identifier=nil) scm.properties(path, identifier) @@ -92,11 +104,15 @@ class Repository < ActiveRecord::Base def latest_changeset @latest_changeset ||= changesets.find(:first) end + + def latest_changesets(path,rev,limit=10) + @latest_changesets ||= changesets.find(:all, limit, :order => "committed_on DESC") + end def scan_changesets_for_issue_ids self.changesets.each(&:scan_comment_for_issue_ids) end - + # Returns an array of committers usernames and associated user_id def committers @committers ||= Changeset.connection.select_rows("SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}") diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index f721b938f2dd1d458a15e8fae1594b2461b234c6..b3cdf3643e721ef34ada74bc181d5cf53b0e069b 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -29,43 +29,60 @@ class Repository::Git < Repository 'Git' end + def branches + scm.branches + end + + def tags + scm.tags + end + def changesets_for_path(path, options={}) - Change.find(:all, :include => {:changeset => :user}, - :conditions => ["repository_id = ? AND path = ?", id, path], - :order => "committed_on DESC, #{Changeset.table_name}.revision DESC", - :limit => options[:limit]).collect(&:changeset) + Change.find( + :all, + :include => {:changeset => :user}, + :conditions => ["repository_id = ? AND path = ?", id, path], + :order => "committed_on DESC, #{Changeset.table_name}.revision DESC", + :limit => options[:limit] + ).collect(&:changeset) end + # With SCM's that have a sequential commit numbering, redmine is able to be + # clever and only fetch changesets going forward from the most recent one + # it knows about. However, with git, you never know if people have merged + # commits into the middle of the repository history, so we always have to + # parse the entire log. def fetch_changesets - scm_info = scm.info - if scm_info - # latest revision found in database - db_revision = latest_changeset ? latest_changeset.revision : nil - # latest revision in the repository - scm_revision = scm_info.lastrev.scmid + # Save ourselves an expensive operation if we're already up to date + return if scm.num_revisions == changesets.count + + revisions = scm.revisions('', nil, nil, :all => true) + return if revisions.nil? || revisions.empty? + + # Find revisions that redmine knows about already + existing_revisions = changesets.find(:all).map!{|c| c.scmid} + + # Clean out revisions that are no longer in git + Changeset.delete_all(["scmid NOT IN (?) AND repository_id = (?)", revisions.map{|r| r.scmid}, self.id]) + + # Subtract revisions that redmine already knows about + revisions.reject!{|r| existing_revisions.include?(r.scmid)} + + # Save the remaining ones to the database + revisions.each{|r| r.save(self)} unless revisions.nil? + end + + def latest_changesets(path,rev,limit=10) + revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false) + return [] if revisions.nil? || revisions.empty? - unless changesets.find_by_scmid(scm_revision) - scm.revisions('', db_revision, nil, :reverse => true) do |revision| - if changesets.find_by_scmid(revision.scmid.to_s).nil? - transaction do - changeset = Changeset.create!(:repository => self, - :revision => revision.identifier, - :scmid => revision.scmid, - :committer => revision.author, - :committed_on => revision.time, - :comments => revision.message) - - revision.paths.each do |change| - Change.create!(:changeset => changeset, - :action => change[:action], - :path => change[:path], - :from_path => change[:from_path], - :from_revision => change[:from_revision]) - end - end - end - end - end - end + changesets.find( + :all, + :conditions => [ + "scmid IN (?)", + revisions.map!{|c| c.scmid} + ], + :order => 'committed_on DESC' + ) end end diff --git a/app/views/repositories/_breadcrumbs.rhtml b/app/views/repositories/_breadcrumbs.rhtml new file mode 100644 index 0000000000000000000000000000000000000000..42d11e1a4b96283bfff09c0379acece64fc6746a --- /dev/null +++ b/app/views/repositories/_breadcrumbs.rhtml @@ -0,0 +1,21 @@ +<%= link_to 'root', :action => 'show', :id => @project, :path => '', :rev => @rev %> +<% +dirs = path.split('/') +if 'file' == kind + filename = dirs.pop +end +link_path = '' +dirs.each do |dir| + next if dir.blank? + link_path << '/' unless link_path.empty? + link_path << "#{dir}" + %> + / <%= link_to h(dir), :action => 'show', :id => @project, :path => to_path_param(link_path), :rev => @rev %> +<% end %> +<% if filename %> + / <%= link_to h(filename), :action => 'changes', :id => @project, :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev %> +<% end %> + +<%= "@ #{revision}" if revision %> + +<% html_title(with_leading_slash(path)) -%> diff --git a/app/views/repositories/_dir_list_content.rhtml b/app/views/repositories/_dir_list_content.rhtml index bcffed4a55110c6cb609db31350c9357133f43a4..8b6a067b35f00d468cbf6de82209930eb462dc46 100644 --- a/app/views/repositories/_dir_list_content.rhtml +++ b/app/views/repositories/_dir_list_content.rhtml @@ -4,7 +4,7 @@ <tr id="<%= tr_id %>" class="<%= params[:parent_id] %> entry <%= entry.kind %>"> <td style="padding-left: <%=18 * depth%>px;" class="filename"> <% if entry.is_dir? %> -<span class="expander" onclick="<%= remote_function :url => {:action => 'browse', :id => @project, :path => to_path_param(entry.path), :rev => @rev, :depth => (depth + 1), :parent_id => tr_id}, +<span class="expander" onclick="<%= remote_function :url => {:action => 'show', :id => @project, :path => to_path_param(entry.path), :rev => @rev, :depth => (depth + 1), :parent_id => tr_id}, :method => :get, :update => { :success => tr_id }, :position => :after, @@ -12,7 +12,7 @@ :condition => "scmEntryClick('#{tr_id}')"%>"> </span> <% end %> <%= link_to h(entry.name), - {:action => (entry.is_dir? ? 'browse' : 'changes'), :id => @project, :path => to_path_param(entry.path), :rev => @rev}, + {:action => (entry.is_dir? ? 'show' : 'changes'), :id => @project, :path => to_path_param(entry.path), :rev => @rev}, :class => (entry.is_dir? ? 'icon icon-folder' : "icon icon-file #{Redmine::MimeType.css_class_of(entry.name)}")%> </td> <td class="size"><%= (entry.size ? number_to_human_size(entry.size) : "?") unless entry.is_dir? %></td> diff --git a/app/views/repositories/_navigation.rhtml b/app/views/repositories/_navigation.rhtml index 25a15f496280b239e6e1648371d594e03cc69d40..d1417a61c11222ee6dd52de09b33c2c2f26cc78d 100644 --- a/app/views/repositories/_navigation.rhtml +++ b/app/views/repositories/_navigation.rhtml @@ -1,21 +1,21 @@ -<%= link_to 'root', :action => 'browse', :id => @project, :path => '', :rev => @rev %> -<% -dirs = path.split('/') -if 'file' == kind - filename = dirs.pop -end -link_path = '' -dirs.each do |dir| - next if dir.blank? - link_path << '/' unless link_path.empty? - link_path << "#{dir}" - %> - / <%= link_to h(dir), :action => 'browse', :id => @project, :path => to_path_param(link_path), :rev => @rev %> -<% end %> -<% if filename %> - / <%= link_to h(filename), :action => 'changes', :id => @project, :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev %> +<% content_for :header_tags do %> + <%= javascript_include_tag 'repository_navigation' %> <% end %> -<%= "@ #{revision}" if revision %> +<%= link_to l(:label_statistics), {:action => 'stats', :id => @project}, :class => 'icon icon-stats' %> + +<% form_tag({:action => controller.action_name, :id => @project, :path => @path, :rev => ''}, {:method => :get, :id => 'revision_selector'}) do -%> + <!-- Branches Dropdown --> + <% if !@repository.branches.nil? && @repository.branches.length > 0 -%> + | <%= l(:label_branch) %>: + <%= select_tag :branch, options_for_select([''] + @repository.branches,@rev), :id => 'branch' %> + <% end -%> + + <% if !@repository.tags.nil? && @repository.tags.length > 0 -%> + | <%= l(:label_tag) %>: + <%= select_tag :tag, options_for_select([''] + @repository.tags,@rev), :id => 'tag' %> + <% end -%> -<% html_title(with_leading_slash(path)) -%> + | <%= l(:label_revision) %>: + <%= text_field_tag 'rev', @rev, :size => 8 %> +<% end -%> diff --git a/app/views/repositories/annotate.rhtml b/app/views/repositories/annotate.rhtml index d0fb8cbf9136fc05a6fc5ba3e120cf3415cacd6f..fd4d63f3a4dee9d75327918a3e63362ffac4ec35 100644 --- a/app/views/repositories/annotate.rhtml +++ b/app/views/repositories/annotate.rhtml @@ -1,4 +1,10 @@ -<h2><%= render :partial => 'navigation', :locals => { :path => @path, :kind => 'file', :revision => @rev } %></h2> +<%= call_hook(:view_repositories_show_contextual, { :repository => @repository, :project => @project }) %> + +<div class="contextual"> + <%= render :partial => 'navigation' %> +</div> + +<h2><%= render :partial => 'breadcrumbs', :locals => { :path => @path, :kind => 'file', :revision => @rev } %></h2> <p><%= render :partial => 'link_to_functions' %></p> diff --git a/app/views/repositories/browse.rhtml b/app/views/repositories/browse.rhtml index 3bf320cef9a110809fc766a7e38af77054e45349..fc769aa221c18ca3b782bb7089cc41c8a0dbb9a9 100644 --- a/app/views/repositories/browse.rhtml +++ b/app/views/repositories/browse.rhtml @@ -1,10 +1,8 @@ <div class="contextual"> -<% form_tag({}, :method => :get) do %> -<%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 5 %> -<% end %> +<%= render :partial => 'navigation' %> </div> -<h2><%= render :partial => 'navigation', :locals => { :path => @path, :kind => 'dir', :revision => @rev } %></h2> +<h2><%= render :partial => 'breadcrumbs', :locals => { :path => @path, :kind => 'dir', :revision => @rev } %></h2> <%= render :partial => 'dir_list' %> <%= render_properties(@properties) %> diff --git a/app/views/repositories/changes.rhtml b/app/views/repositories/changes.rhtml index aa359ef4d60e6a855ef5bbf3983cec5a54c2314c..3d4c7a96b31a8cbcf25b27c22bc80dfde4072161 100644 --- a/app/views/repositories/changes.rhtml +++ b/app/views/repositories/changes.rhtml @@ -1,4 +1,12 @@ -<h2><%= render :partial => 'navigation', :locals => { :path => @path, :kind => (@entry ? @entry.kind : nil), :revision => @rev } %></h2> +<%= call_hook(:view_repositories_show_contextual, { :repository => @repository, :project => @project }) %> + +<div class="contextual"> + <%= render :partial => 'navigation' %> +</div> + +<h2> + <%= render :partial => 'breadcrumbs', :locals => { :path => @path, :kind => (@entry ? @entry.kind : nil), :revision => @rev } %> +</h2> <p><%= render :partial => 'link_to_functions' %></p> diff --git a/app/views/repositories/entry.rhtml b/app/views/repositories/entry.rhtml index 12ba9f428c72aedb39c492c382deb7175537ebe6..1e198806db9bf5b0a8a1568a56f6c549cf7b93e0 100644 --- a/app/views/repositories/entry.rhtml +++ b/app/views/repositories/entry.rhtml @@ -1,4 +1,10 @@ -<h2><%= render :partial => 'navigation', :locals => { :path => @path, :kind => 'file', :revision => @rev } %></h2> +<%= call_hook(:view_repositories_show_contextual, { :repository => @repository, :project => @project }) %> + +<div class="contextual"> + <%= render :partial => 'navigation' %> +</div> + +<h2><%= render :partial => 'breadcrumbs', :locals => { :path => @path, :kind => 'file', :revision => @rev } %></h2> <p><%= render :partial => 'link_to_functions' %></p> diff --git a/app/views/repositories/revision.rhtml b/app/views/repositories/revision.rhtml index b60b2a22a49c00067713b9d0b58349bd950547ed..f992f046d6b7233ad9e1ae1be9b8ebeefd67eaf7 100644 --- a/app/views/repositories/revision.rhtml +++ b/app/views/repositories/revision.rhtml @@ -14,7 +14,7 @@ » <% form_tag({:controller => 'repositories', :action => 'revision', :id => @project, :rev => nil}, :method => :get) do %> - <%= text_field_tag 'rev', @rev, :size => 5 %> + <%= text_field_tag 'rev', @rev[0,8], :size => 8 %> <%= submit_tag 'OK', :name => nil %> <% end %> </div> diff --git a/app/views/repositories/revisions.rhtml b/app/views/repositories/revisions.rhtml index c06c204cdad9f217dd47f9dd9a806362b68f7dda..255cb6221f41e60c40d15cda2b4fb9eee3cdb9d1 100644 --- a/app/views/repositories/revisions.rhtml +++ b/app/views/repositories/revisions.rhtml @@ -1,6 +1,6 @@ <div class="contextual"> <% form_tag({:action => 'revision', :id => @project}) do %> -<%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 5 %> +<%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 8 %> <%= submit_tag 'OK' %> <% end %> </div> diff --git a/app/views/repositories/show.rhtml b/app/views/repositories/show.rhtml index a0f7dc33c322bf10e4bb4604fa6038d09b2ab74f..aae6571f04e5701c01c7e3fc1c9759d5d9152739 100644 --- a/app/views/repositories/show.rhtml +++ b/app/views/repositories/show.rhtml @@ -1,15 +1,10 @@ -<div class="contextual"> <%= call_hook(:view_repositories_show_contextual, { :repository => @repository, :project => @project }) %> -<%= link_to l(:label_statistics), {:action => 'stats', :id => @project}, :class => 'icon icon-stats' %> -<% if !@entries.nil? && authorize_for('repositories', 'browse') -%> -<% form_tag({:action => 'browse', :id => @project}, :method => :get) do -%> -| <%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 5 %> -<% end -%> -<% end -%> +<div class="contextual"> + <%= render :partial => 'navigation' %> </div> -<h2><%= l(:label_repository) %> (<%= @repository.scm_name %>)</h2> +<h2><%= render :partial => 'breadcrumbs', :locals => { :path => @path, :kind => 'dir', :revision => @rev } %></h2> <% if !@entries.nil? && authorize_for('repositories', 'browse') %> <%= render :partial => 'dir_list' %> @@ -18,7 +13,7 @@ <% if !@changesets.empty? && authorize_for('repositories', 'revisions') %> <h3><%= l(:label_latest_revision_plural) %></h3> <%= render :partial => 'revisions', :locals => {:project => @project, :path => '', :revisions => @changesets, :entry => nil }%> -<p><%= link_to l(:label_view_revisions), :action => 'revisions', :id => @project %></p> +<p><%= link_to l(:label_view_all_revisions), :action => 'revisions', :id => @project %></p> <% content_for :header_tags do %> <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :action => 'revisions', :id => @project, :page => nil, :key => User.current.rss_key})) %> <% end %> diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 87ed7c037c1b65aee55b7b61a665cd012614d51a..a683f875bd55409d1ab4ef199e6505222bc8b531 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -798,3 +798,6 @@ bg: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/bs.yml b/config/locales/bs.yml index 2f8d9451230283ade73c8f9a214365fe6c127570..d78e61140d6f5b7231fe561b3604299ef66dde81 100644 --- a/config/locales/bs.yml +++ b/config/locales/bs.yml @@ -831,3 +831,6 @@ bs: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 499001dee8a39008aba0ea81071a5b4f4f73a66b..049f734bc6b6a20fbec8938fde05fb362640c334 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -801,3 +801,6 @@ ca: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/cs.yml b/config/locales/cs.yml index 7444da07a49e74bd6c2882ab9dee696dcd88dc06..4e1afa6f131daa112113f2632a71fb3dbc4e5598 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -804,3 +804,6 @@ cs: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/da.yml b/config/locales/da.yml index 99b47599cef6740abb8622c6dcaec85deb42d961..f438805a82cae0638cbd427ad5b11e4ad9abe932 100644 --- a/config/locales/da.yml +++ b/config/locales/da.yml @@ -831,3 +831,6 @@ da: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/de.yml b/config/locales/de.yml index 6969d7a606b6be5b146725fda7998a2621e0b049..14dab4071acdbf33c666e767c6a5f90bf7a6b6fe 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -830,3 +830,6 @@ de: mail_body_wiki_content_updated: "Die Wiki-Seite '{{page}}' wurde von {{author}} aktualisiert." permission_add_project: Erstelle Projekt setting_new_project_user_role_id: Rolle einem Nicht-Administrator zugeordnet, welcher ein Projekt erstellt + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/en.yml b/config/locales/en.yml index 459a34ef404904068e40feefcf69cb2f6f718173..b907a56b43528849e667cf9f1aa3a6d8567c61d6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -543,6 +543,8 @@ en: label_browse: Browse label_modification: "{{count}} change" label_modification_plural: "{{count}} changes" + label_branch: Branch + label_tag: Tag label_revision: Revision label_revision_plural: Revisions label_associated_revisions: Associated revisions @@ -554,6 +556,7 @@ en: label_latest_revision: Latest revision label_latest_revision_plural: Latest revisions label_view_revisions: View revisions + label_view_all_revisions: View all revisions label_max_size: Maximum size label_sort_highest: Move to top label_sort_higher: Move up diff --git a/config/locales/es.yml b/config/locales/es.yml index f0689b86beaeb8ac72cc044962ec729276152300..89e4aaf6bd79ae998508ceb6e871730e399e6fc9 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -851,3 +851,6 @@ es: mail_body_wiki_content_updated: La página wiki '{{page}}' ha sido actualizada por {{author}}. permission_add_project: Crear proyecto setting_new_project_user_role_id: Permiso asignado a un usuario no-administrador para crear proyectos + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/fi.yml b/config/locales/fi.yml index 759af064390e28e3de501be6a79b907002448545..2fa1c4ce7e8a0abde0968e3719814ba89266ecc3 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -841,3 +841,6 @@ fi: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 2e3ca60bb6cac2b07c2e64be0446c3eb24e755a5..9e691bb6edb2dfa093554023a67f9783054c6e50 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -832,4 +832,7 @@ fr: enumeration_doc_categories: Catégories des documents enumeration_activities: Activités (suivi du temps) label_greater_or_equal: ">=" - label_less_or_equal: <= + label_less_or_equal: "<=" + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/gl.yml b/config/locales/gl.yml index 4cc93a5e7392e9bbd8ef38dd5ad158ddfab0d8b2..7f44b8196718e70295d65ba9e34c4ef08cc7f4d2 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -830,3 +830,6 @@ gl: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/he.yml b/config/locales/he.yml index a1846f4de09be914d8a7f2b84be9693f42f8c7a9..94cf716cd2d84c9eca69a4bcfb15e0848bf9688f 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -813,3 +813,6 @@ he: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 824694942928b72772ec02bea0096cdce48ffda3..c204aaad3b5413c0024a2c60962773581361838a 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -836,3 +836,6 @@ mail_body_wiki_content_updated: A '{{page}}' wiki oldalt {{author}} frissÃtette. permission_add_project: Projekt létrehozása setting_new_project_user_role_id: Projekt létrehozási jog nem adminisztrátor felhasználóknak + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/it.yml b/config/locales/it.yml index 2a00166002ce6070f20434b3259535e03fdfb4d7..fa490e7c68c1103306f66955e3376f2d37b3c424 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -816,3 +816,6 @@ it: mail_body_wiki_content_updated: La pagina '{{page}}' wiki è stata aggiornata da{{author}}. permission_add_project: Crea progetto setting_new_project_user_role_id: Ruolo assegnato agli utenti non amministratori che creano un progetto + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/ja.yml b/config/locales/ja.yml index e3f09379f4ffc2747e23c5ca2744a66aa09d1106..1d1c330b2fe3049227414b2cbe09cb349076c947 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -838,3 +838,6 @@ ja: enumeration_issue_priorities: ãƒã‚±ãƒƒãƒˆã®å„ªå…ˆåº¦ enumeration_doc_categories: 文書カテゴリ enumeration_activities: 作æ¥åˆ†é¡ž (時間トラッã‚ング) + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 5dee19a4b4a333cc8cc50be2aa4de01aca5dec80..a69e6af6c64218e17e6c74434f6fb9795ec89f24 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -869,3 +869,6 @@ ko: # by Kihyun Yoon(ddumbugie@gmail.com) # by John Hwang (jhwang@tavon.org),http://github.com/tavon field_issue_to: Related issue + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/lt.yml b/config/locales/lt.yml index 8565425af8ca2335b8e941122e870468a10755f0..49e59720ec4261ac3e77538e73665d6f0143e16b 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -841,3 +841,6 @@ lt: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/nl.yml b/config/locales/nl.yml index e97a39130d381e478a205570011264ef1dd72b74..df95addccc6e69d07764493f6a9fccf9326fe526 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -786,3 +786,6 @@ nl: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/no.yml b/config/locales/no.yml index a32d59a61fa86e9e17606d39c9f251a48a6a8d81..1e449573d37c3024f55752042cc62d3afb66700e 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -803,3 +803,6 @@ mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 3f80f15907295d3084f9f34c4c4ee1df185804b3..016b555298e31106265e9cbec814c64346aefbaa 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -834,3 +834,6 @@ pl: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index bc08ed16b0ab2c067ba1a86fef8f6f3ec30141f1..e308e48103ce939838e3177af54cc4c24a27dc57 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -836,3 +836,6 @@ pt-BR: mail_body_wiki_content_updated: A página wiki '{{page}}' foi atualizada por {{author}}. permission_add_project: Criar projeto setting_new_project_user_role_id: Papel dado a um usuário não administrador que crie um projeto + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/pt.yml b/config/locales/pt.yml index f10f898033048049ea902c5157f2ff0beb964bb8..5bf3dbb0d626d0ce14b65c24ca9c7c1b5a30e803 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -822,3 +822,6 @@ pt: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/ro.yml b/config/locales/ro.yml index 0497b14e1f5e93d5081307c4f6b19200404c292d..d9409b99d03b115ebdd2e10bddcb2286ab382ca5 100644 --- a/config/locales/ro.yml +++ b/config/locales/ro.yml @@ -801,3 +801,6 @@ ro: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 525c3c04f71756d3f3db78c0cd2c456cd02a2105..08373c64b5787a3adde396afc0b5ad2ddcc32ba4 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -928,3 +928,6 @@ ru: mail_body_wiki_content_updated: "{{author}} обновил(а) wiki-Ñтраницу '{{page}}'." permission_add_project: Создание проекта setting_new_project_user_role_id: Роль, Ð½Ð°Ð·Ð½Ð°Ñ‡Ð°ÐµÐ¼Ð°Ñ Ð¿Ð¾Ð»ÑŒÐ·Ð¾Ð²Ð°Ñ‚ÐµÐ»ÑŽ, Ñоздавшему проект + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/sk.yml b/config/locales/sk.yml index a7b73b782816a2d294ccdbb7e9d017bf6e67a634..27a0a32ea476b8c4f94902d5bba997901a778b00 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -802,4 +802,7 @@ sk: label_wiki_content_updated: Wiki stránka aktualizovaná mail_body_wiki_content_updated: Wiki stránka '{{page}}' bola aktualizovaná užÃvateľom {{author}}. setting_repositories_encodings: Kódovanie repozitára - setting_new_project_user_role_id: Rola dána non-admin užÃvateľovi, ktorý vytvorà projekt \ No newline at end of file + setting_new_project_user_role_id: Rola dána non-admin užÃvateľovi, ktorý vytvorà projekt + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 7f01d35a18f90d1c8588edd412ddf2c70d6c0489..6a1f4e273151a8a1baae968dff54505b58988a85 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -800,3 +800,6 @@ sl: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/sr.yml b/config/locales/sr.yml index 8edd6d79fcfb49eaef89af7903a0c87d8cc82f36..5e565a9cafcc3353df7854722ce006baacd06fb2 100644 --- a/config/locales/sr.yml +++ b/config/locales/sr.yml @@ -824,3 +824,6 @@ mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/sv.yml b/config/locales/sv.yml index 648c0d986db1507e8b999ff9afdfa1671781d567..0e75a25e99f45d7938654f9cda68d11cfe181a4b 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -858,3 +858,6 @@ sv: enumeration_issue_priorities: Ärendeprioriteter enumeration_doc_categories: Dokumentkategorier enumeration_activities: Aktiviteter (tidsuppföljning) + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/th.yml b/config/locales/th.yml index 046ca81315c279fd3e8a1a9dce50003a1d7c949b..3eb1a258439a281b51af8f9e277b895e1b9d9081 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -801,3 +801,6 @@ th: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/tr.yml b/config/locales/tr.yml index b830f90c5d9cbedfc9b200f448a11b1da715bae8..d6822490dad3f3a2252665066d02b7ca81ac2408 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -837,3 +837,6 @@ tr: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/uk.yml b/config/locales/uk.yml index 403b42caead1ec6471b334cf086b96edad2f128e..e95ce4048e77fa29635c484298bb1f925d70932a 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -800,3 +800,6 @@ uk: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/vi.yml b/config/locales/vi.yml index dfe7a60f198146367149177727dda4ace8f047d0..210532849c1cadc306c49ddeaf7dc869008d06fb 100644 --- a/config/locales/vi.yml +++ b/config/locales/vi.yml @@ -870,3 +870,6 @@ vi: mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. permission_add_project: Create project setting_new_project_user_role_id: Role given to a non-admin user who creates a project + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index 2b757e587f9a829ae07e5924d59c8090ce0aff92..85100f91348fcbeea1eda7fb187efb4f7ca34f63 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -908,3 +908,6 @@ enumeration_issue_priorities: é …ç›®å„ªå…ˆæ¬Š enumeration_doc_categories: 文件分類 enumeration_activities: 活動 (時間追蹤) + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 31a19b3c60eaeb370e7d7f467181540cccb9d7ca..a25ef9617a8ac702409e533ae1c6266234df4fcc 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -833,3 +833,6 @@ zh: enumeration_issue_priorities: 问题优先级 enumeration_doc_categories: 文档类别 enumeration_activities: 活动(时间跟踪) + label_view_all_revisions: View all revisions + label_tag: Tag + label_branch: Branch diff --git a/config/routes.rb b/config/routes.rb index bfacb1d3a5a2960a13eb0c2e9c25929eab23aa4e..ded3435ba00af0185b54d46d32449326fc9ae4c5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -218,7 +218,7 @@ ActionController::Routing::Routes.draw do |map| repository_views.connect 'projects/:id/repository/revisions/:rev', :action => 'revision' repository_views.connect 'projects/:id/repository/revisions/:rev/diff', :action => 'diff' repository_views.connect 'projects/:id/repository/revisions/:rev/diff.:format', :action => 'diff' - repository_views.connect 'projects/:id/repository/revisions/:rev/:action/*path' + repository_views.connect 'projects/:id/repository/revisions/:rev/:action/*path', :requirements => { :rev => /[a-z0-9\.\-_]+/ } repository_views.connect 'projects/:id/repository/:action/*path' end diff --git a/lib/diff.rb b/lib/diff.rb index 646f91baef14051c7aa60eb6be67c34ba87fe337..f88e7fbb1b9330bf44418ccfb8c73ae695f8e812 100644 --- a/lib/diff.rb +++ b/lib/diff.rb @@ -1,153 +1,155 @@ -class Diff +module RedmineDiff + class Diff - VERSION = 0.3 + VERSION = 0.3 - def Diff.lcs(a, b) - astart = 0 - bstart = 0 - afinish = a.length-1 - bfinish = b.length-1 - mvector = [] - - # First we prune off any common elements at the beginning - while (astart <= afinish && bstart <= afinish && a[astart] == b[bstart]) - mvector[astart] = bstart - astart += 1 - bstart += 1 - end - - # now the end - while (astart <= afinish && bstart <= bfinish && a[afinish] == b[bfinish]) - mvector[afinish] = bfinish - afinish -= 1 - bfinish -= 1 - end + def Diff.lcs(a, b) + astart = 0 + bstart = 0 + afinish = a.length-1 + bfinish = b.length-1 + mvector = [] + + # First we prune off any common elements at the beginning + while (astart <= afinish && bstart <= afinish && a[astart] == b[bstart]) + mvector[astart] = bstart + astart += 1 + bstart += 1 + end + + # now the end + while (astart <= afinish && bstart <= bfinish && a[afinish] == b[bfinish]) + mvector[afinish] = bfinish + afinish -= 1 + bfinish -= 1 + end - bmatches = b.reverse_hash(bstart..bfinish) - thresh = [] - links = [] - - (astart..afinish).each { |aindex| - aelem = a[aindex] - next unless bmatches.has_key? aelem - k = nil - bmatches[aelem].reverse.each { |bindex| - if k && (thresh[k] > bindex) && (thresh[k-1] < bindex) - thresh[k] = bindex - else - k = thresh.replacenextlarger(bindex, k) - end - links[k] = [ (k==0) ? nil : links[k-1], aindex, bindex ] if k + bmatches = b.reverse_hash(bstart..bfinish) + thresh = [] + links = [] + + (astart..afinish).each { |aindex| + aelem = a[aindex] + next unless bmatches.has_key? aelem + k = nil + bmatches[aelem].reverse.each { |bindex| + if k && (thresh[k] > bindex) && (thresh[k-1] < bindex) + thresh[k] = bindex + else + k = thresh.replacenextlarger(bindex, k) + end + links[k] = [ (k==0) ? nil : links[k-1], aindex, bindex ] if k + } } - } - if !thresh.empty? - link = links[thresh.length-1] - while link - mvector[link[1]] = link[2] - link = link[0] + if !thresh.empty? + link = links[thresh.length-1] + while link + mvector[link[1]] = link[2] + link = link[0] + end end - end - return mvector - end - - def makediff(a, b) - mvector = Diff.lcs(a, b) - ai = bi = 0 - while ai < mvector.length - bline = mvector[ai] - if bline - while bi < bline - discardb(bi, b[bi]) - bi += 1 - end - match(ai, bi) - bi += 1 - else - discarda(ai, a[ai]) - end - ai += 1 - end - while ai < a.length - discarda(ai, a[ai]) - ai += 1 + return mvector end - while bi < b.length + + def makediff(a, b) + mvector = Diff.lcs(a, b) + ai = bi = 0 + while ai < mvector.length + bline = mvector[ai] + if bline + while bi < bline discardb(bi, b[bi]) bi += 1 end match(ai, bi) - 1 - end - - def compactdiffs - diffs = [] - @diffs.each { |df| - i = 0 - curdiff = [] - while i < df.length - whot = df[i][0] - s = @isstring ? df[i][2].chr : [df[i][2]] - p = df[i][1] - last = df[i][1] - i += 1 - while df[i] && df[i][0] == whot && df[i][1] == last+1 - s << df[i][2] - last = df[i][1] - i += 1 - end - curdiff.push [whot, p, s] + bi += 1 + else + discarda(ai, a[ai]) + end + ai += 1 end - diffs.push curdiff - } - return diffs - end + while ai < a.length + discarda(ai, a[ai]) + ai += 1 + end + while bi < b.length + discardb(bi, b[bi]) + bi += 1 + end + match(ai, bi) + 1 + end - attr_reader :diffs, :difftype + def compactdiffs + diffs = [] + @diffs.each { |df| + i = 0 + curdiff = [] + while i < df.length + whot = df[i][0] + s = @isstring ? df[i][2].chr : [df[i][2]] + p = df[i][1] + last = df[i][1] + i += 1 + while df[i] && df[i][0] == whot && df[i][1] == last+1 + s << df[i][2] + last = df[i][1] + i += 1 + end + curdiff.push [whot, p, s] + end + diffs.push curdiff + } + return diffs + end - def initialize(diffs_or_a, b = nil, isstring = nil) - if b.nil? - @diffs = diffs_or_a - @isstring = isstring - else - @diffs = [] + attr_reader :diffs, :difftype + + def initialize(diffs_or_a, b = nil, isstring = nil) + if b.nil? + @diffs = diffs_or_a + @isstring = isstring + else + @diffs = [] + @curdiffs = [] + makediff(diffs_or_a, b) + @difftype = diffs_or_a.class + end + end + + def match(ai, bi) + @diffs.push @curdiffs unless @curdiffs.empty? @curdiffs = [] - makediff(diffs_or_a, b) - @difftype = diffs_or_a.class end - end - - def match(ai, bi) - @diffs.push @curdiffs unless @curdiffs.empty? - @curdiffs = [] - end - def discarda(i, elem) - @curdiffs.push ['-', i, elem] - end + def discarda(i, elem) + @curdiffs.push ['-', i, elem] + end - def discardb(i, elem) - @curdiffs.push ['+', i, elem] - end + def discardb(i, elem) + @curdiffs.push ['+', i, elem] + end - def compact - return Diff.new(compactdiffs) - end + def compact + return Diff.new(compactdiffs) + end - def compact! - @diffs = compactdiffs - end + def compact! + @diffs = compactdiffs + end - def inspect - @diffs.inspect - end + def inspect + @diffs.inspect + end + end end module Diffable def diff(b) - Diff.new(self, b) + RedmineDiff::Diff.new(self, b) end # Create a hash that maps elements of the array to arrays of indices @@ -158,9 +160,9 @@ module Diffable range.each { |i| elem = self[i] if revmap.has_key? elem - revmap[elem].push i + revmap[elem].push i else - revmap[elem] = [i] + revmap[elem] = [i] end } return revmap @@ -179,9 +181,9 @@ module Diffable found = self[index] return nil if value == found if value > found - low = index + 1 + low = index + 1 else - high = index + high = index end end @@ -204,25 +206,25 @@ module Diffable bi = 0 diff.diffs.each { |d| d.each { |mod| - case mod[0] - when '-' - while ai < mod[1] - newary << self[ai] - ai += 1 - bi += 1 - end - ai += 1 - when '+' - while bi < mod[1] - newary << self[ai] - ai += 1 - bi += 1 - end - newary << mod[2] - bi += 1 - else - raise "Unknown diff action" - end + case mod[0] + when '-' + while ai < mod[1] + newary << self[ai] + ai += 1 + bi += 1 + end + ai += 1 + when '+' + while bi < mod[1] + newary << self[ai] + ai += 1 + bi += 1 + end + newary << mod[2] + bi += 1 + else + raise "Unknown diff action" + end } } while ai < self.length @@ -243,38 +245,38 @@ class String end =begin -= Diff -(({diff.rb})) - computes the differences between two arrays or -strings. Copyright (C) 2001 Lars Christensen + = Diff + (({diff.rb})) - computes the differences between two arrays or + strings. Copyright (C) 2001 Lars Christensen -== Synopsis + == Synopsis - diff = Diff.new(a, b) - b = a.patch(diff) + diff = Diff.new(a, b) + b = a.patch(diff) -== Class Diff -=== Class Methods ---- Diff.new(a, b) ---- a.diff(b) - Creates a Diff object which represent the differences between - ((|a|)) and ((|b|)). ((|a|)) and ((|b|)) can be either be arrays - of any objects, strings, or object of any class that include - module ((|Diffable|)) + == Class Diff + === Class Methods + --- Diff.new(a, b) + --- a.diff(b) + Creates a Diff object which represent the differences between + ((|a|)) and ((|b|)). ((|a|)) and ((|b|)) can be either be arrays + of any objects, strings, or object of any class that include + module ((|Diffable|)) -== Module Diffable -The module ((|Diffable|)) is intended to be included in any class for -which differences are to be computed. Diffable is included into String -and Array when (({diff.rb})) is (({require}))'d. + == Module Diffable + The module ((|Diffable|)) is intended to be included in any class for + which differences are to be computed. Diffable is included into String + and Array when (({diff.rb})) is (({require}))'d. -Classes including Diffable should implement (({[]})) to get element at -integer indices, (({<<})) to append elements to the object and -(({ClassName#new})) should accept 0 arguments to create a new empty -object. + Classes including Diffable should implement (({[]})) to get element at + integer indices, (({<<})) to append elements to the object and + (({ClassName#new})) should accept 0 arguments to create a new empty + object. -=== Instance Methods ---- Diffable#patch(diff) - Applies the differences from ((|diff|)) to the object ((|obj|)) - and return the result. ((|obj|)) is not changed. ((|obj|)) and - can be either an array or a string, but must match the object - from which the ((|diff|)) was created. + === Instance Methods + --- Diffable#patch(diff) + Applies the differences from ((|diff|)) to the object ((|obj|)) + and return the result. ((|obj|)) is not changed. ((|obj|)) and + can be either an array or a string, but must match the object + from which the ((|diff|)) was created. =end diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb index 7d21f8ebaaf4809b4c0a5350614ea1a2ffe8ab02..a62076b524520749895bc24fbd6783f77384bead 100644 --- a/lib/redmine/scm/adapters/abstract_adapter.rb +++ b/lib/redmine/scm/adapters/abstract_adapter.rb @@ -100,6 +100,18 @@ module Redmine def entries(path=nil, identifier=nil) return nil end + + def branches + return nil + end + + def tags + return nil + end + + def default_branch + return nil + end def properties(path, identifier=nil) return nil @@ -260,6 +272,7 @@ module Redmine class Revision attr_accessor :identifier, :scmid, :name, :author, :time, :message, :paths, :revision, :branch + def initialize(attributes={}) self.identifier = attributes[:identifier] self.scmid = attributes[:scmid] @@ -271,7 +284,25 @@ module Redmine self.revision = attributes[:revision] self.branch = attributes[:branch] end - + + def save(repo) + if repo.changesets.find_by_scmid(scmid.to_s).nil? + changeset = Changeset.create!( + :repository => repo, + :revision => identifier, + :scmid => scmid, + :committer => author, + :committed_on => time, + :comments => message) + + paths.each do |file| + Change.create!( + :changeset => changeset, + :action => file[:action], + :path => file[:path]) + end + end + end end class Annotate diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb index a9e1dda5c01c4f2a9e48590ef99dafd24f7a9543..14e1674b1286caf46688352299cf213648205bd0 100644 --- a/lib/redmine/scm/adapters/git_adapter.rb +++ b/lib/redmine/scm/adapters/git_adapter.rb @@ -21,90 +21,38 @@ module Redmine module Scm module Adapters class GitAdapter < AbstractAdapter - # Git executable name GIT_BIN = "git" - # Get the revision of a particuliar file - def get_rev (rev,path) - - if rev != 'latest' && !rev.nil? - cmd="#{GIT_BIN} --git-dir #{target('')} show --date=iso --pretty=fuller #{shell_quote rev} -- #{shell_quote path}" - else - @branch ||= shellout("#{GIT_BIN} --git-dir #{target('')} branch") { |io| io.grep(/\*/)[0].strip.match(/\* (.*)/)[1] } - cmd="#{GIT_BIN} --git-dir #{target('')} log --date=iso --pretty=fuller -1 #{@branch} -- #{shell_quote path}" + def info + begin + Info.new(:root_url => url, :lastrev => lastrev('',nil)) + rescue + nil end - rev=[] - i=0 - shellout(cmd) do |io| - files=[] - changeset = {} - parsing_descr = 0 #0: not parsing desc or files, 1: parsing desc, 2: parsing files + end + def branches + branches = [] + cmd = "#{GIT_BIN} --git-dir #{target('')} branch" + shellout(cmd) do |io| io.each_line do |line| - if line =~ /^commit ([0-9a-f]{40})$/ - key = "commit" - value = $1 - if (parsing_descr == 1 || parsing_descr == 2) - parsing_descr = 0 - rev = Revision.new({:identifier => changeset[:commit], - :scmid => changeset[:commit], - :author => changeset[:author], - :time => Time.parse(changeset[:date]), - :message => changeset[:description], - :paths => files - }) - changeset = {} - files = [] - end - changeset[:commit] = $1 - elsif (parsing_descr == 0) && line =~ /^(\w+):\s*(.*)$/ - key = $1 - value = $2 - if key == "Author" - changeset[:author] = value - elsif key == "CommitDate" - changeset[:date] = value - end - elsif (parsing_descr == 0) && line.chomp.to_s == "" - parsing_descr = 1 - changeset[:description] = "" - elsif (parsing_descr == 1 || parsing_descr == 2) && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\s+(.+)$/ - parsing_descr = 2 - fileaction = $1 - filepath = $2 - files << {:action => fileaction, :path => filepath} - elsif (parsing_descr == 1) && line.chomp.to_s == "" - parsing_descr = 2 - elsif (parsing_descr == 1) - changeset[:description] << line - end - end - rev = Revision.new({:identifier => changeset[:commit], - :scmid => changeset[:commit], - :author => changeset[:author], - :time => (changeset[:date] ? Time.parse(changeset[:date]) : nil), - :message => changeset[:description], - :paths => files - }) - + branches << line.match('\s*\*?\s*(.*)$')[1] + end end - - get_rev('latest',path) if rev == [] - - return nil if $? && $?.exitstatus != 0 - return rev + branches.sort! end - def info - revs = revisions(url,nil,nil,{:limit => 1}) - if revs && revs.any? - Info.new(:root_url => url, :lastrev => revs.first) - else - nil + def tags + tags = [] + cmd = "#{GIT_BIN} --git-dir #{target('')} tag" + shellout(cmd) do |io| + io.readlines.sort!.map{|t| t.strip} end - rescue Errno::ENOENT => e - return nil + end + + def default_branch + branches.include?('master') ? 'master' : branches.first end def entries(path=nil, identifier=nil) @@ -121,27 +69,63 @@ module Redmine sha = $2 size = $3 name = $4 + full_path = path.empty? ? name : "#{path}/#{name}" entries << Entry.new({:name => name, - :path => (path.empty? ? name : "#{path}/#{name}"), - :kind => ((type == "tree") ? 'dir' : 'file'), - :size => ((type == "tree") ? nil : size), - :lastrev => get_rev(identifier,(path.empty? ? name : "#{path}/#{name}")) - - }) unless entries.detect{|entry| entry.name == name} + :path => full_path, + :kind => (type == "tree") ? 'dir' : 'file', + :size => (type == "tree") ? nil : size, + :lastrev => lastrev(full_path,identifier) + }) unless entries.detect{|entry| entry.name == name} end end end return nil if $? && $?.exitstatus != 0 entries.sort_by_name end - + + def lastrev(path,rev) + return nil if path.nil? + cmd = "#{GIT_BIN} --git-dir #{target('')} log --pretty=fuller --no-merges -n 1 " + cmd << " #{shell_quote rev} " if rev + cmd << "-- #{path} " unless path.empty? + shellout(cmd) do |io| + begin + id = io.gets.split[1] + author = io.gets.match('Author:\s+(.*)$')[1] + 2.times { io.gets } + time = io.gets.match('CommitDate:\s+(.*)$')[1] + + Revision.new({ + :identifier => id, + :scmid => id, + :author => author, + :time => time, + :message => nil, + :paths => nil + }) + rescue NoMethodError => e + logger.error("The revision '#{path}' has a wrong format") + return nil + end + end + end + + def num_revisions + cmd = "#{GIT_BIN} --git-dir #{target('')} log --all --pretty=format:'' | wc -l" + shellout(cmd) {|io| io.gets.chomp.to_i + 1} + end + def revisions(path, identifier_from, identifier_to, options={}) revisions = Revisions.new - cmd = "#{GIT_BIN} --git-dir #{target('')} log --raw --date=iso --pretty=fuller" + + cmd = "#{GIT_BIN} --git-dir #{target('')} log --find-copies-harder --raw --date=iso --pretty=fuller" cmd << " --reverse" if options[:reverse] - cmd << " -n #{options[:limit].to_i} " if (!options.nil?) && options[:limit] + cmd << " --all" if options[:all] + cmd << " -n #{options[:limit]} " if options[:limit] cmd << " #{shell_quote(identifier_from + '..')} " if identifier_from cmd << " #{shell_quote identifier_to} " if identifier_to + cmd << " -- #{path}" if path && !path.empty? + shellout(cmd) do |io| files=[] changeset = {} @@ -154,13 +138,14 @@ module Redmine value = $1 if (parsing_descr == 1 || parsing_descr == 2) parsing_descr = 0 - revision = Revision.new({:identifier => changeset[:commit], - :scmid => changeset[:commit], - :author => changeset[:author], - :time => Time.parse(changeset[:date]), - :message => changeset[:description], - :paths => files - }) + revision = Revision.new({ + :identifier => changeset[:commit], + :scmid => changeset[:commit], + :author => changeset[:author], + :time => Time.parse(changeset[:date]), + :message => changeset[:description], + :paths => files + }) if block_given? yield revision else @@ -182,26 +167,35 @@ module Redmine elsif (parsing_descr == 0) && line.chomp.to_s == "" parsing_descr = 1 changeset[:description] = "" - elsif (parsing_descr == 1 || parsing_descr == 2) && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\s+(.+)$/ + elsif (parsing_descr == 1 || parsing_descr == 2) \ + && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\s+(.+)$/ parsing_descr = 2 fileaction = $1 filepath = $2 files << {:action => fileaction, :path => filepath} + elsif (parsing_descr == 1 || parsing_descr == 2) \ + && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\s+(.+)$/ + parsing_descr = 2 + fileaction = $1 + filepath = $3 + files << {:action => fileaction, :path => filepath} elsif (parsing_descr == 1) && line.chomp.to_s == "" parsing_descr = 2 elsif (parsing_descr == 1) changeset[:description] << line[4..-1] end - end + end if changeset[:commit] - revision = Revision.new({:identifier => changeset[:commit], - :scmid => changeset[:commit], - :author => changeset[:author], - :time => Time.parse(changeset[:date]), - :message => changeset[:description], - :paths => files - }) + revision = Revision.new({ + :identifier => changeset[:commit], + :scmid => changeset[:commit], + :author => changeset[:author], + :time => Time.parse(changeset[:date]), + :message => changeset[:description], + :paths => files + }) + if block_given? yield revision else @@ -213,15 +207,16 @@ module Redmine return nil if $? && $?.exitstatus != 0 revisions end - + def diff(path, identifier_from, identifier_to=nil) path ||= '' - if !identifier_to - identifier_to = nil + + if identifier_to + cmd = "#{GIT_BIN} --git-dir #{target('')} diff #{shell_quote identifier_to} #{shell_quote identifier_from}" + else + cmd = "#{GIT_BIN} --git-dir #{target('')} show #{shell_quote identifier_from}" end - - cmd = "#{GIT_BIN} --git-dir #{target('')} show #{shell_quote identifier_from}" if identifier_to.nil? - cmd = "#{GIT_BIN} --git-dir #{target('')} diff #{shell_quote identifier_to} #{shell_quote identifier_from}" if !identifier_to.nil? + cmd << " -- #{shell_quote path}" unless path.empty? diff = [] shellout(cmd) do |io| @@ -265,6 +260,4 @@ module Redmine end end end - end - diff --git a/public/javascripts/repository_navigation.js b/public/javascripts/repository_navigation.js new file mode 100644 index 0000000000000000000000000000000000000000..a40815f9406150936b5778dba3d622230c999cd6 --- /dev/null +++ b/public/javascripts/repository_navigation.js @@ -0,0 +1,35 @@ +Event.observe(window,'load',function() { + /* + If we're viewing a tag or branch, don't display it in the + revision box + */ + var branch_selected = $('branch') && $('rev').getValue() == $('branch').getValue(); + var tag_selected = $('tag') && $('rev').getValue() == $('tag').getValue(); + if (branch_selected || tag_selected) { + $('rev').setValue(''); + } + + /* + Copy the branch/tag value into the revision box, then disable + the dropdowns before submitting the form + */ + $$('#branch,#tag').each(function(e) { + e.observe('change',function(e) { + $('rev').setValue(e.element().getValue()); + $$('#branch,#tag').invoke('disable'); + e.element().parentNode.submit(); + $$('#branch,#tag').invoke('enable'); + }); + }); + + /* + Disable the branch/tag dropdowns before submitting the revision form + */ + $('rev').observe('keydown', function(e) { + if (e.keyCode == 13) { + $$('#branch,#tag').invoke('disable'); + e.element().parentNode.submit(); + $$('#branch,#tag').invoke('enable'); + } + }); +}) diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 970b3c4374f05538f81872dba19ced2cb39a28d3..02e3870b33b1f60dda40838af3538915a6052cb9 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -181,7 +181,7 @@ div.square { width: .6em; height: .6em; } .contextual {float:right; white-space: nowrap; line-height:1.4em;margin-top:5px; padding-left: 10px; font-size:0.9em;} -.contextual input {font-size:0.9em;} +.contextual input,select {font-size:0.9em;} .message .contextual { margin-top: 0; } .splitcontentleft{float:left; width:49%;} diff --git a/test/fixtures/repositories/git_repository.tar.gz b/test/fixtures/repositories/git_repository.tar.gz index 84de88aa7d08d0f58ba6f07bcc4b876fcaab23a3..48966da30bf58b5d804ee9b51deb0dcce9da4edb 100644 Binary files a/test/fixtures/repositories/git_repository.tar.gz and b/test/fixtures/repositories/git_repository.tar.gz differ diff --git a/test/functional/repositories_bazaar_controller_test.rb b/test/functional/repositories_bazaar_controller_test.rb index b1787a5383f21cb8e154363c7cf47e9c16c65d83..98aa2369ff6bf7ea4bbd3e8ba4c0c3b9ff80238e 100644 --- a/test/functional/repositories_bazaar_controller_test.rb +++ b/test/functional/repositories_bazaar_controller_test.rb @@ -45,9 +45,9 @@ class RepositoriesBazaarControllerTest < Test::Unit::TestCase end def test_browse_root - get :browse, :id => 3 + get :show, :id => 3 assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal 2, assigns(:entries).size assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'} @@ -55,9 +55,9 @@ class RepositoriesBazaarControllerTest < Test::Unit::TestCase end def test_browse_directory - get :browse, :id => 3, :path => ['directory'] + get :show, :id => 3, :path => ['directory'] assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name) entry = assigns(:entries).detect {|e| e.name == 'edit.png'} @@ -67,9 +67,9 @@ class RepositoriesBazaarControllerTest < Test::Unit::TestCase end def test_browse_at_given_revision - get :browse, :id => 3, :path => [], :rev => 3 + get :show, :id => 3, :path => [], :rev => 3 assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'], assigns(:entries).collect(&:name) end @@ -102,7 +102,7 @@ class RepositoriesBazaarControllerTest < Test::Unit::TestCase def test_directory_entry get :entry, :id => 3, :path => ['directory'] assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entry) assert_equal 'directory', assigns(:entry).name end diff --git a/test/functional/repositories_cvs_controller_test.rb b/test/functional/repositories_cvs_controller_test.rb index 2207d6ab6605e3614068dc974d7a1bf4de77c031..c728bf362e8ede24ac07f39e8642c7212f5ea500 100644 --- a/test/functional/repositories_cvs_controller_test.rb +++ b/test/functional/repositories_cvs_controller_test.rb @@ -51,9 +51,9 @@ class RepositoriesCvsControllerTest < Test::Unit::TestCase end def test_browse_root - get :browse, :id => 1 + get :show, :id => 1 assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal 3, assigns(:entries).size @@ -65,9 +65,9 @@ class RepositoriesCvsControllerTest < Test::Unit::TestCase end def test_browse_directory - get :browse, :id => 1, :path => ['images'] + get :show, :id => 1, :path => ['images'] assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name) entry = assigns(:entries).detect {|e| e.name == 'edit.png'} @@ -78,9 +78,9 @@ class RepositoriesCvsControllerTest < Test::Unit::TestCase def test_browse_at_given_revision Project.find(1).repository.fetch_changesets - get :browse, :id => 1, :path => ['images'], :rev => 1 + get :show, :id => 1, :path => ['images'], :rev => 1 assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) end @@ -118,7 +118,7 @@ class RepositoriesCvsControllerTest < Test::Unit::TestCase def test_directory_entry get :entry, :id => 1, :path => ['sources'] assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entry) assert_equal 'sources', assigns(:entry).name end diff --git a/test/functional/repositories_darcs_controller_test.rb b/test/functional/repositories_darcs_controller_test.rb index 8f1c7df98dfd3c4bf2f2907674e773ded848c17d..3f841e9a1f46d4caf3ba8789a2e6f6dca1a07235 100644 --- a/test/functional/repositories_darcs_controller_test.rb +++ b/test/functional/repositories_darcs_controller_test.rb @@ -45,9 +45,9 @@ class RepositoriesDarcsControllerTest < Test::Unit::TestCase end def test_browse_root - get :browse, :id => 3 + get :show, :id => 3 assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal 3, assigns(:entries).size assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} @@ -56,9 +56,9 @@ class RepositoriesDarcsControllerTest < Test::Unit::TestCase end def test_browse_directory - get :browse, :id => 3, :path => ['images'] + get :show, :id => 3, :path => ['images'] assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) entry = assigns(:entries).detect {|e| e.name == 'edit.png'} @@ -69,9 +69,9 @@ class RepositoriesDarcsControllerTest < Test::Unit::TestCase def test_browse_at_given_revision Project.find(3).repository.fetch_changesets - get :browse, :id => 3, :path => ['images'], :rev => 1 + get :show, :id => 3, :path => ['images'], :rev => 1 assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal ['delete.png'], assigns(:entries).collect(&:name) end diff --git a/test/functional/repositories_git_controller_test.rb b/test/functional/repositories_git_controller_test.rb index 7f63ea3a94fa626281c2805c101c516992f739e9..6c2502f5165a334fd8f587efd19dcb86ca884600 100644 --- a/test/functional/repositories_git_controller_test.rb +++ b/test/functional/repositories_git_controller_test.rb @@ -46,22 +46,37 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase end def test_browse_root - get :browse, :id => 3 + get :show, :id => 3 assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) - assert_equal 3, assigns(:entries).size + assert_equal 6, assigns(:entries).size assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} + assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} + assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} + assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} end - + + def test_browse_branch + get :show, :id => 3, :rev => 'test_branch' + assert_response :success + assert_template 'show' + assert_not_nil assigns(:entries) + assert_equal 4, assigns(:entries).size + assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} + assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} + assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} + assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} + end + def test_browse_directory - get :browse, :id => 3, :path => ['images'] + get :show, :id => 3, :path => ['images'] assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) - assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) + assert_equal ['edit.png'], assigns(:entries).collect(&:name) entry = assigns(:entries).detect {|e| e.name == 'edit.png'} assert_not_nil entry assert_equal 'file', entry.kind @@ -69,9 +84,9 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase end def test_browse_at_given_revision - get :browse, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' + get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal ['delete.png'], assigns(:entries).collect(&:name) end @@ -89,7 +104,7 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase assert_template 'entry' # Line 19 assert_tag :tag => 'th', - :content => /10/, + :content => /11/, :attributes => { :class => /line-num/ }, :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } end @@ -104,7 +119,7 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase def test_directory_entry get :entry, :id => 3, :path => ['sources'] assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entry) assert_equal 'sources', assigns(:entry).name end @@ -127,14 +142,14 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase assert_response :success assert_template 'annotate' # Line 23, changeset 2f9c0091 - assert_tag :tag => 'th', :content => /23/, + assert_tag :tag => 'th', :content => /24/, :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } }, :sibling => { :tag => 'td', :content => /jsmith/ }, :sibling => { :tag => 'td', :content => /watcher =/ } end def test_annotate_binary_file - get :annotate, :id => 3, :path => ['images', 'delete.png'] + get :annotate, :id => 3, :path => ['images', 'edit.png'] assert_response 500 assert_tag :tag => 'div', :attributes => { :class => /error/ }, :content => /can not be annotated/ diff --git a/test/functional/repositories_mercurial_controller_test.rb b/test/functional/repositories_mercurial_controller_test.rb index 53cbedd0018af0e755bfaff88a2adee05bae5606..ec2526550a13dec83758e08195baa564fb881a10 100644 --- a/test/functional/repositories_mercurial_controller_test.rb +++ b/test/functional/repositories_mercurial_controller_test.rb @@ -44,10 +44,10 @@ class RepositoriesMercurialControllerTest < Test::Unit::TestCase assert_not_nil assigns(:changesets) end - def test_browse_root - get :browse, :id => 3 + def test_show_root + get :show, :id => 3 assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal 3, assigns(:entries).size assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} @@ -55,10 +55,10 @@ class RepositoriesMercurialControllerTest < Test::Unit::TestCase assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} end - def test_browse_directory - get :browse, :id => 3, :path => ['images'] + def test_show_directory + get :show, :id => 3, :path => ['images'] assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) entry = assigns(:entries).detect {|e| e.name == 'edit.png'} @@ -67,10 +67,10 @@ class RepositoriesMercurialControllerTest < Test::Unit::TestCase assert_equal 'images/edit.png', entry.path end - def test_browse_at_given_revision - get :browse, :id => 3, :path => ['images'], :rev => 0 + def test_show_at_given_revision + get :show, :id => 3, :path => ['images'], :rev => 0 assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal ['delete.png'], assigns(:entries).collect(&:name) end @@ -103,7 +103,7 @@ class RepositoriesMercurialControllerTest < Test::Unit::TestCase def test_directory_entry get :entry, :id => 3, :path => ['sources'] assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entry) assert_equal 'sources', assigns(:entry).name end diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb index e31094e7ba827aecb2663cd0947f0c4859fdf986..ac1438572ed3c00e7dd23164871c4cc9864fb0d1 100644 --- a/test/functional/repositories_subversion_controller_test.rb +++ b/test/functional/repositories_subversion_controller_test.rb @@ -47,18 +47,18 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase end def test_browse_root - get :browse, :id => 1 + get :show, :id => 1 assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} assert_equal 'dir', entry.kind end def test_browse_directory - get :browse, :id => 1, :path => ['subversion_test'] + get :show, :id => 1, :path => ['subversion_test'] assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal ['folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name) entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} @@ -68,9 +68,9 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase end def test_browse_at_given_revision - get :browse, :id => 1, :path => ['subversion_test'], :rev => 4 + get :show, :id => 1, :path => ['subversion_test'], :rev => 4 assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entries) assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name) end @@ -131,7 +131,7 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase def test_directory_entry get :entry, :id => 1, :path => ['subversion_test', 'folder'] assert_response :success - assert_template 'browse' + assert_template 'show' assert_not_nil assigns(:entry) assert_equal 'folder', assigns(:entry).name end diff --git a/test/unit/git_adapter_test.rb b/test/unit/git_adapter_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..50bded06240efd24a63ef3e47bac21a84774d2e5 --- /dev/null +++ b/test/unit/git_adapter_test.rb @@ -0,0 +1,22 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class GitAdapterTest < Test::Unit::TestCase + REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' + + if File.directory?(REPOSITORY_PATH) + def setup + @adapter = Redmine::Scm::Adapters::GitAdapter.new(REPOSITORY_PATH) + end + + def test_branches + assert_equal @adapter.branches, ['master', 'test_branch'] + end + + def test_getting_all_revisions + assert_equal 12, @adapter.revisions('',nil,nil,:all => true).length + end + else + puts "Git test repository NOT FOUND. Skipping unit tests !!!" + def test_fake; assert true end + end +end diff --git a/test/unit/repository_git_test.rb b/test/unit/repository_git_test.rb index bc997b96c87d215f17bb41d8c17a519436af5787..382774305d08d414add416b5d33d16d4252547a4 100644 --- a/test/unit/repository_git_test.rb +++ b/test/unit/repository_git_test.rb @@ -34,8 +34,8 @@ class RepositoryGitTest < Test::Unit::TestCase @repository.fetch_changesets @repository.reload - assert_equal 6, @repository.changesets.count - assert_equal 11, @repository.changes.count + assert_equal 12, @repository.changesets.count + assert_equal 20, @repository.changes.count commit = @repository.changesets.find(:first, :order => 'committed_on ASC') assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments @@ -57,10 +57,10 @@ class RepositoryGitTest < Test::Unit::TestCase # Remove the 3 latest changesets @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy) @repository.reload - assert_equal 3, @repository.changesets.count + assert_equal 9, @repository.changesets.count @repository.fetch_changesets - assert_equal 6, @repository.changesets.count + assert_equal 12, @repository.changesets.count end else puts "Git test repository NOT FOUND. Skipping unit tests !!!"