##// END OF EJS Templates
scm: cvs: override annotate() in model....
Toshi MARUYAMA -
r5290:0a0819f81ee3
parent child
Show More
@@ -1,189 +1,198
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 ATTRIBUTE_KEY_NAMES = {
25 25 "url" => "CVSROOT",
26 26 "root_url" => "Module",
27 27 "log_encoding" => "Commit messages encoding",
28 28 }
29 29 def self.human_attribute_name(attribute_key_name)
30 30 ATTRIBUTE_KEY_NAMES[attribute_key_name] || super
31 31 end
32 32
33 33 def self.scm_adapter_class
34 34 Redmine::Scm::Adapters::CvsAdapter
35 35 end
36 36
37 37 def self.scm_name
38 38 'CVS'
39 39 end
40 40
41 41 def entry(path=nil, identifier=nil)
42 42 rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
43 43 scm.entry(path, rev.nil? ? nil : rev.committed_on)
44 44 end
45 45
46 46 def entries(path=nil, identifier=nil)
47 47 rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
48 48 entries = scm.entries(path, rev.nil? ? nil : rev.committed_on)
49 49 if entries
50 50 entries.each() do |entry|
51 51 if ( ! entry.lastrev.nil? ) && ( ! entry.lastrev.revision.nil? )
52 52 change=changes.find_by_revision_and_path(
53 53 entry.lastrev.revision,
54 54 scm.with_leading_slash(entry.path) )
55 55 if change
56 56 entry.lastrev.identifier = change.changeset.revision
57 57 entry.lastrev.revision = change.changeset.revision
58 58 entry.lastrev.author = change.changeset.committer
59 59 # entry.lastrev.branch = change.branch
60 60 end
61 61 end
62 62 end
63 63 end
64 64 entries
65 65 end
66 66
67 67 def cat(path, identifier=nil)
68 68 rev = nil
69 69 if ! identifier.nil?
70 70 rev = changesets.find_by_revision(identifier)
71 71 return nil if rev.nil?
72 72 end
73 73 scm.cat(path, rev.nil? ? nil : rev.committed_on)
74 74 end
75 75
76 def annotate(path, identifier=nil)
77 rev = nil
78 if ! identifier.nil?
79 rev = changesets.find_by_revision(identifier)
80 return nil if rev.nil?
81 end
82 scm.annotate(path, rev.nil? ? nil : rev.committed_on)
83 end
84
76 85 def diff(path, rev, rev_to)
77 86 # convert rev to revision. CVS can't handle changesets here
78 87 diff=[]
79 88 changeset_from = changesets.find_by_revision(rev)
80 89 if rev_to.to_i > 0
81 90 changeset_to = changesets.find_by_revision(rev_to)
82 91 end
83 92 changeset_from.changes.each() do |change_from|
84 93 revision_from = nil
85 94 revision_to = nil
86 95 if path.nil? || (change_from.path.starts_with? scm.with_leading_slash(path))
87 96 revision_from = change_from.revision
88 97 end
89 98 if revision_from
90 99 if changeset_to
91 100 changeset_to.changes.each() do |change_to|
92 101 revision_to=change_to.revision if change_to.path==change_from.path
93 102 end
94 103 end
95 104 unless revision_to
96 105 revision_to=scm.get_previous_revision(revision_from)
97 106 end
98 107 file_diff = scm.diff(change_from.path, revision_from, revision_to)
99 108 diff = diff + file_diff unless file_diff.nil?
100 109 end
101 110 end
102 111 return diff
103 112 end
104 113
105 114 def fetch_changesets
106 115 # some nifty bits to introduce a commit-id with cvs
107 116 # natively cvs doesn't provide any kind of changesets,
108 117 # there is only a revision per file.
109 118 # we now take a guess using the author, the commitlog and the commit-date.
110 119
111 120 # last one is the next step to take. the commit-date is not equal for all
112 121 # commits in one changeset. cvs update the commit-date when the *,v file was touched. so
113 122 # we use a small delta here, to merge all changes belonging to _one_ changeset
114 123 time_delta=10.seconds
115 124
116 125 fetch_since = latest_changeset ? latest_changeset.committed_on : nil
117 126 transaction do
118 127 tmp_rev_num = 1
119 128 scm.revisions('', fetch_since, nil, :with_paths => true) do |revision|
120 129 # only add the change to the database, if it doen't exists. the cvs log
121 130 # is not exclusive at all.
122 131 tmp_time = revision.time.clone
123 132 unless changes.find_by_path_and_revision(
124 133 scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision])
125 134 cmt = Changeset.normalize_comments(revision.message, repo_log_encoding)
126 135 cs = changesets.find(:first, :conditions=>{
127 136 :committed_on=>tmp_time - time_delta .. tmp_time + time_delta,
128 137 :committer=>revision.author,
129 138 :comments=>cmt
130 139 })
131 140
132 141 # create a new changeset....
133 142 unless cs
134 143 # we use a temporaray revision number here (just for inserting)
135 144 # later on, we calculate a continous positive number
136 145 tmp_time2 = tmp_time.clone.gmtime
137 146 branch = revision.paths[0][:branch]
138 147 scmid = branch + "-" + tmp_time2.strftime("%Y%m%d-%H%M%S")
139 148 cs = Changeset.create(:repository => self,
140 149 :revision => "tmp#{tmp_rev_num}",
141 150 :scmid => scmid,
142 151 :committer => revision.author,
143 152 :committed_on => tmp_time,
144 153 :comments => revision.message)
145 154 tmp_rev_num += 1
146 155 end
147 156
148 157 #convert CVS-File-States to internal Action-abbrevations
149 158 #default action is (M)odified
150 159 action="M"
151 160 if revision.paths[0][:action]=="Exp" && revision.paths[0][:revision]=="1.1"
152 161 action="A" #add-action always at first revision (= 1.1)
153 162 elsif revision.paths[0][:action]=="dead"
154 163 action="D" #dead-state is similar to Delete
155 164 end
156 165
157 166 Change.create(
158 167 :changeset => cs,
159 168 :action => action,
160 169 :path => scm.with_leading_slash(revision.paths[0][:path]),
161 170 :revision => revision.paths[0][:revision],
162 171 :branch => revision.paths[0][:branch]
163 172 )
164 173 end
165 174 end
166 175
167 176 # Renumber new changesets in chronological order
168 177 changesets.find(
169 178 :all,
170 179 :order => 'committed_on ASC, id ASC',
171 180 :conditions => "revision LIKE 'tmp%'"
172 181 ).each do |changeset|
173 182 changeset.update_attribute :revision, next_revision_number
174 183 end
175 184 end # transaction
176 185 @current_revision_number = nil
177 186 end
178 187
179 188 private
180 189
181 190 # Returns the next revision number to assign to a CVS changeset
182 191 def next_revision_number
183 192 # Need to retrieve existing revision numbers to sort them as integers
184 193 sql = "SELECT revision FROM #{Changeset.table_name} "
185 194 sql << "WHERE repository_id = #{id} AND revision NOT LIKE 'tmp%'"
186 195 @current_revision_number ||= (connection.select_values(sql).collect(&:to_i).max || 0)
187 196 @current_revision_number += 1
188 197 end
189 198 end
General Comments 0
You need to be logged in to leave comments. Login now