0001-Multiple-SCM-per-Project.patch

yusuke kokubo, 2011-01-06 09:08

Download (16.3 KB)

View differences:

app/controllers/repositories_controller.rb
35 35
  rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
36 36
  
37 37
  def edit
38
    rid = params[:rid] ? params[:rid].to_i : 0
38 39
    @repository = @project.repository
39 40
    if !@repository
40
      @repository = Repository.factory(params[:repository_scm])
41
      @repository.project = @project if @repository
41
      @repository[rid] = Repository.factory(params[:repository_scm])
42
      @repository[rid].project = @project if @repository[rid]
42 43
    end
43 44
    if request.post? && @repository
44 45
      @repository.attributes = params[:repository]
......
46 47
    end
47 48
    render(:update) do |page|
48 49
      page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'
49
      if @repository && !@project.repository
50
      if @repository && !@project.repository[rid]
50 51
        @project.reload #needed to reload association
51 52
        page.replace_html "main-menu", render_main_menu(@project)
52 53
      end
......
205 206

  
206 207
  def find_repository
207 208
    @project = Project.find(params[:id])
208
    @repository = @project.repository
209
    rid = params[:rid] ? params[:rid].to_i : 0
210
    @repository = @project.repository[rid]
209 211
    (render_404; return false) unless @repository
210 212
    @path = params[:path].join('/') unless params[:path].nil?
211 213
    @path ||= ''
app/helpers/application_helper.rb
106 106
    text = options.delete(:text) || format_revision(revision)
107 107
    rev = revision.respond_to?(:identifier) ? revision.identifier : revision
108 108

  
109
    link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev},
109
    link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev, :rid => params[:rid]},
110 110
            :title => l(:label_revision_id, format_revision(revision)))
111 111
  end
112 112

  
app/helpers/repositories_helper.rb
91 91
                             :action => 'show',
92 92
                             :id => @project,
93 93
                             :path => path_param,
94
                             :rev => @changeset.identifier)
94
                             :rev => @changeset.identifier,
95
                             :rid => params[:rid])
95 96
        output << "<li class='#{style}'>#{text}</li>"
96 97
        output << render_changes_tree(s)
97 98
      elsif c = tree[file][:c]
......
101 102
                             :action => 'entry',
102 103
                             :id => @project,
103 104
                             :path => path_param,
104
                             :rev => @changeset.identifier) unless c.action == 'D'
105
                             :rev => @changeset.identifier,
106
                             :rid => params[:rid]) unless c.action == 'D'
105 107
        text << " - #{c.revision}" unless c.revision.blank?
106 108
        text << ' (' + link_to('diff', :controller => 'repositories',
107 109
                                       :action => 'diff',
108 110
                                       :id => @project,
109 111
                                       :path => path_param,
110
                                       :rev => @changeset.identifier) + ') ' if c.action == 'M'
112
                                       :rev => @changeset.identifier,
113
                                       :rid => params[:rid]) + ') ' if c.action == 'M'
111 114
        text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank?
112 115
        output << "<li class='#{style}'>#{text}</li>"
113 116
      end
......
140 143
    send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags'
141 144
  end
142 145
  
143
  def scm_select_tag(repository)
146
  def scm_select_tag(repository, rid)
144 147
    scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
145 148
    Redmine::Scm::Base.all.each do |scm|
146 149
      scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm)
......
149 152
    select_tag('repository_scm', 
150 153
               options_for_select(scm_options, repository.class.name.demodulize),
151 154
               :disabled => (repository && !repository.new_record?),
152
               :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)")
155
               :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project, :rid => rid }, :method => :get, :with => "Form.serialize(this.form)")
153 156
               )
154 157
  end
155 158
  
app/models/changeset.rb
175 175
                  :from_revision => change[:from_revision])
176 176
  end
177 177
  
178
  def rid
179
    project.repository.each_with_index do |r, i|
180
      return i if r.id == repository.id
181
    end
182
    -1
183
  end
184
  
178 185
  private
179 186

  
180 187
  # Finds an issue that can be referenced by the commit message
app/models/project.rb
46 46
  has_many :news, :dependent => :delete_all, :include => :author
47 47
  has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
48 48
  has_many :boards, :dependent => :destroy, :order => "position ASC"
