Created
October 31, 2008 15:25
-
-
Save jamiew/21326 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sync_changesets | |
return unless ENABLE_SUBVERSION | |
begin | |
latest_changeset = changesets.find(:first, :select => 'revision', :order => 'revised_at DESC') | |
start = latest_changeset ? latest_changeset.revision.to_i + 1: 1 | |
stop = latest_revision | |
return if start > stop | |
Changeset.transaction do | |
log :debug, 'SYNC', "Revisions: #{start} - #{stop}" | |
(start..stop).each do |rev| | |
log :debug, 'SYNC', "Revision: #{rev}" | |
next if changesets.exists?(:revision => rev.to_s) | |
changeset, node_data = create_changeset(rev) | |
# Store copied nodes | |
node_data[:copied].each do |path| | |
destination = path[0] ? path[0].chomp('/') : nil | |
origin = path[1] ? path[1].chomp('/') : nil | |
changeset.changes.build( | |
:revision => rev, | |
:name => 'CP', | |
:path => destination, | |
:from_path => origin, | |
:from_revision => path[2], | |
:repository => self ) | |
log :debug, 'SYNC', "Node: copied #{destination} (from #{origin}:#{path[2]})" | |
end | |
# Store moved nodes | |
node_data[:moved].each do |path| | |
destination = path[0] ? path[0].chomp('/') : nil | |
origin = path[1] ? path[1].chomp('/') : nil | |
changeset.changes.build( | |
:revision => rev, | |
:name => 'MV', | |
:path => destination, | |
:from_path => origin, | |
:from_revision => path[2], | |
:repository => self ) | |
log :debug, 'SYNC', "Node: moved #{destination} (from #{origin}:#{path[2]})" | |
end | |
# Store added nodes | |
node_data[:added].each do |path| | |
changeset.changes.build( | |
:revision => rev, | |
:name => 'A', | |
:path => path, | |
:repository => self ) | |
log :debug, 'SYNC', "Node: added #{path}" | |
end | |
# Store deleted nodes | |
node_data[:deleted].each do |path| | |
changeset.changes.build( | |
:revision => rev, | |
:name => 'D', | |
:path => path, | |
:repository => self ) | |
log :debug, 'SYNC', "Node: deleted #{path}" | |
end | |
# Store updated nodes | |
node_data[:updated].each do |path| | |
changeset.changes.build( | |
:revision => rev, | |
:name => 'M', | |
:path => path, | |
:repository => self ) | |
log :debug, 'SYNC', "Node: updated #{path}" | |
end | |
changeset.save! | |
log :info, 'SYNC', "Added revision #{rev}" | |
end | |
end # end transaction | |
rescue ActiveRecord::RecordInvalid => ex | |
log :error, 'SYNC', "Revision already exists!" | |
rescue => other | |
log :error, 'SYNC', other.message | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment