initial commit
[gitredmine.git] / git_edge_patch.diff
blob99e18346dcb28fa2a06fece26c03c3332da28d2a
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/changeset.rb
30 ===================================================================
31 --- app/models/changeset.rb (revision 887)
32 +++ app/models/changeset.rb (working copy)
33 @@ -32,7 +32,7 @@
34 :date_column => 'committed_on'
36 validates_presence_of :repository_id, :revision, :committed_on, :commit_date
37 - validates_numericality_of :revision, :only_integer => true
38 +# validates_numericality_of :revision, :only_integer => true
39 validates_uniqueness_of :revision, :scope => :repository_id
40 validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
42 Index: app/controllers/repositories_controller.rb
43 ===================================================================
44 --- app/controllers/repositories_controller.rb (revision 887)
45 +++ app/controllers/repositories_controller.rb (working copy)
46 @@ -46,7 +46,7 @@
48 def show
49 # check if new revisions have been committed in the repository
50 - @repository.fetch_changesets if Setting.autofetch_changesets?
51 + @repository.fetch_changesets #if Setting.autofetch_changesets?
52 # get entries for the browse frame
53 @entries = @repository.entries('')
54 # latest changesets
55 @@ -105,7 +105,8 @@
56 end
58 def diff
59 - @rev_to = params[:rev_to] ? params[:rev_to].to_i : (@rev - 1)
60 + @rev_to = params[:rev_to].to_i ? params[:rev_to].to_i : (@rev.to_i - 1) if @repository.class.to_s!='Repository::Git'
61 +@rev_to = params[:rev_to] ? params[:rev_to] : (nil) if @repository.class.to_s=='Repository::Git'
62 @diff_type = ('sbs' == params[:type]) ? 'sbs' : 'inline'
64 @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
65 @@ -147,7 +148,7 @@
66 render_404 and return false unless @repository
67 @path = params[:path].join('/') unless params[:path].nil?
68 @path ||= ''
69 - @rev = params[:rev].to_i if params[:rev]
70 + @rev = params[:rev] if params[:rev]
71 rescue ActiveRecord::RecordNotFound
72 render_404
73 end
74 Index: lib/redmine/scm/adapters/abstract_adapter.rb
75 ===================================================================
76 --- lib/redmine/scm/adapters/abstract_adapter.rb (revision 887)
77 +++ lib/redmine/scm/adapters/abstract_adapter.rb (working copy)
78 @@ -172,7 +172,12 @@
79 end
80 }.last
81 end
82 - end
83 + end
86 +def get_rev(rev,path)
87 +Revision.new
88 +end
90 class Revision
91 attr_accessor :identifier, :scmid, :name, :author, :time, :message, :paths, :revision, :branch
92 Index: lib/redmine.rb
93 ===================================================================
94 --- lib/redmine.rb (revision 887)
95 +++ lib/redmine.rb (working copy)
96 @@ -10,7 +10,7 @@
97 # RMagick is not available
98 end
100 -REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs )
101 +REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Git)
103 # Permissions
104 Redmine::AccessControl.map do |map|
105 Index: app/helpers/repositories_helper.rb
106 ===================================================================
107 --- app/helpers/repositories_helper.rb (revision 887)
108 +++ app/helpers/repositories_helper.rb (working copy)
109 @@ -73,6 +73,10 @@
110 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
113 + def git_field_tags(form, repository)
114 + content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
115 + end
117 def cvs_field_tags(form, repository)
118 content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
119 content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
120 Index: app/models/repository/subversion.rb
121 ===================================================================
122 --- app/models/repository/subversion.rb (revision 887)
123 +++ app/models/repository/subversion.rb (working copy)
124 @@ -42,7 +42,7 @@
125 db_revision = latest_changeset ? latest_changeset.revision : 0
126 # latest revision in the repository
127 scm_revision = scm_info.lastrev.identifier.to_i
128 - if db_revision < scm_revision
129 + if db_revision.to_i < scm_revision
130 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
131 identifier_from = db_revision + 1
132 while (identifier_from <= scm_revision)
133 Index: app/models/repository/git.rb
134 ===================================================================
135 --- app/models/repository/git.rb (revision 0)
136 +++ app/models/repository/git.rb (revision 0)
137 @@ -0,0 +1,83 @@
138 +# redMine - project management software
139 +# Copyright (C) 2006-2007 Jean-Philippe Lang
140 +# Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
141 +# This program is free software; you can redistribute it and/or
142 +# modify it under the terms of the GNU General Public License
143 +# as published by the Free Software Foundation; either version 2
144 +# of the License, or (at your option) any later version.
146 +# This program is distributed in the hope that it will be useful,
147 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
148 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
149 +# GNU General Public License for more details.
151 +# You should have received a copy of the GNU General Public License
152 +# along with this program; if not, write to the Free Software
153 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
155 +require 'redmine/scm/adapters/git_adapter'
157 +class Repository::Git < Repository
158 + attr_protected :root_url
159 + validates_presence_of :url
161 + def scm_adapter
162 + Redmine::Scm::Adapters::GitAdapter
163 + end
165 + def self.scm_name
166 + 'Git'
167 + end
169 + def entries(path=nil, identifier=nil)
170 + entries=scm.entries(path, identifier)
171 + if entries
172 + entries.each do |entry|
173 + next unless entry.is_file?
174 + # Search the DB for the entry's last change
175 + change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC")
176 + if change
177 + entry.lastrev.identifier = change.changeset.revision
178 + entry.lastrev.name = change.changeset.revision
179 + entry.lastrev.author = change.changeset.committer
180 + entry.lastrev.revision = change.revision
181 + end
182 + end
183 + end
184 + entries
185 + end
187 + def fetch_changesets
188 + scm_info = scm.info
190 + if scm_info
191 + # latest revision found in database
192 + db_revision = latest_changeset ? latest_changeset.revision : nil
193 + # latest revision in the repository
194 + scm_revision = scm_info.lastrev.identifier
196 + unless changesets.find_by_revision(scm_revision)
198 + revisions = scm.revisions('', db_revision, nil)
199 + transaction do
200 + revisions.reverse_each do |revision|
201 + changeset = Changeset.create(:repository => self,
202 + :revision => revision.identifier,
203 + :scmid => revision.scmid,
204 + :committer => revision.author,
205 + :committed_on => revision.time,
206 + :comments => revision.message)
208 + revision.paths.each do |change|
209 + Change.create(:changeset => changeset,
210 + :action => change[:action],
211 + :path => change[:path],
212 + :from_path => change[:from_path],
213 + :from_revision => change[:from_revision])
214 + end
215 + end
216 + end
217 + end
218 + end
219 + end
220 +end
221 Index: app/models/changeset.rb
222 ===================================================================
223 --- app/models/changeset.rb (revision 887)
224 +++ app/models/changeset.rb (working copy)
225 @@ -32,7 +32,7 @@
226 :date_column => 'committed_on'
228 validates_presence_of :repository_id, :revision, :committed_on, :commit_date
229 - validates_numericality_of :revision, :only_integer => true
230 +# validates_numericality_of :revision, :only_integer => true
231 validates_uniqueness_of :revision, :scope => :repository_id
232 validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
234 Index: app/controllers/repositories_controller.rb
235 ===================================================================
236 --- app/controllers/repositories_controller.rb (revision 887)
237 +++ app/controllers/repositories_controller.rb (working copy)
238 @@ -46,7 +46,7 @@
240 def show
241 # check if new revisions have been committed in the repository
242 - @repository.fetch_changesets if Setting.autofetch_changesets?
243 + @repository.fetch_changesets #if Setting.autofetch_changesets?
244 # get entries for the browse frame
245 @entries = @repository.entries('')
246 # latest changesets
247 @@ -105,7 +105,8 @@
250 def diff
251 - @rev_to = params[:rev_to] ? params[:rev_to].to_i : (@rev - 1)
252 + @rev_to = params[:rev_to].to_i ? params[:rev_to].to_i : (@rev.to_i - 1) if @repository.class.to_s!='Repository::Git'
253 +@rev_to = params[:rev_to] ? params[:rev_to] : (nil) if @repository.class.to_s=='Repository::Git'
254 @diff_type = ('sbs' == params[:type]) ? 'sbs' : 'inline'
256 @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
257 @@ -147,7 +148,7 @@
258 render_404 and return false unless @repository
259 @path = params[:path].join('/') unless params[:path].nil?
260 @path ||= ''
261 - @rev = params[:rev].to_i if params[:rev]
262 + @rev = params[:rev] if params[:rev]
263 rescue ActiveRecord::RecordNotFound
264 render_404
266 Index: db/migrate/078_make_revisions_string.rb
267 ===================================================================
268 --- db/migrate/078_make_revisions_string.rb (revision 0)
269 +++ db/migrate/078_make_revisions_string.rb (revision 0)
270 @@ -0,0 +1,11 @@
271 +class MakeRevisionsString < ActiveRecord::Migration
272 + def self.up
273 + change_column :changes, :from_revision, :string
274 + change_column :changesets, :revision, :string
275 + end
277 + def self.down
278 + change_column :changes, :from_revision, :integer
279 + change_column :changesets, :revision, :integer
280 + end
281 +end
282 Index: lib/redmine/scm/adapters/abstract_adapter.rb
283 ===================================================================
284 --- lib/redmine/scm/adapters/abstract_adapter.rb (revision 887)
285 +++ lib/redmine/scm/adapters/abstract_adapter.rb (working copy)
286 @@ -172,7 +172,12 @@
288 }.last
289 end
290 - end
291 + end
294 +def get_rev(rev,path)
295 +Revision.new
296 +end
298 class Revision
299 attr_accessor :identifier, :scmid, :name, :author, :time, :message, :paths, :revision, :branch
300 Index: lib/redmine.rb
301 ===================================================================
302 --- lib/redmine.rb (revision 887)
303 +++ lib/redmine.rb (working copy)
304 @@ -10,7 +10,7 @@
305 # RMagick is not available
308 -REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs )
309 +REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Git)
311 # Permissions
312 Redmine::AccessControl.map do |map|
313 Index: app/helpers/repositories_helper.rb
314 ===================================================================
315 --- app/helpers/repositories_helper.rb (revision 887)
316 +++ app/helpers/repositories_helper.rb (working copy)
317 @@ -73,6 +73,10 @@
318 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
321 + def git_field_tags(form, repository)
322 + content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
323 + end
325 def cvs_field_tags(form, repository)
326 content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
327 content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
328 Index: app/models/repository/subversion.rb
329 ===================================================================
330 --- app/models/repository/subversion.rb (revision 887)
331 +++ app/models/repository/subversion.rb (working copy)
332 @@ -42,7 +42,7 @@
333 db_revision = latest_changeset ? latest_changeset.revision : 0
334 # latest revision in the repository
335 scm_revision = scm_info.lastrev.identifier.to_i
336 - if db_revision < scm_revision
337 + if db_revision.to_i < scm_revision
338 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
339 identifier_from = db_revision + 1
340 while (identifier_from <= scm_revision)
341 Index: app/models/repository/git.rb
342 ===================================================================
343 --- app/models/repository/git.rb (revision 0)
344 +++ app/models/repository/git.rb (revision 0)
345 @@ -0,0 +1,83 @@
346 +# redMine - project management software
347 +# Copyright (C) 2006-2007 Jean-Philippe Lang
348 +# Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
349 +# This program is free software; you can redistribute it and/or
350 +# modify it under the terms of the GNU General Public License
351 +# as published by the Free Software Foundation; either version 2
352 +# of the License, or (at your option) any later version.
354 +# This program is distributed in the hope that it will be useful,
355 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
356 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
357 +# GNU General Public License for more details.
359 +# You should have received a copy of the GNU General Public License
360 +# along with this program; if not, write to the Free Software
361 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
363 +require 'redmine/scm/adapters/git_adapter'
365 +class Repository::Git < Repository
366 + attr_protected :root_url
367 + validates_presence_of :url
369 + def scm_adapter
370 + Redmine::Scm::Adapters::GitAdapter
371 + end
373 + def self.scm_name
374 + 'Git'
375 + end
377 + def entries(path=nil, identifier=nil)
378 + entries=scm.entries(path, identifier)
379 + if entries
380 + entries.each do |entry|
381 + next unless entry.is_file?
382 + # Search the DB for the entry's last change
383 + change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC")
384 + if change
385 + entry.lastrev.identifier = change.changeset.revision
386 + entry.lastrev.name = change.changeset.revision
387 + entry.lastrev.author = change.changeset.committer
388 + entry.lastrev.revision = change.revision
389 + end
390 + end
391 + end
392 + entries
393 + end
395 + def fetch_changesets
396 + scm_info = scm.info
398 + if scm_info
399 + # latest revision found in database
400 + db_revision = latest_changeset ? latest_changeset.revision : nil
401 + # latest revision in the repository
402 + scm_revision = scm_info.lastrev.identifier
404 + unless changesets.find_by_revision(scm_revision)
406 + revisions = scm.revisions('', db_revision, nil)
407 + transaction do
408 + revisions.reverse_each do |revision|
409 + changeset = Changeset.create(:repository => self,
410 + :revision => revision.identifier,
411 + :scmid => revision.scmid,
412 + :committer => revision.author,
413 + :committed_on => revision.time,
414 + :comments => revision.message)
416 + revision.paths.each do |change|
417 + Change.create(:changeset => changeset,
418 + :action => change[:action],
419 + :path => change[:path],
420 + :from_path => change[:from_path],
421 + :from_revision => change[:from_revision])
422 + end
423 + end
424 + end
425 + end
426 + end
427 + end
428 +end
429 Index: app/models/changeset.rb
430 ===================================================================
431 --- app/models/changeset.rb (revision 887)
432 +++ app/models/changeset.rb (working copy)
433 @@ -32,7 +32,7 @@
434 :date_column => 'committed_on'
436 validates_presence_of :repository_id, :revision, :committed_on, :commit_date
437 - validates_numericality_of :revision, :only_integer => true
438 +# validates_numericality_of :revision, :only_integer => true
439 validates_uniqueness_of :revision, :scope => :repository_id
440 validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
442 Index: app/controllers/repositories_controller.rb
443 ===================================================================
444 --- app/controllers/repositories_controller.rb (revision 887)
445 +++ app/controllers/repositories_controller.rb (working copy)
446 @@ -46,7 +46,7 @@
448 def show
449 # check if new revisions have been committed in the repository
450 - @repository.fetch_changesets if Setting.autofetch_changesets?
451 + @repository.fetch_changesets #if Setting.autofetch_changesets?
452 # get entries for the browse frame
453 @entries = @repository.entries('')
454 # latest changesets
455 @@ -105,7 +105,8 @@
458 def diff
459 - @rev_to = params[:rev_to] ? params[:rev_to].to_i : (@rev - 1)
460 + @rev_to = params[:rev_to].to_i ? params[:rev_to].to_i : (@rev.to_i - 1) if @repository.class.to_s!='Repository::Git'
461 +@rev_to = params[:rev_to] ? params[:rev_to] : (nil) if @repository.class.to_s=='Repository::Git'
462 @diff_type = ('sbs' == params[:type]) ? 'sbs' : 'inline'
464 @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
465 @@ -147,7 +148,7 @@
466 render_404 and return false unless @repository
467 @path = params[:path].join('/') unless params[:path].nil?
468 @path ||= ''
469 - @rev = params[:rev].to_i if params[:rev]
470 + @rev = params[:rev] if params[:rev]
471 rescue ActiveRecord::RecordNotFound
472 render_404
474 Index: db/migrate/078_make_revisions_string.rb
475 ===================================================================
476 --- db/migrate/078_make_revisions_string.rb (revision 0)
477 +++ db/migrate/078_make_revisions_string.rb (revision 0)
478 @@ -0,0 +1,11 @@
479 +class MakeRevisionsString < ActiveRecord::Migration
480 + def self.up
481 + change_column :changes, :from_revision, :string
482 + change_column :changesets, :revision, :string
483 + end
485 + def self.down
486 + change_column :changes, :from_revision, :integer
487 + change_column :changesets, :revision, :integer
488 + end
489 +end
490 Index: lib/redmine/scm/adapters/abstract_adapter.rb
491 ===================================================================
492 --- lib/redmine/scm/adapters/abstract_adapter.rb (revision 887)
493 +++ lib/redmine/scm/adapters/abstract_adapter.rb (working copy)
494 @@ -172,7 +172,12 @@
496 }.last
497 end
498 - end
499 + end
502 +def get_rev(rev,path)
503 +Revision.new
504 +end
506 class Revision
507 attr_accessor :identifier, :scmid, :name, :author, :time, :message, :paths, :revision, :branch
508 Index: lib/redmine/scm/adapters/git_adapter.rb
509 ===================================================================
510 --- lib/redmine/scm/adapters/git_adapter.rb (revision 0)
511 +++ lib/redmine/scm/adapters/git_adapter.rb (revision 0)
512 @@ -0,0 +1,205 @@
513 +# redMine - project management software
514 +# Copyright (C) 2006-2007 Jean-Philippe Lang
515 +# Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
516 +# This program is free software; you can redistribute it and/or
517 +# modify it under the terms of the GNU General Public License
518 +# as published by the Free Software Foundation; either version 2
519 +# of the License, or (at your option) any later version.
521 +# This program is distributed in the hope that it will be useful,
522 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
523 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
524 +# GNU General Public License for more details.
526 +# You should have received a copy of the GNU General Public License
527 +# along with this program; if not, write to the Free Software
528 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
530 +require 'redmine/scm/adapters/abstract_adapter'
532 +module Redmine
533 + module Scm
534 + module Adapters
535 + class GitAdapter < AbstractAdapter
537 + # Git executable name
538 + GIT_BIN = "git"
541 + #get the revision of a particuliar file
542 + def get_rev (rev,path)
543 +cmd="cd #{target('')} && git show #{rev} #{path}" if rev!='latest'
544 +cmd="cd #{target('')} && git log -1 master -- #{path}" if
545 +rev=='latest' or rev.nil?
546 +puts cmd
547 +rev=[]
548 + i=0
549 + shellout(cmd) do |io|
550 + commit_files=[]
551 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
553 + message=''
554 + io.each_line do |line|
556 + i=0 if line=~/^commit/
557 + params[:commit]=line.chomp.gsub("commit ",'') if i==0
559 + params[:author]=line.chomp.gsub("Author: ",'') if i==1
560 + params[:date]=line.chomp.gsub("Date: ",'') if i==2
561 + params[:message]+= line.chomp.to_s if i==4 and line[0..0]!=':'
562 + params[:file][:action], params[:file][:path]= line.chomp.slice(/[ACDMRTUXB].*/).split(' ', 2) if i>=4 and line[0..0]==':'
563 + commit_files << {:action=>params[:file][:action],:path=>params[:file][:path]} if i>=4 and line[0..0]==':'
564 + i+=1
565 + end
567 + rev = Revision.new({:identifier => params[:commit],
568 + :scmid => params[:commit],
569 + :author => params[:author],
570 + :time => Time.parse(params[:date]),
571 + :message => params[:message],
572 + :paths => commit_files
573 + })
574 + end
576 + get_rev('latest',path) if i==0
578 + return nil if $? && $?.exitstatus != 0
579 + return rev
580 +# rescue Errno::ENOENT => e
581 +# raise CommandFailed
582 +end
585 + def info
586 +# cmd = "#{GIT_BIN} -R #{target('')} root"
587 +# root_url = nil
588 +# shellout(cmd) do |io|
589 + root_url = target('')
590 +# end
591 + return nil if $? && $?.exitstatus != 0
592 + info = Info.new({:root_url => target(''),
593 + :lastrev => revisions(root_url,nil,nil,nil).first
594 + })
595 + info
596 + rescue Errno::ENOENT => e
597 + return nil
598 + end
600 + def entries(path=nil, identifier=nil)
601 + path ||= ''
602 + entries = Entries.new
603 + cmd = "cd #{target('')} && #{GIT_BIN} show HEAD:#{path}" if identifier.nil?
604 + cmd = "cd #{target('')} && #{GIT_BIN} show #{identifier}:#{path}" if identifier
605 + shellout(cmd) do |io|
606 + io.each_line do |line|
607 + e = line.chomp.split('\\')
608 + unless e.to_s.strip=='' or line[0..3]=='tree'
609 + name=e.first.split('/')[0]
610 + entries << Entry.new({:name => name,
611 + :path => (path.empty? ? name : "#{path}/#{name}"),
612 + :kind => ((e.first.include? '/') ? 'dir' : 'file'),
613 + :lastrev => get_rev(identifier,(path.empty? ? name : "#{path}/#{name}"))
614 + }) unless entries.detect{|entry| entry.name == name}
615 + puts e[0..3]
616 + end
617 + end
618 + end
619 + return nil if $? && $?.exitstatus != 0
620 + entries.sort_by_name
621 +# rescue Errno::ENOENT => e
622 +# raise CommandFailed
623 + end
625 + def entry(path=nil, identifier=nil)
626 + path ||= ''
627 + search_path = path.split('/')[0..-2].join('/')
628 + entry_name = path.split('/').last
629 + e = entries(search_path, identifier)
630 + e ? e.detect{|entry| entry.name == entry_name} : nil
631 + end
633 + def revisions(path, identifier_from, identifier_to, options={})
634 + revisions = Revisions.new
635 + cmd = "cd #{target('')} && #{GIT_BIN} whatchanged "
636 + cmd << " #{identifier_from}.. " if identifier_from
637 + cmd << " #{identifier_to} " if identifier_to
638 + #cmd << " HEAD " if !identifier_to
639 + puts cmd
640 + shellout(cmd) do |io|
641 + files=[]
642 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
643 + i=0
644 + message=''
645 + io.each_line do |line|
647 + if line=~/^commit/ and i>0
648 + revisions << Revision.new({:identifier => params[:commit],
649 + :scmid => params[:commit],
650 + :author => params[:author],
651 + :time => Time.parse(params[:date]),
652 + :message => params[:message],
653 + :paths => files
654 + })
656 + files=[]
657 + i=0
658 + params={:commit=>'',:author=>'',:date=>'',:message=>'',:file=>{:path=>'',:action=>''}}
659 + end
660 + params[:commit]=line.chomp.gsub("commit ",'') if i==0
661 + params[:author]=line.chomp.gsub("Author: ",'') if i==1
662 + params[:date]=line.chomp.gsub("Date: ",'') if i==2
663 + params[:message]+= line.chomp.to_s if i>=4 and line[0..0]!=':'
664 + params[:file][:action], params[:file][:path]= line.chomp.slice(/[ACDMRTUXB].*/).split(' ', 2) if i>=4 and line[0..0]==':'
665 + files << {:action=>params[:file][:action],:path=>params[:file][:path]} if i>=4 and line[0..0]==':'
666 + i+=1
667 + end
668 + end
670 + return nil if $? && $?.exitstatus != 0
671 + revisions
672 + rescue Errno::ENOENT => e
673 + raise CommandFailed
674 + puts 'revs: #{revisions}'
675 + end
677 + def diff(path, identifier_from, identifier_to=nil, type="inline")
678 + path ||= ''
679 + if identifier_to
680 + identifier_to = identifier_to
681 + else
682 + identifier_to = nil
683 + end
684 + cmd = "cd #{target('')} && #{GIT_BIN} diff #{identifier_from}^!" if identifier_to.nil?
685 + cmd = "cd #{target('')} && #{GIT_BIN} diff #{identifier_to} #{identifier_from}" if !identifier_to.nil?
686 + cmd << " #{path}" unless path.empty?
687 + diff = []
688 + shellout(cmd) do |io|
689 + io.each_line do |line|
690 + diff << line
691 + end
692 + end
693 + return nil if $? && $?.exitstatus != 0
694 + DiffTableList.new diff, type
696 + rescue Errno::ENOENT => e
697 + raise CommandFailed
698 + end
700 + def cat(path, identifier=nil)
701 + cmd = "cd #{target('')} && #{GIT_BIN} show #{identifier}:#{path}"
702 + cat = nil
703 + shellout(cmd) do |io|
704 + io.binmode
705 + cat = io.read
706 + end
707 + return nil if $? && $?.exitstatus != 0
708 + cat
709 + rescue Errno::ENOENT => e
710 + raise CommandFailed
711 + end
712 + end
713 + end
714 + end
716 +end
718 Index: lib/redmine.rb
719 ===================================================================
720 --- lib/redmine.rb (revision 887)
721 +++ lib/redmine.rb (working copy)
722 @@ -10,7 +10,7 @@
723 # RMagick is not available
726 -REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs )
727 +REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Git)
729 # Permissions
730 Redmine::AccessControl.map do |map|