49
  has_one :repository, :dependent => :destroy
49
  has_many :repository, :dependent => :destroy
50 50
  has_many :changesets, :through => :repository
51 51
  has_one :wiki, :dependent => :destroy
52 52
  # Custom field for the project issues
app/views/issues/_changesets.rhtml
1 1
<% changesets.each do |changeset| %>
2 2
    <div class="changeset <%= cycle('odd', 'even') %>">
3 3
    <p><%= link_to("#{l(:label_revision)} #{changeset.revision}",
4
                :controller => 'repositories', :action => 'revision', :id => changeset.project, :rev => changeset.revision) %><br />
4
                :controller => 'repositories', :action => 'revision', :id => changeset.project, :rev => changeset.revision, :rid => changeset.rid) %><br />
5 5
        <span class="author"><%= authoring(changeset.committed_on, changeset.author) %></span></p>
6 6
    <div class="changeset-changes">
7 7
        <%= textilizable(changeset, :comments) %>
app/views/projects/settings/_repository.rhtml
1
<% remote_form_for :repository, @repository, 
2
                   :url => { :controller => 'repositories', :action => 'edit', :id => @project },
1
<% @repository.each_with_index do |r, rid| %>
2

  
3
<% remote_form_for :repository, r, r,
4
                   :url => { :controller => 'repositories', :action => 'edit', :id => @project, :rid => rid },
3 5
                   :builder => TabularFormBuilder,
4 6
                   :lang => current_language do |f| %>
5 7

  
6
<%= error_messages_for 'repository' %>
8
<%= error_messages_for 'r' %>
7 9

  
8 10
<div class="box tabular">
9
<p><%= label_tag('repository_scm', l(:label_scm)) %><%= scm_select_tag(@repository) %></p>
10
<%= repository_field_tags(f, @repository) if @repository %>
11
<p><%= label_tag('repository_scm', l(:label_scm)) %><%= scm_select_tag(r, rid) %></p>
12
<%= repository_field_tags(f, r) if r %>
11 13
</div>
12 14

  
13 15
<div class="contextual">
14
<% if @repository && !@repository.new_record? %>
15
<%= link_to(l(:label_user_plural), {:controller => 'repositories', :action => 'committers', :id => @project}, :class => 'icon icon-user') %>
16
<%= link_to(l(:button_delete), {:controller => 'repositories', :action => 'destroy', :id => @project},
16
<% if @repository[0] && !r.new_record? %>
17
<%= link_to(l(:label_user_plural), {:controller => 'repositories', :action => 'committers', :id => @project, :rid => rid}, :class => 'icon icon-user') %>
18
<%= link_to(l(:button_delete), {:controller => 'repositories', :action => 'destroy', :id => @project, :rid => rid},
17 19
            :confirm => l(:text_are_you_sure),
18 20
            :method => :post,
19 21
            :class => 'icon icon-del') %>
20 22
<% end %>
21 23
</div>
22 24

  
23
<%= submit_tag((@repository.nil? || @repository.new_record?) ? l(:button_create) : l(:button_save), :disabled => @repository.nil?) %>
25
<%= submit_tag((r.nil? || r.new_record?) ? l(:button_create) : l(:button_save), :disabled => r.nil?) %>
26
<% end %>
27
<% end %>
28

  
29
<% rid = @repository.size
30
  remote_form_for :repository, @repository[rid],
31
                  :url => { :controller => 'repositories', :action => 'edit', :id => @project, :rid => rid },
32
                  :builder => TabularFormBuilder,
33
                  :lang => current_language do |f| %>
34
<div class="box tabular">
35
<p><%= label_tag('repository_scm', l(:label_scm)) %><%= scm_select_tag(@repository[rid], rid) %></p>
36
<%= repository_field_tags(f, @repository[rid]) if @repository[rid] %>
37
</div>
38
<%= submit_tag((@repository[rid].nil? || @repository[rid].new_record?) ? l(:button_create) : l(:button_save), :disabled => @repository[rid].nil?) %>
24 39
<% end %>
app/views/repositories/_breadcrumbs.rhtml
1
<%= link_to 'root', :action => 'show', :id => @project, :path => '', :rev => @rev %>
1
<% if params[:rid] %>
2
(<%= @project.repository[params[:rid].to_i].url %>)
3
<% end %>
4
<%= link_to 'root', :action => 'show', :id => @project, :path => '', :rev => @rev , :rid => params[:rid]%>
2 5
<% 
3 6
dirs = path.split('/')
4 7
if 'file' == kind
......
10 13
    link_path << '/' unless link_path.empty?
11 14
    link_path << "#{dir}" 
12 15
    %>
13
    / <%= link_to h(dir), :action => 'show', :id => @project, :path => to_path_param(link_path), :rev => @rev %>
16
    / <%= link_to h(dir), :action => 'show', :id => @project, :path => to_path_param(link_path), :rev => @rev, :rid => params[:rid] %>
14 17
<% end %>
15 18
<% if filename %>
16
    / <%= link_to h(filename), :action => 'changes', :id => @project, :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev %>
19
    / <%= link_to h(filename), :action => 'changes', :id => @project, :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev , :rid => params[:rid]%>
17 20
<% end %>
18 21

  
19 22
<%= "@ #{h revision}" if revision %>
app/views/repositories/_dir_list_content.rhtml
4 4
<tr id="<%= tr_id %>" class="<%= h params[:parent_id] %> entry <%= entry.kind %>">
5 5
<td style="padding-left: <%=18 * depth%>px;" class="filename">
6 6
<% if entry.is_dir? %>
7
<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},
7
<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, :rid => params[:rid]},
8 8
									:method => :get,
