initial commit
[gitredmine.git] / git_edge_latest_patch.diff
blobd0f4af18888e1a9e3a8afb04b88f4cba3173bfdf
1 Index: app/helpers/repositories_helper.rb
2 ===================================================================
3 --- app/helpers/repositories_helper.rb (revision 887)
4 +++ app/helpers/repositories_helper.rb (working copy)
5 @@ -73,6 +73,10 @@
6 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
7 end
9 + def git_field_tags(form, repository)
10 + content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
11 + end
13 def cvs_field_tags(form, repository)
14 content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
15 content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
16 Index: app/models/repository/subversion.rb
17 ===================================================================
18 --- app/models/repository/subversion.rb (revision 887)
19 +++ app/models/repository/subversion.rb (working copy)
20 @@ -42,7 +42,7 @@
21 db_revision = latest_changeset ? latest_changeset.revision : 0
22 # latest revision in the repository
23 scm_revision = scm_info.lastrev.identifier.to_i
24 - if db_revision < scm_revision
25 + if db_revision.to_i < scm_revision
26 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
27 identifier_from = db_revision + 1
28 while (identifier_from <= scm_revision)
29 Index: app/models/repository/git.rb
30 ===================================================================
31 --- app/models/repository/git.rb (revision 0)
32 +++ app/models/repository/git.rb (revision 0)
33 @@ -0,0 +1,90 @@
34 +# redMine - project management software
35 +# Copyright (C) 2006-2007 Jean-Philippe Lang
36 +# Copyright (C) 2007 Patrick Aljord patcito@Ĺ‹mail.com
37 +# This program is free software; you can redistribute it and/or
38 +# modify it under the terms of the GNU General Public License
39 +# as published by the Free Software Foundation; either version 2
40 +# of the License, or (at your option) any later version.
41 +#
42 +# This program is distributed in the hope that it will be useful,
43 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
44 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 +# GNU General Public License for more details.
46 +#
47 +# You should have received a copy of the GNU General Public License
48 +# along with this program; if not, write to the Free Software
49 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
51 +require 'redmine/scm/adapters/git_adapter'
53 +class Repository::Git < Repository
54 + attr_protected :root_url
55 + validates_presence_of :url
57 + def scm_adapter
58 + Redmine::Scm::Adapters::GitAdapter
59 + end
61 + def self.scm_name
62 + 'Git'
63 + end
65 + def entries(path=nil, identifier=nil)
66 + entries=scm.entries(path, identifier)
67 + if entries
68 + entries.each do |entry|
69 + next unless entry.is_file?
70 + # Search the DB for the entry's last change
71 + change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC")
72 + if change
73 + entry.lastrev.identifier = change.changeset.revision
74 + entry.lastrev.name = change.changeset.revision
75 + entry.lastrev.author = change.changeset.committer
76 + entry.lastrev.revision = change.revision
77 + end
78 + end
79 + end
80 + entries
81 + end
83 + def changesets_for_path(path)
84 + path = "#{path}" unless path.starts_with?('/')
85 + Change.find(:all, :include => :changeset,
86 + :conditions => ["repository_id = ? AND path = ?", id, path],
87 + :order => "committed_on DESC, #{Changeset.table_name}.revision DESC").collect(&:changeset)
88 + end
90 + def fetch_changesets
91 + scm_info = scm.info
93 + if scm_info
94 + # latest revision found in database
95 + db_revision = latest_changeset ? latest_changeset.revision : nil
96 + # latest revision in the repository
97 + scm_revision = scm_info.lastrev.identifier
99 + unless changesets.find_by_revision(scm_revision)
101 + revisions = scm.revisions('', db_revision, nil)
102 + transaction do
103 + revisions.reverse_each do |revision|
104 + changeset = Changeset.create(:repository => self,
105 + :revision => revision.identifier,
106 + :scmid => revision.scmid,
107 + :committer => revision.author,
108 + :committed_on => revision.time,
109 + :comments => revision.message)
111 + revision.paths.each do |change|
112 + Change.create(:changeset => changeset,
113 + :action => change[:action],
114 + :path => change[:path],
115 + :from_path => change[:from_path],
116 + :from_revision => change[:from_revision])
117 + end
118 + end
119 + end
120 + end
121 + end
122 + end
123 +end
124 Index: app/models/changeset.rb
125 ===================================================================
126 --- app/models/changeset.rb (revision 887)
127 +++ app/models/changeset.rb (working copy)
128 @@ -32,7 +32,7 @@
129 :date_column => 'committed_on'
131 validates_presence_of :repository_id, :revision, :committed_on, :commit_date
132 - validates_numericality_of :revision, :only_integer => true
133 +# validates_numericality_of :revision, :only_integer => true
134 validates_uniqueness_of :revision, :scope => :repository_id
135 validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
137 Index: app/controllers/repositories_controller.rb
138 ===================================================================
139 --- app/controllers/repositories_controller.rb (revision 887)
140 +++ app/controllers/repositories_controller.rb (working copy)
141 @@ -105,7 +105,7 @@
144 def diff
145 - @rev_to = params[:rev_to] ? params[:rev_to].to_i : (@rev - 1)
146 + get_rev_to
147 @diff_type = ('sbs' == params[:type]) ? 'sbs' : 'inline'
149 @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
150 @@ -147,11 +147,16 @@
151 render_404 and return false unless @repository
152 @path = params[:path].join('/') unless params[:path].nil?
153 @path ||= ''
154 - @rev = params[:rev].to_i if params[:rev]
155 + @rev = params[:rev] if params[:rev]
156 rescue ActiveRecord::RecordNotFound
157 render_404
160 + def get_rev_to
161 + @rev_to = params[:rev_to].to_i ? params[:rev_to].to_i : (@rev.to_i - 1) if @rev !~ /\D/
162 + @rev_to = params[:rev_to] ? params[:rev_to] : (nil) if !(@rev !~ /\D/)
163 + end
165 def show_error
166 flash.now[:error] = l(:notice_scm_error)
167 render :nothing => true, :layout => true
168 Index: app/views/repositories/_revisions.rhtml
169 ===================================================================
170 --- app/views/repositories/_revisions.rhtml (revision 887)
171 +++ app/views/repositories/_revisions.rhtml (working copy)
172 @@ -13,11 +13,11 @@
173 <% line_num = 1 %>
174 <% revisions.each do |changeset| %>
175 <tr class="<%= cycle 'odd', 'even' %>">
176 -<td class="id"><%= link_to changeset.revision, :action => 'revision', :id => project, :rev => changeset.revision %></td>
177 +<td class="id"><%= link_to changeset.revision[0..5], :action => 'revision', :id => project, :rev => changeset.revision %></td>
178 <td class="checkbox"><%= radio_button_tag('rev', changeset.revision, (line_num==1), :id => "cb-#{line_num}", :onclick => "$('cbto-#{line_num+1}').checked=true;") if show_diff && (line_num < revisions.size) %></td>
179 <td class="checkbox"><%= radio_button_tag('rev_to', changeset.revision, (line_num==2), :id => "cbto-#{line_num}", :onclick => "if ($('cb-#{line_num}').checked==true) {$('cb-#{line_num-1}').checked=true;}") if show_diff && (line_num > 1) %></td>
180 <td align="center" style="width:15%"><%= format_time(changeset.committed_on) %></td>
181 -<td align="center" style="width:15%"><em><%=h changeset.committer %></em></td>
182 +<td align="center" style="width:15%"><em><%=h changeset.committer.split('<').first %></em></td>
183 <td align="left"><%= textilizable(changeset.comments) %></td>
184 </tr>
185 <% line_num += 1 %>
186 Index: app/views/repositories/_dir_list_content.rhtml
187 ===================================================================
188 --- app/views/repositories/_dir_list_content.rhtml (revision 887)
189 +++ app/views/repositories/_dir_list_content.rhtml (working copy)
190 @@ -23,9 +23,9 @@
191 end %>
192 </td>
193 <td align="right"><%= (entry.size ? number_to_human_size(entry.size) : "?") unless entry.is_dir? %></td>
194 -<td align="right"><%= link_to(entry.lastrev.name, :action => 'revision', :id => @project, :rev => entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %></td>
195 +<td align="right"><%= link_to(entry.lastrev.name[0..5], :action => 'revision', :id => @project, :rev => entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %></td>
196 <td align="center"><%= format_time(entry.lastrev.time) if entry.lastrev %></td>
197 -<td align="center"><em><%=h(entry.lastrev.author) if entry.lastrev %></em></td>
198 +<td align="center"><em><%=h(entry.lastrev.author.split('<').first) if entry.lastrev %></em></td>
199 <% changeset = @project.repository.changesets.find_by_revision(entry.lastrev.identifier) if entry.lastrev %>
200 <td><%=h truncate(changeset.comments, 50) unless changeset.nil? %></td>
201 </tr>
202 Index: db/migrate/078_make_revisions_string.rb
203 ===================================================================
204 --- db/migrate/078_make_revisions_string.rb (revision 0)
205 +++ db/migrate/078_make_revisions_string.rb (revision 0)
206 @@ -0,0 +1,11 @@
207 +class MakeRevisionsString < ActiveRecord::Migration
208 + def self.up
209 + change_column :changes, :from_revision, :string
210 + change_column :changesets, :revision, :string
211 + end
213 + def self.down
214 + change_column :changes, :from_revision, :integer
215 + change_column :changesets, :revision, :integer
216 + end
217 +end
218 Index: lib/redmine/scm/adapters/abstract_adapter.rb
219 ===================================================================
220 --- lib/redmine/scm/adapters/abstract_adapter.rb (revision 887)
221 +++ lib/redmine/scm/adapters/abstract_adapter.rb (working copy)
222 @@ -172,7 +172,12 @@
224 }.last
225 end
226 - end
227 + end
230 +def get_rev(rev,path)
231 +Revision.new
232 +end
234 class Revision
235 attr_accessor :identifier, :scmid, :name, :author, :time, :message, :paths, :revision, :branch
236 Index: lib/redmine/scm/adapters/git_adapter.rb
237 ===================================================================
238 --- lib/redmine/scm/adapters/git_adapter.rb (revision 0)
239 +++ lib/redmine/scm/adapters/git_adapter.rb (revision 0)
240 @@ -0,0 +1,205 @@
241 +# redMine - project management software
242 +# Copyright (C) 2006-2007 Jean-Philippe Lang
244 +# This program is free software; you can redistribute it and/or
245 +# modify it under the terms of the GNU General Public License
246 +# as published by the Free Software Foundation; either version 2
247 +# of the License, or (at your option) any later version.
249 +# This program is distributed in the hope that it will be useful,
250 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
251 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
252 +# GNU General Public License for more details.
254 +# You should have received a copy of the GNU General Public License
255 +# along with this program; if not, write to the Free Software
256 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
258 +require 'redmine/scm/adapters/abstract_adapter'
260 +module Redmine
261 + module Scm
262 + module Adapters
263 + class GitAdapter < AbstractAdapter
265 + # Git executable name
266 + GIT_BIN = "git"
269 + #get the revision of a particuliar file
270 + def get_rev (rev,path)
271 +cmd="cd #{target('')} && git show #{rev} #{path}" if rev!='latest'
272 +cmd="cd #{target('')} && git log -1 master -- #{path}" if
273 +rev=='latest' or rev.nil?
274 +puts cmd
275 +rev=[]
276 + i=0
277 + shellout(cmd) do |io|
278 + commit_files=[]
279 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
281 + message=''
282 + io.each_line do |line|
284 + i=0 if line=~/^commit/
285 + params[:commit]=line.chomp.gsub("commit ",'') if i==0
287 + params[:author]=line.chomp.gsub("Author: ",'') if i==1
288 + params[:date]=line.chomp.gsub("Date: ",'') if i==2
289 + params[:message]+= line.chomp.to_s if i==4 and line[0..0]!=':'
290 + params[:file][:action], params[:file][:path]= line.chomp.slice(/[ACDMRTUXB].*/).split(' ', 2) if i>=4 and line[0..0]==':'
291 + commit_files << {:action=>params[:file][:action],:path=>params[:file][:path]} if i>=4 and line[0..0]==':'
292 + i+=1
293 + end
295 + rev = Revision.new({:identifier => params[:commit],
296 + :scmid => params[:commit],
297 + :author => params[:author],
298 + :time => Time.parse(params[:date]),
299 + :message => params[:message],
300 + :paths => commit_files
301 + })
302 + end
304 + get_rev('latest',path) if i==0
306 + return nil if $? && $?.exitstatus != 0
307 + return rev
308 +# rescue Errno::ENOENT => e
309 +# raise CommandFailed
310 +end
313 + def info
314 +# cmd = "#{GIT_BIN} -R #{target('')} root"
315 +# root_url = nil
316 +# shellout(cmd) do |io|
317 + root_url = target('')
318 +# end
319 + return nil if $? && $?.exitstatus != 0
320 + info = Info.new({:root_url => target(''),
321 + :lastrev => revisions(root_url,nil,nil,nil).first
322 + })
323 + info
324 + rescue Errno::ENOENT => e
325 + return nil
326 + end
328 + def entries(path=nil, identifier=nil)
329 + path ||= ''
330 + entries = Entries.new
331 + cmd = "cd #{target('')} && #{GIT_BIN} show HEAD:#{path}" if identifier.nil?
332 + cmd = "cd #{target('')} && #{GIT_BIN} show #{identifier}:#{path}" if identifier
333 + shellout(cmd) do |io|
334 + io.each_line do |line|
335 + e = line.chomp.split('\\')
336 + unless e.to_s.strip=='' or line[0..3]=='tree'
337 + name=e.first.split('/')[0]
338 + entries << Entry.new({:name => name,
339 + :path => (path.empty? ? name : "#{path}/#{name}"),
340 + :kind => ((e.first.include? '/') ? 'dir' : 'file'),
341 + :lastrev => get_rev(identifier,(path.empty? ? name : "#{path}/#{name}"))
342 + }) unless entries.detect{|entry| entry.name == name}
343 + puts e[0..3]
344 + end
345 + end
346 + end
347 + return nil if $? && $?.exitstatus != 0
348 + entries.sort_by_name
349 +# rescue Errno::ENOENT => e
350 +# raise CommandFailed
351 + end
353 + def entry(path=nil, identifier=nil)
354 + path ||= ''
355 + search_path = path.split('/')[0..-2].join('/')
356 + entry_name = path.split('/').last
357 + e = entries(search_path, identifier)
358 + e ? e.detect{|entry| entry.name == entry_name} : nil
359 + end
361 + def revisions(path, identifier_from, identifier_to, options={})
362 + revisions = Revisions.new
363 + cmd = "cd #{target('')} && #{GIT_BIN} whatchanged "
364 + cmd << " #{identifier_from}.. " if identifier_from
365 + cmd << " #{identifier_to} " if identifier_to
366 + #cmd << " HEAD " if !identifier_to
367 + puts cmd
368 + shellout(cmd) do |io|
369 + files=[]
370 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
371 + i=0
372 + message=''
373 + io.each_line do |line|
375 + if line=~/^commit/ and i>0
376 + revisions << Revision.new({:identifier => params[:commit],
377 + :scmid => params[:commit],
378 + :author => params[:author],
379 + :time => Time.parse(params[:date]),
380 + :message => params[:message],
381 + :paths => files
382 + })
384 + files=[]
385 + i=0
386 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
387 + end
388 + params[:commit]=line.chomp.gsub("commit ",'') if i==0
389 + params[:author]=line.chomp.gsub("Author: ",'') if i==1
390 + params[:date]=line.chomp.gsub("Date: ",'') if i==2
391 + params[:message]+= line.chomp.to_s if i>=4 and line[0..0]!=':'
392 + params[:file][:action], params[:file][:path]= line.chomp.slice(/[ACDMRTUXB].*/).split(' ', 2) if i>=4 and line[0..0]==':'
393 + files << {:action=>params[:file][:action],:path=>params[:file][:path]} if i>=4 and line[0..0]==':'
394 + i+=1
395 + end
396 + end
398 + return nil if $? && $?.exitstatus != 0
399 + revisions
400 + rescue Errno::ENOENT => e
401 + raise CommandFailed
402 + puts 'revs: #{revisions}'
403 + end
405 + def diff(path, identifier_from, identifier_to=nil, type="inline")
406 + path ||= ''
407 + if identifier_to
408 + identifier_to = identifier_to
409 + else
410 + identifier_to = nil
411 + end
412 + cmd = "cd #{target('')} && #{GIT_BIN} diff #{identifier_from}^!" if identifier_to.nil?
413 + cmd = "cd #{target('')} && #{GIT_BIN} diff #{identifier_to} #{identifier_from}" if !identifier_to.nil?
414 + cmd << " #{path}" unless path.empty?
415 + diff = []
416 + shellout(cmd) do |io|
417 + io.each_line do |line|
418 + diff << line
419 + end
420 + end
421 + return nil if $? && $?.exitstatus != 0
422 + DiffTableList.new diff, type
424 + rescue Errno::ENOENT => e
425 + raise CommandFailed
426 + end
428 + def cat(path, identifier=nil)
429 + cmd = "cd #{target('')} && #{GIT_BIN} show #{identifier}:#{path}"
430 + cat = nil
431 + shellout(cmd) do |io|
432 + io.binmode
433 + cat = io.read
434 + end
435 + return nil if $? && $?.exitstatus != 0
436 + cat
437 + rescue Errno::ENOENT => e
438 + raise CommandFailed
439 + end
440 + end
441 + end
442 + end
444 +end
446 Index: lib/redmine.rb
447 ===================================================================
448 --- lib/redmine.rb (revision 887)
449 +++ lib/redmine.rb (working copy)
450 @@ -10,7 +10,7 @@
451 # RMagick is not available
454 -REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs )
455 +REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Git)
457 # Permissions
458 Redmine::AccessControl.map do |map|