initial commit
[gitredmine.git] / git_edge_2_patch.diff
blobc43729cc7927b7d694e3da938f229d8bd6a182d0
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 @@ -46,7 +46,7 @@
143 def show
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('')
149 # latest changesets
150 @@ -105,7 +105,7 @@
153 def diff
154 - @rev_to = params[:rev_to] ? params[:rev_to].to_i : (@rev - 1)
155 + get_rev_to
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?
162 @path ||= ''
163 - @rev = params[:rev].to_i if params[:rev]
164 + @rev = params[:rev] if params[:rev]
165 rescue ActiveRecord::RecordNotFound
166 render_404
169 + def get_rev_to
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/)
172 + end
174 def show_error
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)
181 @@ -0,0 +1,11 @@
182 +class MakeRevisionsString < ActiveRecord::Migration
183 + def self.up
184 + change_column :changes, :from_revision, :string
185 + change_column :changesets, :revision, :string
186 + end
188 + def self.down
189 + change_column :changes, :from_revision, :integer
190 + change_column :changesets, :revision, :integer
191 + end
192 +end
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)
197 @@ -172,7 +172,12 @@
199 }.last
200 end
201 - end
202 + end
205 +def get_rev(rev,path)
206 +Revision.new
207 +end
209 class Revision
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)
215 @@ -0,0 +1,205 @@
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'
235 +module Redmine
236 + module Scm
237 + module Adapters
238 + class GitAdapter < AbstractAdapter
240 + # Git executable name
241 + GIT_BIN = "git"
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?
249 +puts cmd
250 +rev=[]
251 + i=0
252 + shellout(cmd) do |io|
253 + commit_files=[]
254 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
256 + message=''
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]==':'
267 + i+=1
268 + end
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
276 + })
277 + end
279 + get_rev('latest',path) if i==0
281 + return nil if $? && $?.exitstatus != 0
282 + return rev
283 +# rescue Errno::ENOENT => e
284 +# raise CommandFailed
285 +end
288 + def info
289 +# cmd = "#{GIT_BIN} -R #{target('')} root"
290 +# root_url = nil
291 +# shellout(cmd) do |io|
292 + root_url = target('')
293 +# end
294 + return nil if $? && $?.exitstatus != 0
295 + info = Info.new({:root_url => target(''),
296 + :lastrev => revisions(root_url,nil,nil,nil).first
297 + })
298 + info
299 + rescue Errno::ENOENT => e
300 + return nil
301 + end
303 + def entries(path=nil, identifier=nil)
304 + path ||= ''
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}
318 + puts e[0..3]
319 + end
320 + end
321 + end
322 + return nil if $? && $?.exitstatus != 0
323 + entries.sort_by_name
324 +# rescue Errno::ENOENT => e
325 +# raise CommandFailed
326 + end
328 + def entry(path=nil, identifier=nil)
329 + path ||= ''
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
334 + end
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
342 + puts cmd
343 + shellout(cmd) do |io|
344 + files=[]
345 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
346 + i=0
347 + message=''
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],
356 + :paths => files
357 + })
359 + files=[]
360 + i=0
361 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
362 + end
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]==':'
369 + i+=1
370 + end
371 + end
373 + return nil if $? && $?.exitstatus != 0
374 + revisions
375 + rescue Errno::ENOENT => e
376 + raise CommandFailed
377 + puts 'revs: #{revisions}'
378 + end
380 + def diff(path, identifier_from, identifier_to=nil, type="inline")
381 + path ||= ''
382 + if identifier_to
383 + identifier_to = identifier_to
384 + else
385 + identifier_to = nil
386 + end
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?
390 + diff = []
391 + shellout(cmd) do |io|
392 + io.each_line do |line|
393 + diff << line
394 + end
395 + end
396 + return nil if $? && $?.exitstatus != 0
397 + DiffTableList.new diff, type
399 + rescue Errno::ENOENT => e
400 + raise CommandFailed
401 + end
403 + def cat(path, identifier=nil)
404 + cmd = "cd #{target('')} && #{GIT_BIN} show #{identifier}:#{path}"
405 + cat = nil
406 + shellout(cmd) do |io|
407 + io.binmode
408 + cat = io.read
409 + end
410 + return nil if $? && $?.exitstatus != 0
411 + cat
412 + rescue Errno::ENOENT => e
413 + raise CommandFailed
414 + end
415 + end
416 + end
417 + end
419 +end
421 Index: lib/redmine.rb
422 ===================================================================
423 --- lib/redmine.rb (revision 887)
424 +++ lib/redmine.rb (working copy)
425 @@ -10,7 +10,7 @@
426 # RMagick is not available
429 -REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs )
430 +REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Git)
432 # Permissions
433 Redmine::AccessControl.map do |map|