Skip to content

Commit

Permalink
create changes in redmine only when filesystem scm has been patched...
Browse files Browse the repository at this point in the history
  • Loading branch information
amartel committed Feb 6, 2012
1 parent bd77d69 commit 6a36276
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions lib/scm_extensions_filesystem_adapter_patch.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,24 +38,28 @@ def scm_extensions_upload(repository, folder_path, attachments, comments, identi
if container if container
error = false error = false


rev = -1 if repository.supports_all_revisions?
rev = repository.latest_changeset.revision.to_i if repository.latest_changeset rev = -1
rev = rev + 1 rev = repository.latest_changeset.revision.to_i if repository.latest_changeset
changeset = Changeset.create(:repository => repository, rev = rev + 1
changeset = Changeset.create(:repository => repository,
:revision => rev, :revision => rev,
:committer => User.current.login, :committer => User.current.login,
:committed_on => Time.now, :committed_on => Time.now,
:comments => comments) :comments => comments)


end
attachments.each_value do |attachment| attachments.each_value do |attachment|
file = attachment['file'] file = attachment['file']
next unless file && file.size > 0 && !error next unless file && file.size > 0 && !error
filename = File.basename(file.original_filename) filename = File.basename(file.original_filename)
next if scm_extensions_invalid_path(filename) next if scm_extensions_invalid_path(filename)
begin begin
action = "A" if repository.supports_all_revisions?
action = "M" if File.exists?(File.join(repository.url, folder_path, filename)) action = "A"
Change.create( :changeset => changeset, :action => action, :path => File.join("/", folder_path, filename)) action = "M" if File.exists?(File.join(repository.url, folder_path, filename))
Change.create( :changeset => changeset, :action => action, :path => File.join("/", folder_path, filename))
end
File.open(File.join(repository.url, folder_path, filename), "wb") do |f| File.open(File.join(repository.url, folder_path, filename), "wb") do |f|
buffer = "" buffer = ""
while (buffer = file.read(8192)) while (buffer = file.read(8192))
Expand Down Expand Up @@ -95,15 +99,17 @@ def scm_extensions_delete(repository, path, comments, identifier)
error = false error = false


begin begin
rev = -1 if repository.supports_all_revisions?
rev = repository.latest_changeset.revision.to_i if repository.latest_changeset rev = -1
rev = rev + 1 rev = repository.latest_changeset.revision.to_i if repository.latest_changeset
changeset = Changeset.create(:repository => repository, rev = rev + 1
changeset = Changeset.create(:repository => repository,
:revision => rev, :revision => rev,
:committer => User.current.login, :committer => User.current.login,
:committed_on => Time.now, :committed_on => Time.now,
:comments => comments) :comments => comments)
Change.create( :changeset => changeset, :action => 'D', :path => File.join("/", path)) Change.create( :changeset => changeset, :action => 'D', :path => File.join("/", path))
end


FileUtils.remove_entry_secure File.join(repository.url, path) FileUtils.remove_entry_secure File.join(repository.url, path)
if metapath if metapath
Expand All @@ -124,16 +130,17 @@ def scm_extensions_mkdir(repository, path, comments, identifier)


error = false error = false
begin begin
rev = -1 if repository.supports_all_revisions?
rev = repository.latest_changeset.revision.to_i if repository.latest_changeset rev = -1
rev = rev + 1 rev = repository.latest_changeset.revision.to_i if repository.latest_changeset
changeset = Changeset.create(:repository => repository, rev = rev + 1
changeset = Changeset.create(:repository => repository,
:revision => rev, :revision => rev,
:committer => User.current.login, :committer => User.current.login,
:committed_on => Time.now, :committed_on => Time.now,
:comments => "created folder: #{path}") :comments => "created folder: #{path}")
Change.create( :changeset => changeset, :action => 'A', :path => File.join("/", path)) Change.create( :changeset => changeset, :action => 'A', :path => File.join("/", path))

end
Dir.mkdir(File.join(repository.url, path)) Dir.mkdir(File.join(repository.url, path))
rescue rescue
error = true error = true
Expand Down

0 comments on commit 6a36276

Please sign in to comment.