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

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1355 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-04-24 17:28:55 +00:00
parent 1a4f81163d
commit 76b8d3eff2
1 changed files with 10 additions and 4 deletions

View File

@ -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