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