From 76b8d3eff26b007791ebb58dd98546e0faa3938d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 24 Apr 2008 17:28:55 +0000 Subject: [PATCH] CVS duplicate key violation fix (#996, #1098). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1355 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/repository/cvs.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/repository/cvs.rb b/app/models/repository/cvs.rb index 7c01a27e..c2d8be97 100644 --- a/app/models/repository/cvs.rb +++ b/app/models/repository/cvs.rb @@ -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