##// END OF EJS Templates
fix typo of app/models/repository/cvs.rb...
Toshi MARUYAMA -
r12853:6eaba1137a68
parent child
Show More
@@ -1,205 +1,205
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'redmine/scm/adapters/cvs_adapter'
19 19 require 'digest/sha1'
20 20
21 21 class Repository::Cvs < Repository
22 22 validates_presence_of :url, :root_url, :log_encoding
23 23
24 24 safe_attributes 'root_url',
25 25 :if => lambda {|repository, user| repository.new_record?}
26 26
27 27 def self.human_attribute_name(attribute_key_name, *args)
28 28 attr_name = attribute_key_name.to_s
29 29 if attr_name == "root_url"
30 30 attr_name = "cvsroot"
31 31 elsif attr_name == "url"
32 32 attr_name = "cvs_module"
33 33 end
34 34 super(attr_name, *args)
35 35 end
36 36
37 37 def self.scm_adapter_class
38 38 Redmine::Scm::Adapters::CvsAdapter
39 39 end
40 40
41 41 def self.scm_name
42 42 'CVS'
43 43 end
44 44
45 45 def entry(path=nil, identifier=nil)
46 46 rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
47 47 scm.entry(path, rev.nil? ? nil : rev.committed_on)
48 48 end
49 49
50 50 def scm_entries(path=nil, identifier=nil)
51 51 rev = nil
52 52 if ! identifier.nil?
53 53 rev = changesets.find_by_revision(identifier)
54 54 return nil if rev.nil?
55 55 end
56 56 entries = scm.entries(path, rev.nil? ? nil : rev.committed_on)
57 57 if entries
58 58 entries.each() do |entry|
59 59 if ( ! entry.lastrev.nil? ) && ( ! entry.lastrev.revision.nil? )
60 60 change = filechanges.find_by_revision_and_path(
61 61 entry.lastrev.revision,
62 62 scm.with_leading_slash(entry.path) )
63 63 if change
64 64 entry.lastrev.identifier = change.changeset.revision
65 65 entry.lastrev.revision = change.changeset.revision
66 66 entry.lastrev.author = change.changeset.committer
67 67 # entry.lastrev.branch = change.branch
68 68 end
69 69 end
70 70 end
71 71 end
72 72 entries
73 73 end
74 74 protected :scm_entries
75 75
76 76 def cat(path, identifier=nil)
77 77 rev = nil
78 78 if ! identifier.nil?
79 79 rev = changesets.find_by_revision(identifier)
80 80 return nil if rev.nil?
81 81 end
82 82 scm.cat(path, rev.nil? ? nil : rev.committed_on)
83 83 end
84 84
85 85 def annotate(path, identifier=nil)
86 86 rev = nil
87 87 if ! identifier.nil?
88 88 rev = changesets.find_by_revision(identifier)
89 89 return nil if rev.nil?
90 90 end
91 91 scm.annotate(path, rev.nil? ? nil : rev.committed_on)
92 92 end
93 93
94 94 def diff(path, rev, rev_to)
95 95 # convert rev to revision. CVS can't handle changesets here
96 96 diff=[]
97 97 changeset_from = changesets.find_by_revision(rev)
98 98 if rev_to.to_i > 0
99 99 changeset_to = changesets.find_by_revision(rev_to)
100 100 end
101 101 changeset_from.filechanges.each() do |change_from|
102 102 revision_from = nil
103 103 revision_to = nil
104 104 if path.nil? || (change_from.path.starts_with? scm.with_leading_slash(path))
105 105 revision_from = change_from.revision
106 106 end
107 107 if revision_from
108 108 if changeset_to
109 109 changeset_to.filechanges.each() do |change_to|
110 110 revision_to = change_to.revision if change_to.path == change_from.path
111 111 end
112 112 end
113 113 unless revision_to
114 114 revision_to = scm.get_previous_revision(revision_from)
115 115 end
116 116 file_diff = scm.diff(change_from.path, revision_from, revision_to)
117 117 diff = diff + file_diff unless file_diff.nil?
118 118 end
119 119 end
120 120 return diff
121 121 end
122 122
123 123 def fetch_changesets
124 124 # some nifty bits to introduce a commit-id with cvs
125 125 # natively cvs doesn't provide any kind of changesets,
126 126 # there is only a revision per file.
127 127 # we now take a guess using the author, the commitlog and the commit-date.
128 128
129 129 # last one is the next step to take. the commit-date is not equal for all
130 130 # commits in one changeset. cvs update the commit-date when the *,v file was touched. so
131 131 # we use a small delta here, to merge all changes belonging to _one_ changeset
132 132 time_delta = 10.seconds
133 133 fetch_since = latest_changeset ? latest_changeset.committed_on : nil
134 134 transaction do
135 135 tmp_rev_num = 1
136 136 scm.revisions('', fetch_since, nil, :log_encoding => repo_log_encoding) do |revision|
137 137 # only add the change to the database, if it doen't exists. the cvs log
138 138 # is not exclusive at all.
139 139 tmp_time = revision.time.clone
140 140 unless filechanges.find_by_path_and_revision(
141 141 scm.with_leading_slash(revision.paths[0][:path]),
142 142 revision.paths[0][:revision]
143 143 )
144 144 cmt = Changeset.normalize_comments(revision.message, repo_log_encoding)
145 145 author_utf8 = Changeset.to_utf8(revision.author, repo_log_encoding)
146 146 cs = changesets.where(
147 147 :committed_on => tmp_time - time_delta .. tmp_time + time_delta,
148 148 :committer => author_utf8,
149 149 :comments => cmt
150 150 ).first
151 151 # create a new changeset....
152 152 unless cs
153 # we use a temporaray revision number here (just for inserting)
153 # we use a temporary revision number here (just for inserting)
154 154 # later on, we calculate a continous positive number
155 155 tmp_time2 = tmp_time.clone.gmtime
156 156 branch = revision.paths[0][:branch]
157 157 scmid = branch + "-" + tmp_time2.strftime("%Y%m%d-%H%M%S")
158 158 cs = Changeset.create(:repository => self,
159 159 :revision => "tmp#{tmp_rev_num}",
160 160 :scmid => scmid,
161 161 :committer => revision.author,
162 162 :committed_on => tmp_time,
163 163 :comments => revision.message)
164 164 tmp_rev_num += 1
165 165 end
166 166 # convert CVS-File-States to internal Action-abbrevations
167 167 # default action is (M)odified
168 168 action = "M"
169 169 if revision.paths[0][:action] == "Exp" && revision.paths[0][:revision] == "1.1"
170 170 action = "A" # add-action always at first revision (= 1.1)
171 171 elsif revision.paths[0][:action] == "dead"
172 172 action = "D" # dead-state is similar to Delete
173 173 end
174 174 Change.create(
175 175 :changeset => cs,
176 176 :action => action,
177 177 :path => scm.with_leading_slash(revision.paths[0][:path]),
178 178 :revision => revision.paths[0][:revision],
179 179 :branch => revision.paths[0][:branch]
180 180 )
181 181 end
182 182 end
183 183
184 184 # Renumber new changesets in chronological order
185 185 Changeset.
186 186 order('committed_on ASC, id ASC').
187 187 where("repository_id = ? AND revision LIKE 'tmp%'", id).
188 188 each do |changeset|
189 189 changeset.update_attribute :revision, next_revision_number
190 190 end
191 191 end # transaction
192 192 @current_revision_number = nil
193 193 end
194 194
195 195 private
196 196
197 197 # Returns the next revision number to assign to a CVS changeset
198 198 def next_revision_number
199 199 # Need to retrieve existing revision numbers to sort them as integers
200 200 sql = "SELECT revision FROM #{Changeset.table_name} "
201 201 sql << "WHERE repository_id = #{id} AND revision NOT LIKE 'tmp%'"
202 202 @current_revision_number ||= (connection.select_values(sql).collect(&:to_i).max || 0)
203 203 @current_revision_number += 1
204 204 end
205 205 end
General Comments 0
You need to be logged in to leave comments. Login now