1 Index: app/helpers/repositories_helper.rb
2 ===================================================================
3 --- app/helpers/repositories_helper.rb (revision 887)
4 +++ app/helpers/repositories_helper.rb (working copy)
6 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
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?)))
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)
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)
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.
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.
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
58 + Redmine::Scm::Adapters::GitAdapter
65 + def entries(path=nil, identifier=nil)
66 + entries=scm.entries(path, identifier)
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")
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
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)
90 + def fetch_changesets
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)
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])
124 Index: app/models/changeset.rb
125 ===================================================================
126 --- app/models/changeset.rb (revision 887)
127 +++ app/models/changeset.rb (working copy)
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)
144 # check if new revisions have been committed in the repository
145 - @repository.fetch_changesets if Setting.autofetch_changesets?
146 + @repository.fetch_changesets #if Setting.autofetch_changesets?
147 # get entries for the browse frame
148 @entries = @repository.entries('')
154 - @rev_to = params[:rev_to] ? params[:rev_to].to_i : (@rev - 1)
156 @diff_type = ('sbs' == params[:type]) ? 'sbs' : 'inline'
158 @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
159 @@ -147,11 +147,16 @@
160 render_404 and return false unless @repository
161 @path = params[:path].join('/') unless params[:path].nil?
163 - @rev = params[:rev].to_i if params[:rev]
164 + @rev = params[:rev] if params[:rev]
165 rescue ActiveRecord::RecordNotFound
170 + @rev_to = params[:rev_to].to_i ? params[:rev_to].to_i : (@rev.to_i - 1) if @rev !~ /\D/
171 + @rev_to = params[:rev_to] ? params[:rev_to] : (nil) if !(@rev !~ /\D/)
175 flash.now[:error] = l(:notice_scm_error)
176 render :nothing => true, :layout => true
177 Index: db/migrate/078_make_revisions_string.rb
178 ===================================================================
179 --- db/migrate/078_make_revisions_string.rb (revision 0)
180 +++ db/migrate/078_make_revisions_string.rb (revision 0)
182 +class MakeRevisionsString < ActiveRecord::Migration
184 + change_column :changes, :from_revision, :string
185 + change_column :changesets, :revision, :string
189 + change_column :changes, :from_revision, :integer
190 + change_column :changesets, :revision, :integer
193 Index: lib/redmine/scm/adapters/abstract_adapter.rb
194 ===================================================================
195 --- lib/redmine/scm/adapters/abstract_adapter.rb (revision 887)
196 +++ lib/redmine/scm/adapters/abstract_adapter.rb (working copy)
205 +def get_rev(rev,path)
210 attr_accessor :identifier, :scmid, :name, :author, :time, :message, :paths, :revision, :branch
211 Index: lib/redmine/scm/adapters/git_adapter.rb
212 ===================================================================
213 --- lib/redmine/scm/adapters/git_adapter.rb (revision 0)
214 +++ lib/redmine/scm/adapters/git_adapter.rb (revision 0)
216 +# redMine - project management software
217 +# Copyright (C) 2006-2007 Jean-Philippe Lang
219 +# This program is free software; you can redistribute it and/or
220 +# modify it under the terms of the GNU General Public License
221 +# as published by the Free Software Foundation; either version 2
222 +# of the License, or (at your option) any later version.
224 +# This program is distributed in the hope that it will be useful,
225 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
226 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
227 +# GNU General Public License for more details.
229 +# You should have received a copy of the GNU General Public License
230 +# along with this program; if not, write to the Free Software
231 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
233 +require 'redmine/scm/adapters/abstract_adapter'
238 + class GitAdapter < AbstractAdapter
240 + # Git executable name
244 + #get the revision of a particuliar file
245 + def get_rev (rev,path)
246 +cmd="cd #{target('')} && git show #{rev} #{path}" if rev!='latest'
247 +cmd="cd #{target('')} && git log -1 master -- #{path}" if
248 +rev=='latest' or rev.nil?
252 + shellout(cmd) do |io|
254 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
257 + io.each_line do |line|
259 + i=0 if line=~/^commit/
260 + params[:commit]=line.chomp.gsub("commit ",'') if i==0
262 + params[:author]=line.chomp.gsub("Author: ",'') if i==1
263 + params[:date]=line.chomp.gsub("Date: ",'') if i==2
264 + params[:message]+= line.chomp.to_s if i==4 and line[0..0]!=':'
265 + params[:file][:action], params[:file][:path]= line.chomp.slice(/[ACDMRTUXB].*/).split(' ', 2) if i>=4 and line[0..0]==':'
266 + commit_files << {:action=>params[:file][:action],:path=>params[:file][:path]} if i>=4 and line[0..0]==':'
270 + rev = Revision.new({:identifier => params[:commit],
271 + :scmid => params[:commit],
272 + :author => params[:author],
273 + :time => Time.parse(params[:date]),
274 + :message => params[:message],
275 + :paths => commit_files
279 + get_rev('latest',path) if i==0
281 + return nil if $? && $?.exitstatus != 0
283 +# rescue Errno::ENOENT => e
284 +# raise CommandFailed
289 +# cmd = "#{GIT_BIN} -R #{target('')} root"
291 +# shellout(cmd) do |io|
292 + root_url = target('')
294 + return nil if $? && $?.exitstatus != 0
295 + info = Info.new({:root_url => target(''),
296 + :lastrev => revisions(root_url,nil,nil,nil).first
299 + rescue Errno::ENOENT => e
303 + def entries(path=nil, identifier=nil)
305 + entries = Entries.new
306 + cmd = "cd #{target('')} && #{GIT_BIN} show HEAD:#{path}" if identifier.nil?
307 + cmd = "cd #{target('')} && #{GIT_BIN} show #{identifier}:#{path}" if identifier
308 + shellout(cmd) do |io|
309 + io.each_line do |line|
310 + e = line.chomp.split('\\')
311 + unless e.to_s.strip=='' or line[0..3]=='tree'
312 + name=e.first.split('/')[0]
313 + entries << Entry.new({:name => name,
314 + :path => (path.empty? ? name : "#{path}/#{name}"),
315 + :kind => ((e.first.include? '/') ? 'dir' : 'file'),
316 + :lastrev => get_rev(identifier,(path.empty? ? name : "#{path}/#{name}"))
317 + }) unless entries.detect{|entry| entry.name == name}
322 + return nil if $? && $?.exitstatus != 0
323 + entries.sort_by_name
324 +# rescue Errno::ENOENT => e
325 +# raise CommandFailed
328 + def entry(path=nil, identifier=nil)
330 + search_path = path.split('/')[0..-2].join('/')
331 + entry_name = path.split('/').last
332 + e = entries(search_path, identifier)
333 + e ? e.detect{|entry| entry.name == entry_name} : nil
336 + def revisions(path, identifier_from, identifier_to, options={})
337 + revisions = Revisions.new
338 + cmd = "cd #{target('')} && #{GIT_BIN} whatchanged "
339 + cmd << " #{identifier_from}.. " if identifier_from
340 + cmd << " #{identifier_to} " if identifier_to
341 + #cmd << " HEAD " if !identifier_to
343 + shellout(cmd) do |io|
345 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
348 + io.each_line do |line|
350 + if line=~/^commit/ and i>0
351 + revisions << Revision.new({:identifier => params[:commit],
352 + :scmid => params[:commit],
353 + :author => params[:author],
354 + :time => Time.parse(params[:date]),
355 + :message => params[:message],
361 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
363 + params[:commit]=line.chomp.gsub("commit ",'') if i==0
364 + params[:author]=line.chomp.gsub("Author: ",'') if i==1
365 + params[:date]=line.chomp.gsub("Date: ",'') if i==2
366 + params[:message]+= line.chomp.to_s if i>=4 and line[0..0]!=':'
367 + params[:file][:action], params[:file][:path]= line.chomp.slice(/[ACDMRTUXB].*/).split(' ', 2) if i>=4 and line[0..0]==':'
368 + files << {:action=>params[:file][:action],:path=>params[:file][:path]} if i>=4 and line[0..0]==':'
373 + return nil if $? && $?.exitstatus != 0
375 + rescue Errno::ENOENT => e
376 + raise CommandFailed
377 + puts 'revs: #{revisions}'
380 + def diff(path, identifier_from, identifier_to=nil, type="inline")
383 + identifier_to = identifier_to
385 + identifier_to = nil
387 + cmd = "cd #{target('')} && #{GIT_BIN} diff #{identifier_from}^!" if identifier_to.nil?
388 + cmd = "cd #{target('')} && #{GIT_BIN} diff #{identifier_to} #{identifier_from}" if !identifier_to.nil?
389 + cmd << " #{path}" unless path.empty?
391 + shellout(cmd) do |io|
392 + io.each_line do |line|
396 + return nil if $? && $?.exitstatus != 0
397 + DiffTableList.new diff, type
399 + rescue Errno::ENOENT => e
400 + raise CommandFailed
403 + def cat(path, identifier=nil)
404 + cmd = "cd #{target('')} && #{GIT_BIN} show #{identifier}:#{path}"
406 + shellout(cmd) do |io|
410 + return nil if $? && $?.exitstatus != 0
412 + rescue Errno::ENOENT => e
413 + raise CommandFailed
421 Index: lib/redmine.rb
422 ===================================================================
423 --- lib/redmine.rb (revision 887)
424 +++ lib/redmine.rb (working copy)
426 # RMagick is not available
429 -REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs )
430 +REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Git)
433 Redmine::AccessControl.map do |map|