comparison app/models/repository/.svn/text-base/cvs.rb.svn-base @ 210:0579821a129a

Update to Redmine trunk rev 4802
author Chris Cannam
date Tue, 08 Feb 2011 13:51:46 +0000
parents 513646585e45
children 051f544170fe
comparison
equal deleted inserted replaced
128:07fa8a8b56a8 210:0579821a129a
102 transaction do 102 transaction do
103 tmp_rev_num = 1 103 tmp_rev_num = 1
104 scm.revisions('', fetch_since, nil, :with_paths => true) do |revision| 104 scm.revisions('', fetch_since, nil, :with_paths => true) do |revision|
105 # only add the change to the database, if it doen't exists. the cvs log 105 # only add the change to the database, if it doen't exists. the cvs log
106 # is not exclusive at all. 106 # is not exclusive at all.
107 unless changes.find_by_path_and_revision(scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision]) 107 tmp_time = revision.time.clone
108 revision 108 unless changes.find_by_path_and_revision(
109 scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision])
109 cs = changesets.find(:first, :conditions=>{ 110 cs = changesets.find(:first, :conditions=>{
110 :committed_on=>revision.time-time_delta..revision.time+time_delta, 111 :committed_on=>tmp_time - time_delta .. tmp_time + time_delta,
111 :committer=>revision.author, 112 :committer=>revision.author,
112 :comments=>Changeset.normalize_comments(revision.message) 113 :comments=>Changeset.normalize_comments(revision.message)
113 }) 114 })
114 115
115 # create a new changeset.... 116 # create a new changeset....
116 unless cs 117 unless cs
117 # we use a temporaray revision number here (just for inserting) 118 # we use a temporaray revision number here (just for inserting)
118 # later on, we calculate a continous positive number 119 # later on, we calculate a continous positive number
119 latest = changesets.find(:first, :order => 'id DESC') 120 tmp_time2 = tmp_time.clone.gmtime
121 branch = revision.paths[0][:branch]
122 scmid = branch + "-" + tmp_time2.strftime("%Y%m%d-%H%M%S")
120 cs = Changeset.create(:repository => self, 123 cs = Changeset.create(:repository => self,
121 :revision => "_#{tmp_rev_num}", 124 :revision => "tmp#{tmp_rev_num}",
125 :scmid => scmid,
122 :committer => revision.author, 126 :committer => revision.author,
123 :committed_on => revision.time, 127 :committed_on => tmp_time,
124 :comments => revision.message) 128 :comments => revision.message)
125 tmp_rev_num += 1 129 tmp_rev_num += 1
126 end 130 end
127 131
128 #convert CVS-File-States to internal Action-abbrevations 132 #convert CVS-File-States to internal Action-abbrevations
142 ) 146 )
143 end 147 end
144 end 148 end
145 149
146 # Renumber new changesets in chronological order 150 # Renumber new changesets in chronological order
147 changesets.find(:all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE '_%'").each do |changeset| 151 changesets.find(
152 :all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE 'tmp%'"
153 ).each do |changeset|
148 changeset.update_attribute :revision, next_revision_number 154 changeset.update_attribute :revision, next_revision_number
149 end 155 end
150 end # transaction 156 end # transaction
157 @current_revision_number = nil
151 end 158 end
152 159
153 private 160 private
154 161
155 # Returns the next revision number to assign to a CVS changeset 162 # Returns the next revision number to assign to a CVS changeset
156 def next_revision_number 163 def next_revision_number
157 # Need to retrieve existing revision numbers to sort them as integers 164 # Need to retrieve existing revision numbers to sort them as integers
158 @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) 165 sql = "SELECT revision FROM #{Changeset.table_name} "
166 sql << "WHERE repository_id = #{id} AND revision NOT LIKE 'tmp%'"
167 @current_revision_number ||= (connection.select_values(sql).collect(&:to_i).max || 0)
159 @current_revision_number += 1 168 @current_revision_number += 1
160 end 169 end
161 end 170 end