@@ -107,8 +107,7 class Repository::Git < Repository | |||||
107 | # However, Git does not have a sequential commit numbering. |
|
107 | # However, Git does not have a sequential commit numbering. | |
108 | # |
|
108 | # | |
109 | # In order to fetch only new adding revisions, |
|
109 | # In order to fetch only new adding revisions, | |
110 |
# Redmine needs to |
|
110 | # Redmine needs to save "heads". | |
111 | # Branch "last_scmid" is for this requirement. |
|
|||
112 | # |
|
111 | # | |
113 | # In Git and Mercurial, revisions are not in date order. |
|
112 | # In Git and Mercurial, revisions are not in date order. | |
114 | # Redmine Mercurial fixed issues. |
|
113 | # Redmine Mercurial fixed issues. | |
@@ -131,9 +130,17 class Repository::Git < Repository | |||||
131 | def fetch_changesets |
|
130 | def fetch_changesets | |
132 | scm_brs = branches |
|
131 | scm_brs = branches | |
133 | return if scm_brs.nil? || scm_brs.empty? |
|
132 | return if scm_brs.nil? || scm_brs.empty? | |
|
133 | ||||
134 | h1 = extra_info || {} |
|
134 | h1 = extra_info || {} | |
135 | h = h1.dup |
|
135 | h = h1.dup | |
136 | h["branches"] ||= {} |
|
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 | ||||
137 | h["db_consistent"] ||= {} |
|
144 | h["db_consistent"] ||= {} | |
138 | if changesets.count == 0 |
|
145 | if changesets.count == 0 | |
139 | h["db_consistent"]["ordering"] = 1 |
|
146 | h["db_consistent"]["ordering"] = 1 | |
@@ -144,31 +151,18 class Repository::Git < Repository | |||||
144 | merge_extra_info(h) |
|
151 | merge_extra_info(h) | |
145 | self.save |
|
152 | self.save | |
146 | end |
|
153 | end | |
147 |
save_revisions(h, |
|
154 | save_revisions(prev_db_heads, repo_heads) | |
148 | end |
|
155 | end | |
149 |
|
156 | |||
150 |
def save_revisions(h, |
|
157 | def save_revisions(prev_db_heads, repo_heads) | |
151 | # Remember what revisions we already processed (in any branches) |
|
158 | h = {} | |
152 | all_revisions = [] |
|
159 | opts = {} | |
153 | scm_brs.each do |br1| |
|
160 | opts[:reverse] = true | |
154 | br = br1.to_s |
|
161 | opts[:excludes] = prev_db_heads | |
155 | last_revision = nil |
|
162 | opts[:includes] = repo_heads | |
156 | from_scmid = nil |
|
|||
157 | from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br] |
|
|||
158 | h["branches"][br] ||= {} |
|
|||
159 |
|
||||
160 | revisions = scm.revisions('', from_scmid, br, {:reverse => true}) |
|
|||
161 | next if revisions.blank? |
|
|||
162 |
|
||||
163 | # Remember the last commit id here, before we start removing revisions from the array. |
|
|||
164 | # We'll do that for optimization, but it also means, that we may lose even all revisions. |
|
|||
165 | last_revision = revisions.last |
|
|||
166 |
|
163 | |||
167 | # remove revisions that we have already processed (possibly in other branches) |
|
164 | revisions = scm.revisions('', nil, nil, opts) | |
168 | revisions.reject!{|r| all_revisions.include?(r.scmid)} |
|
165 | return if revisions.blank? | |
169 | # add revisions that we are to parse now to 'all processed revisions' |
|
|||
170 | # (this equals to a union, because we executed diff above) |
|
|||
171 | all_revisions += revisions.map{|r| r.scmid} |
|
|||
172 |
|
166 | |||
173 | # Make the search for existing revisions in the database in a more sufficient manner |
|
167 | # Make the search for existing revisions in the database in a more sufficient manner | |
174 | # This is replacing the one-after-one queries. |
|
168 | # This is replacing the one-after-one queries. | |
@@ -206,18 +200,11 class Repository::Git < Repository | |||||
206 | parents.each do |ch, chparents| |
|
200 | parents.each do |ch, chparents| | |
207 | ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact |
|
201 | ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact | |
208 | end |
|
202 | end | |
209 | # saving the last scmid was moved from here, because we won't come in here, |
|
|||
210 | # if the revision was already added for another branch |
|
|||
211 | end |
|
203 | end | |
212 | end |
|
204 | end | |
213 |
|
205 | h["heads"] = repo_heads.dup | ||
214 | # save the data about the last revision for this branch |
|
206 | merge_extra_info(h) | |
215 | unless last_revision.nil? |
|
207 | self.save | |
216 | h["branches"][br]["last_scmid"] = last_revision.scmid |
|
|||
217 | merge_extra_info(h) |
|
|||
218 | self.save |
|
|||
219 | end |
|
|||
220 | end |
|
|||
221 | end |
|
208 | end | |
222 | private :save_revisions |
|
209 | private :save_revisions | |
223 |
|
210 |
@@ -116,7 +116,7 class RepositoryGitTest < ActiveSupport::TestCase | |||||
116 | assert_equal "README", change.path |
|
116 | assert_equal "README", change.path | |
117 | assert_equal "A", change.action |
|
117 | assert_equal "A", change.action | |
118 |
|
118 | |||
119 |
assert_equal NUM_HEAD, @repository.extra_info[" |
|
119 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | def test_fetch_changesets_incremental |
|
122 | def test_fetch_changesets_incremental | |
@@ -124,11 +124,11 class RepositoryGitTest < ActiveSupport::TestCase | |||||
124 | @repository.fetch_changesets |
|
124 | @repository.fetch_changesets | |
125 | @project.reload |
|
125 | @project.reload | |
126 | assert_equal NUM_REV, @repository.changesets.count |
|
126 | assert_equal NUM_REV, @repository.changesets.count | |
127 |
extra_info_ |
|
127 | extra_info_heads = @repository.extra_info["heads"].dup | |
128 | assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127", |
|
128 | assert_equal NUM_HEAD, extra_info_heads.size | |
129 | extra_info_db["latin-1-path-encoding"]["last_scmid"] |
|
129 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } | |
130 | assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
130 | assert_equal 4, extra_info_heads.size | |
131 | extra_info_db["master"]["last_scmid"] |
|
131 | ||
132 | del_revs = [ |
|
132 | del_revs = [ | |
133 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
133 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", | |
134 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
134 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", | |
@@ -142,20 +142,19 class RepositoryGitTest < ActiveSupport::TestCase | |||||
142 | end |
|
142 | end | |
143 | @project.reload |
|
143 | @project.reload | |
144 | cs1 = @repository.changesets |
|
144 | cs1 = @repository.changesets | |
145 |
assert_equal |
|
145 | assert_equal NUM_REV - 6, cs1.count | |
146 | h = @repository.extra_info.dup |
|
146 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" | |
147 | h["branches"]["master"]["last_scmid"] = |
|
147 | h = {} | |
148 | "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" |
|
148 | h["heads"] = extra_info_heads | |
149 | @repository.merge_extra_info(h) |
|
149 | @repository.merge_extra_info(h) | |
150 | @repository.save |
|
150 | @repository.save | |
151 | @project.reload |
|
151 | @project.reload | |
152 | extra_info_db_1 = @repository.extra_info["branches"] |
|
152 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") | |
153 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", |
|
|||
154 | extra_info_db_1["master"]["last_scmid"] |
|
|||
155 |
|
||||
156 | @repository.fetch_changesets |
|
153 | @repository.fetch_changesets | |
157 | @project.reload |
|
154 | @project.reload | |
158 | assert_equal NUM_REV, @repository.changesets.count |
|
155 | 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") | |||
159 | end |
|
158 | end | |
160 |
|
159 | |||
161 | def test_fetch_changesets_history_editing |
|
160 | def test_fetch_changesets_history_editing | |
@@ -163,9 +162,11 class RepositoryGitTest < ActiveSupport::TestCase | |||||
163 | @repository.fetch_changesets |
|
162 | @repository.fetch_changesets | |
164 | @project.reload |
|
163 | @project.reload | |
165 | assert_equal NUM_REV, @repository.changesets.count |
|
164 | assert_equal NUM_REV, @repository.changesets.count | |
166 |
|
|
165 | extra_info_heads = @repository.extra_info["heads"].dup | |
167 | assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
166 | assert_equal NUM_HEAD, extra_info_heads.size | |
168 | @repository.extra_info["branches"]["master"]["last_scmid"] |
|
167 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } | |
|
168 | assert_equal 4, extra_info_heads.size | |||
|
169 | ||||
169 | del_revs = [ |
|
170 | del_revs = [ | |
170 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
171 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", | |
171 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
172 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", | |
@@ -189,17 +190,21 class RepositoryGitTest < ActiveSupport::TestCase | |||||
189 | @project.reload |
|
190 | @project.reload | |
190 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
191 | assert_equal NUM_REV - 5, @repository.changesets.count | |
191 |
|
192 | |||
192 | h = @repository.extra_info.dup |
|
193 | extra_info_heads << "abcd1234efgh" | |
193 | h["branches"]["master"]["last_scmid"] = "abcd1234efgh" |
|
194 | h = {} | |
|
195 | h["heads"] = extra_info_heads | |||
194 | @repository.merge_extra_info(h) |
|
196 | @repository.merge_extra_info(h) | |
195 | @repository.save |
|
197 | @repository.save | |
196 | @project.reload |
|
198 | @project.reload | |
197 | assert_equal "abcd1234efgh", |
|
199 | h1 = @repository.extra_info["heads"].dup | |
198 | @repository.extra_info["branches"]["master"]["last_scmid"] |
|
200 | assert h1.index("abcd1234efgh") | |
|
201 | assert_equal 5, h1.size | |||
199 |
|
202 | |||
200 | @repository.fetch_changesets |
|
203 | @repository.fetch_changesets | |
201 | @project.reload |
|
204 | @project.reload | |
202 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
205 | assert_equal NUM_REV - 5, @repository.changesets.count | |
|
206 | h2 = @repository.extra_info["heads"].dup | |||
|
207 | assert_equal h1, h2 | |||
203 | end |
|
208 | end | |
204 |
|
209 | |||
205 | def test_parents |
|
210 | def test_parents | |
@@ -246,6 +251,8 class RepositoryGitTest < ActiveSupport::TestCase | |||||
246 | @project.reload |
|
251 | @project.reload | |
247 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
252 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] | |
248 |
|
253 | |||
|
254 | extra_info_heads = @repository.extra_info["heads"].dup | |||
|
255 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } | |||
249 | del_revs = [ |
|
256 | del_revs = [ | |
250 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
257 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", | |
251 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
258 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", | |
@@ -261,18 +268,19 class RepositoryGitTest < ActiveSupport::TestCase | |||||
261 | cs1 = @repository.changesets |
|
268 | cs1 = @repository.changesets | |
262 | assert_equal NUM_REV - 6, cs1.count |
|
269 | assert_equal NUM_REV - 6, cs1.count | |
263 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
270 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] | |
264 | h = @repository.extra_info.dup |
|
271 | ||
265 | h["branches"]["master"]["last_scmid"] = |
|
272 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" | |
266 | "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" |
|
273 | h = {} | |
|
274 | h["heads"] = extra_info_heads | |||
267 | @repository.merge_extra_info(h) |
|
275 | @repository.merge_extra_info(h) | |
268 | @repository.save |
|
276 | @repository.save | |
269 | @project.reload |
|
277 | @project.reload | |
270 | extra_info_db_1 = @repository.extra_info["branches"] |
|
278 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") | |
271 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", |
|
|||
272 | extra_info_db_1["master"]["last_scmid"] |
|
|||
273 |
|
||||
274 | @repository.fetch_changesets |
|
279 | @repository.fetch_changesets | |
|
280 | @project.reload | |||
275 | assert_equal NUM_REV, @repository.changesets.count |
|
281 | assert_equal NUM_REV, @repository.changesets.count | |
|
282 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size | |||
|
283 | ||||
276 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
284 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] | |
277 | end |
|
285 | end | |
278 |
|
286 | |||
@@ -511,7 +519,7 class RepositoryGitTest < ActiveSupport::TestCase | |||||
511 | @repository.fetch_changesets |
|
519 | @repository.fetch_changesets | |
512 | @project.reload |
|
520 | @project.reload | |
513 | assert_equal NUM_REV, @repository.changesets.count |
|
521 | assert_equal NUM_REV, @repository.changesets.count | |
514 | %w|95488a44bc25f7d1f97d775a31359539ff333a63 95488a44b|.each do |r1| |
|
522 | %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1| | |
515 | changeset = @repository.find_changeset_by_name(r1) |
|
523 | changeset = @repository.find_changeset_by_name(r1) | |
516 | assert_nil changeset.previous |
|
524 | assert_nil changeset.previous | |
517 | end |
|
525 | end | |
@@ -535,7 +543,7 class RepositoryGitTest < ActiveSupport::TestCase | |||||
535 | @repository.fetch_changesets |
|
543 | @repository.fetch_changesets | |
536 | @project.reload |
|
544 | @project.reload | |
537 | assert_equal NUM_REV, @repository.changesets.count |
|
545 | assert_equal NUM_REV, @repository.changesets.count | |
538 | %w|67e7792ce20ccae2e4bb73eed09bb397819c8834 67e7792ce20cca|.each do |r1| |
|
546 | %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1| | |
539 | changeset = @repository.find_changeset_by_name(r1) |
|
547 | changeset = @repository.find_changeset_by_name(r1) | |
540 | assert_nil changeset.next |
|
548 | assert_nil changeset.next | |
541 | end |
|
549 | end |
General Comments 0
You need to be logged in to leave comments.
Login now