Project

General

Profile

Feature #5386 » 5386-branches-in-associated-revisions-2.3-stable.diff

Patch to add list of branches to associated revisions for redmine 2.3 - Evzen Sindelar, 2013-05-23 11:01

View differences:

app/helpers/application_helper.rb Wed May 22 23:25:08 2013 +0200
113 113
      )
114 114
  end
115 115

  
116
  # Generates a link to a SCM repository
117
  def link_to_repository(rev, project, options={})
118
    text = options.delete(:text) || rev
119
    link_to(text, {:controller => 'repositories', :action => 'show', :id => project, :rev => rev},
120
            :title => rev)
121
  end
122

  
116 123
  # Generates a link to a message
117 124
  def link_to_message(message, options={}, html_options = nil)
118 125
    link_to(
app/models/repository/git.rb Wed May 22 23:25:08 2013 +0200
209 209
        # There is no search in the db for this revision, because above we ensured,
210 210
        # that it's not in the db.
211 211
        save_revision(rev)
212
        save_revision_branches(rev)
212 213
      end
213 214
    end
214 215
    h["heads"] = repo_heads.dup
......
217 218
  end
218 219
  private :save_revisions
219 220

  
221
  def save_revision_branches(rev)
222
    db_rev = find_changeset_by_name(rev.scmid)
223
    unless db_rev.nil?
224
      branches = scm.revision_branches(rev.scmid)
225
      unless branches.nil?
226
        db_rev.branches = branches.join(',')
227
        db_rev.save
228
      end
229
    end
230
  end
231
  private :save_revision_branches
232

  
220 233
  def save_revision(rev)
221 234
    parents = (rev.parents || []).collect{|rp| find_changeset_by_name(rp)}.compact
222 235
    changeset = Changeset.create(
app/views/issues/_changesets.html.erb Wed May 22 23:25:08 2013 +0200
1 1
<% changesets.each do |changeset| %>
2 2
    <div class="changeset <%= cycle('odd', 'even') %>">
3 3
    <p><%= link_to_revision(changeset, changeset.repository,
4
                            :text => "#{l(:label_revision)} #{changeset.format_identifier}") %><br />
4
                            :text => "#{l(:label_revision)} #{changeset.format_identifier}") %>
5
        <% if changeset.branches? %>
6
            <span style="float: right;">
7
            <%== changeset.branches.split(',').collect{ |branch|
8
            changeset.repository.branches.include?(branch) ? 
9
              link_to_repository(branch, changeset.project, :text => branch) : nil }.compact.join(' / ') %>
10
            </span>
11
        <% end %>
12
        <br />
13

  
5 14
        <span class="author"><%= authoring(changeset.committed_on, changeset.author) %></span></p>
6 15
    <div class="wiki">
7 16
        <%= textilizable(changeset, :comments) %>
db/migrate/20111012193800_add_changesets_branches.rb Wed May 22 23:25:08 2013 +0200
1
class AddChangesetsBranches < ActiveRecord::Migration
2
  def self.up
3
    add_column :changesets, :branches, :string, :limit => nil, :default => nil
4
  end
5

  
6
  def self.down
7
    remove_column :changesets, :branches
8
  end
9
end
lib/redmine/scm/adapters/git_adapter.rb Wed May 22 23:25:08 2013 +0200
311 311
          end
312 312
        end
313 313

  
314
        def revision_branches(identifier)
315
          cmd_args = %w|branch --contains|
316
          cmd_args << identifier
317
          branches = []
318
          git_cmd(cmd_args) do |io|
319
            io.each_line do |line|
320
              branches << line.match('\s*\*?\s*(.*)$')[1]
321
            end
322
          end
323
          branches.sort!
324
        rescue ScmCommandAborted
325
          nil
326
        end
327

  
314 328
        def diff(path, identifier_from, identifier_to=nil)
315 329
          path ||= ''
316 330
          cmd_args = []
(5-5/11)