@@ -117,7 +117,7 class Repository::Cvs < Repository | |||
|
117 | 117 | # we use a temporaray revision number here (just for inserting) |
|
118 | 118 | # later on, we calculate a continous positive number |
|
119 | 119 | cs = Changeset.create(:repository => self, |
|
120 |
:revision => " |
|
|
120 | :revision => "tmp#{tmp_rev_num}", | |
|
121 | 121 | :committer => revision.author, |
|
122 | 122 | :committed_on => revision.time, |
|
123 | 123 | :comments => revision.message) |
@@ -144,11 +144,12 class Repository::Cvs < Repository | |||
|
144 | 144 | |
|
145 | 145 | # Renumber new changesets in chronological order |
|
146 | 146 | changesets.find( |
|
147 |
:all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE ' |
|
|
147 | :all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE 'tmp%'" | |
|
148 | 148 | ).each do |changeset| |
|
149 | 149 | changeset.update_attribute :revision, next_revision_number |
|
150 | 150 | end |
|
151 | 151 | end # transaction |
|
152 | @current_revision_number = nil | |
|
152 | 153 | end |
|
153 | 154 | |
|
154 | 155 | private |
@@ -156,7 +157,9 class Repository::Cvs < Repository | |||
|
156 | 157 | # Returns the next revision number to assign to a CVS changeset |
|
157 | 158 | def next_revision_number |
|
158 | 159 | # Need to retrieve existing revision numbers to sort them as integers |
|
159 | @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) | |
|
160 | sql = "SELECT revision FROM #{Changeset.table_name} " | |
|
161 | sql << "WHERE repository_id = #{id} AND revision NOT LIKE 'tmp%'" | |
|
162 | @current_revision_number ||= (connection.select_values(sql).collect(&:to_i).max || 0) | |
|
160 | 163 | @current_revision_number += 1 |
|
161 | 164 | end |
|
162 | 165 | end |
@@ -47,13 +47,29 class RepositoryCvsTest < ActiveSupport::TestCase | |||
|
47 | 47 | def test_fetch_changesets_incremental |
|
48 | 48 | assert_equal 0, @repository.changesets.count |
|
49 | 49 | @repository.fetch_changesets |
|
50 |
# Remove |
|
|
51 | @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy) | |
|
50 | # Remove changesets with revision > 3 | |
|
51 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3} | |
|
52 | 52 | @repository.reload |
|
53 |
assert_equal |
|
|
54 | ||
|
53 | assert_equal 3, @repository.changesets.count | |
|
54 | assert_equal %w|3 2 1|, @repository.changesets.collect(&:revision) | |
|
55 | ||
|
56 | rev3_commit = @repository.changesets.find(:first, :order => 'committed_on DESC') | |
|
57 | assert_equal '3', rev3_commit.revision | |
|
58 | # 2007-12-14 01:27:22 +0900 | |
|
59 | rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22) | |
|
60 | assert_equal rev3_committed_on, rev3_commit.committed_on | |
|
61 | latest_rev = @repository.latest_changeset | |
|
62 | assert_equal rev3_committed_on, latest_rev.committed_on | |
|
63 | ||
|
55 | 64 | @repository.fetch_changesets |
|
65 | @repository.reload | |
|
56 | 66 | assert_equal 5, @repository.changesets.count |
|
67 | ||
|
68 | assert_equal %w|5 4 3 2 1|, @repository.changesets.collect(&:revision) | |
|
69 | rev5_commit = @repository.changesets.find(:first, :order => 'committed_on DESC') | |
|
70 | # 2007-12-14 01:30:01 +0900 | |
|
71 | rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1) | |
|
72 | assert_equal rev5_committed_on, rev5_commit.committed_on | |
|
57 | 73 | end |
|
58 | 74 | |
|
59 | 75 | def test_deleted_files_should_not_be_listed |
General Comments 0
You need to be logged in to leave comments.
Login now