@@ -103,39 +103,26 class Repository::Git < Repository | |||||
103 | # |
|
103 | # | |
104 | # But, Git 1.7.3.4 does not support --reverse with -n or --skip. |
|
104 | # But, Git 1.7.3.4 does not support --reverse with -n or --skip. | |
105 | # |
|
105 | # | |
106 | # With SCM's that have a sequential commit numbering, redmine is able to be |
|
|||
107 | # clever and only fetch changesets going forward from the most recent one |
|
|||
108 | # it knows about. |
|
|||
109 | # However, with git, you never know if people have merged |
|
|||
110 | # commits into the middle of the repository history, so we should parse |
|
|||
111 | # the entire log. |
|
|||
112 | # |
|
|||
113 | # Since it's way too slow for large repositories, |
|
|||
114 | # we only parse 1 week before the last known commit. |
|
|||
115 | # |
|
|||
116 | # The repository can still be fully reloaded by calling #clear_changesets |
|
106 | # The repository can still be fully reloaded by calling #clear_changesets | |
117 | # before fetching changesets (eg. for offline resync) |
|
107 | # before fetching changesets (eg. for offline resync) | |
118 | def fetch_changesets |
|
108 | def fetch_changesets | |
119 | c = changesets.find(:first, :order => 'committed_on DESC') |
|
109 | scm_brs = branches | |
120 | since = (c ? c.committed_on - 7.days : nil) |
|
110 | return if scm_brs.nil? || scm_brs.empty? | |
121 |
|
111 | h = extra_info || {} | ||
122 | revisions = scm.revisions('', nil, nil, {:all => true, :since => since, :reverse => true}) |
|
112 | h["branches"] ||= {} | |
123 | return if revisions.nil? || revisions.empty? |
|
113 | scm_brs.each do |br| | |
124 |
|
114 | from_scmid = nil | ||
125 | recent_changesets = changesets.find(:all, :conditions => ['committed_on >= ?', since]) |
|
115 | from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br] | |
126 |
|
116 | h["branches"][br] ||= {} | ||
127 | # Clean out revisions that are no longer in git |
|
117 | scm.revisions('', from_scmid, br, {:reverse => true}) do |rev| | |
128 | recent_changesets.each {|c| c.destroy unless revisions.detect {|r| r.scmid.to_s == c.scmid.to_s }} |
|
118 | db_rev = find_changeset_by_name(rev.revision) | |
129 |
|
||||
130 | # Subtract revisions that redmine already knows about |
|
|||
131 | recent_revisions = recent_changesets.map{|c| c.scmid} |
|
|||
132 | revisions.reject!{|r| recent_revisions.include?(r.scmid)} |
|
|||
133 |
|
||||
134 | # Save the remaining ones to the database |
|
|||
135 | unless revisions.nil? |
|
|||
136 | revisions.each do |rev| |
|
|||
137 | transaction do |
|
119 | transaction do | |
138 | save_revision(rev) |
|
120 | if db_rev.nil? | |
|
121 | save_revision(rev) | |||
|
122 | end | |||
|
123 | h["branches"][br]["last_scmid"] = rev.scmid | |||
|
124 | merge_extra_info(h) | |||
|
125 | self.save | |||
139 | end |
|
126 | end | |
140 | end |
|
127 | end | |
141 | end |
|
128 | end |
@@ -55,6 +55,8 class RepositoryGitTest < ActiveSupport::TestCase | |||||
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def test_fetch_changesets_from_scratch |
|
57 | def test_fetch_changesets_from_scratch | |
|
58 | assert_nil @repository.extra_info | |||
|
59 | ||||
58 | @repository.fetch_changesets |
|
60 | @repository.fetch_changesets | |
59 | @repository.reload |
|
61 | @repository.reload | |
60 |
|
62 | |||
@@ -74,30 +76,45 class RepositoryGitTest < ActiveSupport::TestCase | |||||
74 | change = commit.changes.sort_by(&:path).first |
|
76 | change = commit.changes.sort_by(&:path).first | |
75 | assert_equal "README", change.path |
|
77 | assert_equal "README", change.path | |
76 | assert_equal "A", change.action |
|
78 | assert_equal "A", change.action | |
|
79 | ||||
|
80 | assert_equal 4, @repository.extra_info["branches"].size | |||
77 | end |
|
81 | end | |
78 |
|
82 | |||
79 | def test_fetch_changesets_incremental |
|
83 | def test_fetch_changesets_incremental | |
80 | @repository.fetch_changesets |
|
84 | @repository.fetch_changesets | |
81 |
|
85 | @repository.reload | ||
82 | # Remove the latest changesets |
|
86 | assert_equal 21, @repository.changesets.count | |
83 |
@repository.changes |
|
87 | assert_equal 33, @repository.changes.count | |
84 | :all, |
|
88 | extra_info_db = @repository.extra_info["branches"] | |
85 | :order => 'committed_on DESC', |
|
89 | assert_equal 4, extra_info_db.size | |
86 | :limit => 8).each(&:destroy) |
|
90 | assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127", | |
|
91 | extra_info_db["latin-1-path-encoding"]["last_scmid"] | |||
|
92 | assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", | |||
|
93 | extra_info_db["master"]["last_scmid"] | |||
|
94 | ||||
|
95 | del_revs = [ | |||
|
96 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", | |||
|
97 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", | |||
|
98 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", | |||
|
99 | "deff712f05a90d96edbd70facc47d944be5897e3", | |||
|
100 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", | |||
|
101 | "7e61ac704deecde634b51e59daa8110435dcb3da", | |||
|
102 | ] | |||
|
103 | @repository.changesets.each do |rev| | |||
|
104 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } | |||
|
105 | end | |||
87 | @repository.reload |
|
106 | @repository.reload | |
88 | cs1 = @repository.changesets |
|
107 | cs1 = @repository.changesets | |
89 |
assert_equal 1 |
|
108 | assert_equal 15, cs1.count | |
90 |
|
109 | h = @repository.extra_info.dup | ||
91 | rev_a_commit = @repository.changesets.find( |
|
110 | h["branches"]["master"]["last_scmid"] = | |
92 | :first, |
|
111 | "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" | |
93 | :order => 'committed_on DESC') |
|
112 | @repository.merge_extra_info(h) | |
94 | assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision |
|
113 | @repository.save | |
95 | # Mon Jul 5 22:34:26 2010 +0200 |
|
114 | @repository.reload | |
96 | rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26) |
|
115 | extra_info_db_1 = @repository.extra_info["branches"] | |
97 | assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid |
|
116 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", | |
98 | assert_equal rev_a_committed_on, rev_a_commit.committed_on |
|
117 | extra_info_db_1["master"]["last_scmid"] | |
99 | latest_rev = @repository.latest_changeset |
|
|||
100 | assert_equal rev_a_committed_on, latest_rev.committed_on |
|
|||
101 |
|
118 | |||
102 | @repository.fetch_changesets |
|
119 | @repository.fetch_changesets | |
103 | assert_equal 21, @repository.changesets.count |
|
120 | assert_equal 21, @repository.changesets.count | |
@@ -318,7 +335,7 class RepositoryGitTest < ActiveSupport::TestCase | |||||
318 | def test_next_nil |
|
335 | def test_next_nil | |
319 | @repository.fetch_changesets |
|
336 | @repository.fetch_changesets | |
320 | @repository.reload |
|
337 | @repository.reload | |
321 | %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| |
|
338 | %w|67e7792ce20ccae2e4bb73eed09bb397819c8834 67e7792ce20cca|.each do |r1| | |
322 | changeset = @repository.find_changeset_by_name(r1) |
|
339 | changeset = @repository.find_changeset_by_name(r1) | |
323 | assert_nil changeset.next |
|
340 | assert_nil changeset.next | |
324 | end |
|
341 | end |
General Comments 0
You need to be logged in to leave comments.
Login now