@@ -107,7 +107,8 class Repository::Git < Repository | |||
|
107 | 107 | # However, Git does not have a sequential commit numbering. |
|
108 | 108 | # |
|
109 | 109 | # In order to fetch only new adding revisions, |
|
110 |
# Redmine needs to |
|
|
110 | # Redmine needs to parse revisions per branch. | |
|
111 | # Branch "last_scmid" is for this requirement. | |
|
111 | 112 | # |
|
112 | 113 | # In Git and Mercurial, revisions are not in date order. |
|
113 | 114 | # Redmine Mercurial fixed issues. |
@@ -130,17 +131,9 class Repository::Git < Repository | |||
|
130 | 131 | def fetch_changesets |
|
131 | 132 | scm_brs = branches |
|
132 | 133 | return if scm_brs.nil? || scm_brs.empty? |
|
133 | ||
|
134 | 134 | h1 = extra_info || {} |
|
135 | 135 | h = h1.dup |
|
136 | repo_heads = scm_brs.map{ |br| br.scmid } | |
|
137 | h["heads"] ||= [] | |
|
138 | prev_db_heads = h["heads"].dup | |
|
139 | if prev_db_heads.empty? | |
|
140 | prev_db_heads += heads_from_branches_hash | |
|
141 | end | |
|
142 | return if prev_db_heads.sort == repo_heads.sort | |
|
143 | ||
|
136 | h["branches"] ||= {} | |
|
144 | 137 | h["db_consistent"] ||= {} |
|
145 | 138 | if changesets.count == 0 |
|
146 | 139 | h["db_consistent"]["ordering"] = 1 |
@@ -151,39 +144,35 class Repository::Git < Repository | |||
|
151 | 144 | merge_extra_info(h) |
|
152 | 145 | self.save |
|
153 | 146 | end |
|
154 | ||
|
155 | save_revisions(prev_db_heads, repo_heads) | |
|
156 | end | |
|
157 | ||
|
158 | def save_revisions(prev_db_heads, repo_heads) | |
|
159 | h = {} | |
|
160 | opts = {} | |
|
161 | opts[:reverse] = true | |
|
162 | opts[:excludes] = prev_db_heads | |
|
163 | opts[:includes] = repo_heads | |
|
164 | begin | |
|
165 | scm.revisions('', nil, nil, opts) do |rev| | |
|
166 | db_rev = find_changeset_by_name(rev.scmid) | |
|
167 | transaction do | |
|
168 | if db_rev.nil? | |
|
169 | db_saved_rev = save_revision(rev) | |
|
170 | parents = {} | |
|
171 | parents[db_saved_rev] = rev.parents unless rev.parents.nil? | |
|
172 | parents.each do |ch, chparents| | |
|
173 | ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact | |
|
147 | save_revisions(h, scm_brs) | |
|
148 | end | |
|
149 | ||
|
150 | def save_revisions(h, scm_brs) | |
|
151 | scm_brs.each do |br1| | |
|
152 | br = br1.to_s | |
|
153 | from_scmid = nil | |
|
154 | from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br] | |
|
155 | h["branches"][br] ||= {} | |
|
156 | begin | |
|
157 | scm.revisions('', from_scmid, br, {:reverse => true}) do |rev| | |
|
158 | db_rev = find_changeset_by_name(rev.revision) | |
|
159 | transaction do | |
|
160 | if db_rev.nil? | |
|
161 | db_saved_rev = save_revision(rev) | |
|
162 | parents = {} | |
|
163 | parents[db_saved_rev] = rev.parents unless rev.parents.nil? | |
|
164 | parents.each do |ch, chparents| | |
|
165 | ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact | |
|
166 | end | |
|
174 | 167 | end |
|
168 | h["branches"][br]["last_scmid"] = rev.scmid | |
|
169 | merge_extra_info(h) | |
|
170 | self.save | |
|
175 | 171 | end |
|
176 | h["heads"] = prev_db_heads.dup | |
|
177 | h["heads"] << rev.scmid | |
|
178 | merge_extra_info(h) | |
|
179 | self.save | |
|
180 | 172 | end |
|
173 | rescue Redmine::Scm::Adapters::CommandFailed => e | |
|
174 | logger.error("save revisions error: #{e.message}") | |
|
181 | 175 | end |
|
182 | h["heads"] = repo_heads.dup | |
|
183 | merge_extra_info(h) | |
|
184 | self.save | |
|
185 | rescue Redmine::Scm::Adapters::CommandFailed => e | |
|
186 | logger.error("save revisions error: #{e.message}") | |
|
187 | 176 | end |
|
188 | 177 | end |
|
189 | 178 | private :save_revisions |
@@ -116,7 +116,7 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
116 | 116 | assert_equal "README", change.path |
|
117 | 117 | assert_equal "A", change.action |
|
118 | 118 | |
|
119 |
assert_equal NUM_HEAD, @repository.extra_info["he |
|
|
119 | assert_equal NUM_HEAD, @repository.extra_info["branches"].size | |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def test_fetch_changesets_incremental |
@@ -124,11 +124,11 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
124 | 124 | @repository.fetch_changesets |
|
125 | 125 | @project.reload |
|
126 | 126 | assert_equal NUM_REV, @repository.changesets.count |
|
127 |
extra_info_ |
|
|
128 | assert_equal NUM_HEAD, extra_info_heads.size | |
|
129 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } | |
|
130 | assert_equal 4, extra_info_heads.size | |
|
131 | ||
|
127 | extra_info_db = @repository.extra_info["branches"] | |
|
128 | assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127", | |
|
129 | extra_info_db["latin-1-path-encoding"]["last_scmid"] | |
|
130 | assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", | |
|
131 | extra_info_db["master"]["last_scmid"] | |
|
132 | 132 | del_revs = [ |
|
133 | 133 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
134 | 134 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
@@ -142,19 +142,20 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
142 | 142 | end |
|
143 | 143 | @project.reload |
|
144 | 144 | cs1 = @repository.changesets |
|
145 |
assert_equal |
|
|
146 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" | |
|
147 | h = {} | |
|
148 | h["heads"] = extra_info_heads | |
|
145 | assert_equal 22, cs1.count | |
|
146 | h = @repository.extra_info.dup | |
|
147 | h["branches"]["master"]["last_scmid"] = | |
|
148 | "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" | |
|
149 | 149 | @repository.merge_extra_info(h) |
|
150 | 150 | @repository.save |
|
151 | 151 | @project.reload |
|
152 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") | |
|
152 | extra_info_db_1 = @repository.extra_info["branches"] | |
|
153 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", | |
|
154 | extra_info_db_1["master"]["last_scmid"] | |
|
155 | ||
|
153 | 156 | @repository.fetch_changesets |
|
154 | 157 | @project.reload |
|
155 | 158 | assert_equal NUM_REV, @repository.changesets.count |
|
156 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size | |
|
157 | assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c") | |
|
158 | 159 | end |
|
159 | 160 | |
|
160 | 161 | def test_fetch_changesets_history_editing |
@@ -162,11 +163,9 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
162 | 163 | @repository.fetch_changesets |
|
163 | 164 | @project.reload |
|
164 | 165 | assert_equal NUM_REV, @repository.changesets.count |
|
165 |
|
|
|
166 | assert_equal NUM_HEAD, extra_info_heads.size | |
|
167 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } | |
|
168 | assert_equal 4, extra_info_heads.size | |
|
169 | ||
|
166 | assert_equal NUM_HEAD, @repository.extra_info["branches"].size | |
|
167 | assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", | |
|
168 | @repository.extra_info["branches"]["master"]["last_scmid"] | |
|
170 | 169 | del_revs = [ |
|
171 | 170 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
172 | 171 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
@@ -190,21 +189,17 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
190 | 189 | @project.reload |
|
191 | 190 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
192 | 191 | |
|
193 | extra_info_heads << "abcd1234efgh" | |
|
194 | h = {} | |
|
195 | h["heads"] = extra_info_heads | |
|
192 | h = @repository.extra_info.dup | |
|
193 | h["branches"]["master"]["last_scmid"] = "abcd1234efgh" | |
|
196 | 194 | @repository.merge_extra_info(h) |
|
197 | 195 | @repository.save |
|
198 | 196 | @project.reload |
|
199 | h1 = @repository.extra_info["heads"].dup | |
|
200 | assert h1.index("abcd1234efgh") | |
|
201 | assert_equal 5, h1.size | |
|
197 | assert_equal "abcd1234efgh", | |
|
198 | @repository.extra_info["branches"]["master"]["last_scmid"] | |
|
202 | 199 | |
|
203 | 200 | @repository.fetch_changesets |
|
204 | 201 | @project.reload |
|
205 | 202 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
206 | h2 = @repository.extra_info["heads"].dup | |
|
207 | assert_equal h1, h2 | |
|
208 | 203 | end |
|
209 | 204 | |
|
210 | 205 | def test_parents |
@@ -251,8 +246,6 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
251 | 246 | @project.reload |
|
252 | 247 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
253 | 248 | |
|
254 | extra_info_heads = @repository.extra_info["heads"].dup | |
|
255 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } | |
|
256 | 249 | del_revs = [ |
|
257 | 250 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
258 | 251 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
@@ -268,19 +261,18 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
268 | 261 | cs1 = @repository.changesets |
|
269 | 262 | assert_equal NUM_REV - 6, cs1.count |
|
270 | 263 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
271 | ||
|
272 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" | |
|
273 | h = {} | |
|
274 | h["heads"] = extra_info_heads | |
|
264 | h = @repository.extra_info.dup | |
|
265 | h["branches"]["master"]["last_scmid"] = | |
|
266 | "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" | |
|
275 | 267 | @repository.merge_extra_info(h) |
|
276 | 268 | @repository.save |
|
277 | 269 | @project.reload |
|
278 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") | |
|
270 | extra_info_db_1 = @repository.extra_info["branches"] | |
|
271 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", | |
|
272 | extra_info_db_1["master"]["last_scmid"] | |
|
273 | ||
|
279 | 274 | @repository.fetch_changesets |
|
280 | @project.reload | |
|
281 | 275 | assert_equal NUM_REV, @repository.changesets.count |
|
282 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size | |
|
283 | ||
|
284 | 276 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
285 | 277 | end |
|
286 | 278 | |
@@ -519,7 +511,7 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
519 | 511 | @repository.fetch_changesets |
|
520 | 512 | @project.reload |
|
521 | 513 | assert_equal NUM_REV, @repository.changesets.count |
|
522 | %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1| | |
|
514 | %w|95488a44bc25f7d1f97d775a31359539ff333a63 95488a44b|.each do |r1| | |
|
523 | 515 | changeset = @repository.find_changeset_by_name(r1) |
|
524 | 516 | assert_nil changeset.previous |
|
525 | 517 | end |
@@ -543,7 +535,7 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
543 | 535 | @repository.fetch_changesets |
|
544 | 536 | @project.reload |
|
545 | 537 | assert_equal NUM_REV, @repository.changesets.count |
|
546 | %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1| | |
|
538 | %w|67e7792ce20ccae2e4bb73eed09bb397819c8834 67e7792ce20cca|.each do |r1| | |
|
547 | 539 | changeset = @repository.find_changeset_by_name(r1) |
|
548 | 540 | assert_nil changeset.next |
|
549 | 541 | end |
General Comments 0
You need to be logged in to leave comments.
Login now