9 9
                  :update => { :success => tr_id },
10 10
                  :position => :after,
......
12 12
                  :condition => "scmEntryClick('#{tr_id}')"%>">&nbsp</span>
13 13
<% end %>
14 14
<%=  link_to h(entry.name),
15
          {:action => (entry.is_dir? ? 'show' : 'changes'), :id => @project, :path => to_path_param(entry.path), :rev => @rev},
15
          {:action => (entry.is_dir? ? 'show' : 'changes'), :id => @project, :path => to_path_param(entry.path), :rev => @rev, :rid => params[:rid]},
16 16
          :class => (entry.is_dir? ? 'icon icon-folder' : "icon icon-file #{Redmine::MimeType.css_class_of(entry.name)}")%>
17 17
</td>
18 18
<td class="size"><%= (entry.size ? number_to_human_size(entry.size) : "?") unless entry.is_dir? %></td>
19
<% changeset = @project.repository.changesets.find_by_revision(entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %>
19
<% changeset = @project.repository[params[:rid].to_i].changesets.find_by_revision(entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %>
20 20
<td class="revision"><%= link_to_revision(changeset, @project) if changeset %></td>
21 21
<td class="age"><%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %></td>
22 22
<td class="author"><%= changeset.nil? ? h(entry.lastrev.author.to_s.split('<').first) : changeset.author if entry.lastrev %></td>
app/views/repositories/_navigation.rhtml
16 16
    <%= select_tag :tag, options_for_select([''] + @repository.tags,@rev), :id => 'tag' %>
17 17
  <% end -%>
18 18

  
19
  <%= hidden_field_tag :rid, params[:rid] %>
20

  
19 21
  | <%= l(:label_revision) %>: 
20 22
  <%= text_field_tag 'rev', @rev, :size => 8 %>
21 23
<% end -%>
app/views/repositories/show.rhtml
4 4
  <%= render :partial => 'navigation' %>
5 5
</div>
6 6

  
7
<ul>
8
<% @project.repository.each_with_index do |r, i| %>
9
 <li><%= link_to r.url, :rid => i %></li>
10
<% end %>
11
</ul>
12

  
7 13
<h2><%= render :partial => 'breadcrumbs', :locals => { :path => @path, :kind => 'dir', :revision => @rev } %></h2>
8 14

  
9 15
<% if !@entries.nil? && authorize_for('repositories', 'browse') %>
lib/redmine.rb
201 201
              :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
202 202
  menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id
203 203
  menu.push :repository, { :controller => 'repositories', :action => 'show' },
204
              :if => Proc.new { |p| p.repository && !p.repository.new_record? }
204
              :if => Proc.new { |p| p.repository && p.repository[0] && !p.repository[0].new_record? }
205 205
  menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
206 206
end
207 207

  
208
-