Commit 76b8d3ef authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

CVS duplicate key violation fix (#996, #1098).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1355 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 1a4f8116
......@@ -138,12 +138,18 @@ class Repository::Cvs < Repository
end
# Renumber new changesets in chronological order
c = changesets.find(:first, :order => 'committed_on DESC, id DESC', :conditions => "revision NOT LIKE '_%'")
next_rev = c.nil? ? 1 : (c.revision.to_i + 1)
changesets.find(:all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE '_%'").each do |changeset|
changeset.update_attribute :revision, next_rev
next_rev += 1
changeset.update_attribute :revision, next_revision_number
end
end # transaction
end
private
# Returns the next revision number to assign to a CVS changeset
def next_revision_number
# Need to retrieve existing revision numbers to sort them as integers
@current_revision_number ||= (connection.select_values("SELECT revision FROM #{Changeset.table_name} WHERE repository_id = #{id} AND revision NOT LIKE '_%'").collect(&:to_i).max || 0)
@current_revision_number += 1
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment