@@ -107,8 +107,7 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 |
|
|
111 | # Branch "last_scmid" is for this requirement. | |
|
110 | # Redmine needs to save "heads". | |
|
112 | 111 | # |
|
113 | 112 | # In Git and Mercurial, revisions are not in date order. |
|
114 | 113 | # Redmine Mercurial fixed issues. |
@@ -131,9 +130,17 class Repository::Git < Repository | |||
|
131 | 130 | def fetch_changesets |
|
132 | 131 | scm_brs = branches |
|
133 | 132 | return if scm_brs.nil? || scm_brs.empty? |
|
133 | ||
|
134 | 134 | h1 = extra_info || {} |
|
135 | 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 | 144 | h["db_consistent"] ||= {} |
|
138 | 145 | if changesets.count == 0 |
|
139 | 146 | h["db_consistent"]["ordering"] = 1 |
@@ -144,35 +151,39 class Repository::Git < Repository | |||
|
144 | 151 | merge_extra_info(h) |
|
145 | 152 | self.save |
|
146 | 153 | end |
|
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 | |
|
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 | |
|
167 | 174 | end |
|
168 | h["branches"][br]["last_scmid"] = rev.scmid | |
|
169 | merge_extra_info(h) | |
|
170 | self.save | |
|
171 | 175 | end |
|
176 | h["heads"] = prev_db_heads.dup | |
|
177 | h["heads"] << rev.scmid | |
|
178 | merge_extra_info(h) | |
|
179 | self.save | |
|
172 | 180 | end |
|
173 | rescue Redmine::Scm::Adapters::CommandFailed => e | |
|
174 | logger.error("save revisions error: #{e.message}") | |
|
175 | 181 | 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}") | |
|
176 | 187 | end |
|
177 | 188 | end |
|
178 | 189 | private :save_revisions |
@@ -87,7 +87,7 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
87 | 87 | assert_equal "README", change.path |
|
88 | 88 | assert_equal "A", change.action |
|
89 | 89 | |
|
90 |
assert_equal 5, @repository.extra_info[" |
|
|
90 | assert_equal 5, @repository.extra_info["heads"].size | |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | def test_fetch_changesets_incremental |
@@ -95,11 +95,10 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
95 | 95 | @repository.fetch_changesets |
|
96 | 96 | @project.reload |
|
97 | 97 | assert_equal NUM_REV, @repository.changesets.count |
|
98 |
extra_info_ |
|
|
99 | assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127", | |
|
100 | extra_info_db["latin-1-path-encoding"]["last_scmid"] | |
|
101 | assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", | |
|
102 | extra_info_db["master"]["last_scmid"] | |
|
98 | extra_info_heads = @repository.extra_info["heads"].dup | |
|
99 | assert_equal 5, extra_info_heads.size | |
|
100 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } | |
|
101 | assert_equal 4, extra_info_heads.size | |
|
103 | 102 | |
|
104 | 103 | del_revs = [ |
|
105 | 104 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
@@ -114,20 +113,19 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
114 | 113 | end |
|
115 | 114 | @project.reload |
|
116 | 115 | cs1 = @repository.changesets |
|
117 |
assert_equal |
|
|
118 | h = @repository.extra_info.dup | |
|
119 | h["branches"]["master"]["last_scmid"] = | |
|
120 | "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" | |
|
116 | assert_equal NUM_REV - 6, cs1.count | |
|
117 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" | |
|
118 | h = {} | |
|
119 | h["heads"] = extra_info_heads | |
|
121 | 120 | @repository.merge_extra_info(h) |
|
122 | 121 | @repository.save |
|
123 | 122 | @project.reload |
|
124 | extra_info_db_1 = @repository.extra_info["branches"] | |
|
125 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", | |
|
126 | extra_info_db_1["master"]["last_scmid"] | |
|
127 | ||
|
123 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") | |
|
128 | 124 | @repository.fetch_changesets |
|
129 | 125 | @project.reload |
|
130 | 126 | assert_equal NUM_REV, @repository.changesets.count |
|
127 | assert_equal 5, @repository.extra_info["heads"].size | |
|
128 | assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c") | |
|
131 | 129 | end |
|
132 | 130 | |
|
133 | 131 | def test_fetch_changesets_history_editing |
@@ -135,9 +133,10 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
135 | 133 | @repository.fetch_changesets |
|
136 | 134 | @project.reload |
|
137 | 135 | assert_equal NUM_REV, @repository.changesets.count |
|
138 |
|
|
|
139 | assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", | |
|
140 | @repository.extra_info["branches"]["master"]["last_scmid"] | |
|
136 | extra_info_heads = @repository.extra_info["heads"].dup | |
|
137 | assert_equal 5, extra_info_heads.size | |
|
138 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } | |
|
139 | assert_equal 4, extra_info_heads.size | |
|
141 | 140 | |
|
142 | 141 | del_revs = [ |
|
143 | 142 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
@@ -162,17 +161,21 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
162 | 161 | @project.reload |
|
163 | 162 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
164 | 163 | |
|
165 | h = @repository.extra_info.dup | |
|
166 | h["branches"]["master"]["last_scmid"] = "abcd1234efgh" | |
|
164 | extra_info_heads << "abcd1234efgh" | |
|
165 | h = {} | |
|
166 | h["heads"] = extra_info_heads | |
|
167 | 167 | @repository.merge_extra_info(h) |
|
168 | 168 | @repository.save |
|
169 | 169 | @project.reload |
|
170 | assert_equal "abcd1234efgh", | |
|
171 | @repository.extra_info["branches"]["master"]["last_scmid"] | |
|
170 | h1 = @repository.extra_info["heads"].dup | |
|
171 | assert h1.index("abcd1234efgh") | |
|
172 | assert_equal 5, h1.size | |
|
172 | 173 | |
|
173 | 174 | @repository.fetch_changesets |
|
174 | 175 | @project.reload |
|
175 | 176 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
177 | h2 = @repository.extra_info["heads"].dup | |
|
178 | assert_equal h1, h2 | |
|
176 | 179 | end |
|
177 | 180 | |
|
178 | 181 | def test_parents |
@@ -216,6 +219,8 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
216 | 219 | @project.reload |
|
217 | 220 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
218 | 221 | |
|
222 | extra_info_heads = @repository.extra_info["heads"].dup | |
|
223 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } | |
|
219 | 224 | del_revs = [ |
|
220 | 225 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
221 | 226 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
@@ -231,18 +236,19 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
231 | 236 | cs1 = @repository.changesets |
|
232 | 237 | assert_equal NUM_REV - 6, cs1.count |
|
233 | 238 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
234 | h = @repository.extra_info.dup | |
|
235 | h["branches"]["master"]["last_scmid"] = | |
|
236 | "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" | |
|
239 | ||
|
240 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" | |
|
241 | h = {} | |
|
242 | h["heads"] = extra_info_heads | |
|
237 | 243 | @repository.merge_extra_info(h) |
|
238 | 244 | @repository.save |
|
239 | 245 | @project.reload |
|
240 | extra_info_db_1 = @repository.extra_info["branches"] | |
|
241 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", | |
|
242 | extra_info_db_1["master"]["last_scmid"] | |
|
243 | ||
|
246 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") | |
|
244 | 247 | @repository.fetch_changesets |
|
248 | @project.reload | |
|
245 | 249 | assert_equal NUM_REV, @repository.changesets.count |
|
250 | assert_equal 5, @repository.extra_info["heads"].size | |
|
251 | ||
|
246 | 252 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
247 | 253 | end |
|
248 | 254 | |
@@ -481,7 +487,7 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
481 | 487 | @repository.fetch_changesets |
|
482 | 488 | @project.reload |
|
483 | 489 | assert_equal NUM_REV, @repository.changesets.count |
|
484 | %w|95488a44bc25f7d1f97d775a31359539ff333a63 95488a44b|.each do |r1| | |
|
490 | %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1| | |
|
485 | 491 | changeset = @repository.find_changeset_by_name(r1) |
|
486 | 492 | assert_nil changeset.previous |
|
487 | 493 | end |
@@ -505,7 +511,7 class RepositoryGitTest < ActiveSupport::TestCase | |||
|
505 | 511 | @repository.fetch_changesets |
|
506 | 512 | @project.reload |
|
507 | 513 | assert_equal NUM_REV, @repository.changesets.count |
|
508 | %w|67e7792ce20ccae2e4bb73eed09bb397819c8834 67e7792ce20cca|.each do |r1| | |
|
514 | %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1| | |
|
509 | 515 | changeset = @repository.find_changeset_by_name(r1) |
|
510 | 516 | assert_nil changeset.next |
|
511 | 517 | end |
General Comments 0
You need to be logged in to leave comments.
Login now