##// END OF EJS Templates
CVS: add support for modules names with spaces (#1434)....
Jean-Philippe Lang -
r1513:40a9bbe94684
parent child
Show More
@@ -1,354 +1,354
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'redmine/scm/adapters/abstract_adapter'
18 require 'redmine/scm/adapters/abstract_adapter'
19
19
20 module Redmine
20 module Redmine
21 module Scm
21 module Scm
22 module Adapters
22 module Adapters
23 class CvsAdapter < AbstractAdapter
23 class CvsAdapter < AbstractAdapter
24
24
25 # CVS executable name
25 # CVS executable name
26 CVS_BIN = "cvs"
26 CVS_BIN = "cvs"
27
27
28 # Guidelines for the input:
28 # Guidelines for the input:
29 # url -> the project-path, relative to the cvsroot (eg. module name)
29 # url -> the project-path, relative to the cvsroot (eg. module name)
30 # root_url -> the good old, sometimes damned, CVSROOT
30 # root_url -> the good old, sometimes damned, CVSROOT
31 # login -> unnecessary
31 # login -> unnecessary
32 # password -> unnecessary too
32 # password -> unnecessary too
33 def initialize(url, root_url=nil, login=nil, password=nil)
33 def initialize(url, root_url=nil, login=nil, password=nil)
34 @url = url
34 @url = url
35 @login = login if login && !login.empty?
35 @login = login if login && !login.empty?
36 @password = (password || "") if @login
36 @password = (password || "") if @login
37 #TODO: better Exception here (IllegalArgumentException)
37 #TODO: better Exception here (IllegalArgumentException)
38 raise CommandFailed if root_url.blank?
38 raise CommandFailed if root_url.blank?
39 @root_url = root_url
39 @root_url = root_url
40 end
40 end
41
41
42 def root_url
42 def root_url
43 @root_url
43 @root_url
44 end
44 end
45
45
46 def url
46 def url
47 @url
47 @url
48 end
48 end
49
49
50 def info
50 def info
51 logger.debug "<cvs> info"
51 logger.debug "<cvs> info"
52 Info.new({:root_url => @root_url, :lastrev => nil})
52 Info.new({:root_url => @root_url, :lastrev => nil})
53 end
53 end
54
54
55 def get_previous_revision(revision)
55 def get_previous_revision(revision)
56 CvsRevisionHelper.new(revision).prevRev
56 CvsRevisionHelper.new(revision).prevRev
57 end
57 end
58
58
59 # Returns an Entries collection
59 # Returns an Entries collection
60 # or nil if the given path doesn't exist in the repository
60 # or nil if the given path doesn't exist in the repository
61 # this method is used by the repository-browser (aka LIST)
61 # this method is used by the repository-browser (aka LIST)
62 def entries(path=nil, identifier=nil)
62 def entries(path=nil, identifier=nil)
63 logger.debug "<cvs> entries '#{path}' with identifier '#{identifier}'"
63 logger.debug "<cvs> entries '#{path}' with identifier '#{identifier}'"
64 path_with_project="#{url}#{with_leading_slash(path)}"
64 path_with_project="#{url}#{with_leading_slash(path)}"
65 entries = Entries.new
65 entries = Entries.new
66 cmd = "#{CVS_BIN} -d #{root_url} rls -ed"
66 cmd = "#{CVS_BIN} -d #{root_url} rls -ed"
67 cmd << " -D \"#{time_to_cvstime(identifier)}\"" if identifier
67 cmd << " -D \"#{time_to_cvstime(identifier)}\"" if identifier
68 cmd << " #{path_with_project}"
68 cmd << " #{shell_quote path_with_project}"
69 shellout(cmd) do |io|
69 shellout(cmd) do |io|
70 io.each_line(){|line|
70 io.each_line(){|line|
71 fields=line.chop.split('/',-1)
71 fields=line.chop.split('/',-1)
72 logger.debug(">>InspectLine #{fields.inspect}")
72 logger.debug(">>InspectLine #{fields.inspect}")
73
73
74 if fields[0]!="D"
74 if fields[0]!="D"
75 entries << Entry.new({:name => fields[-5],
75 entries << Entry.new({:name => fields[-5],
76 #:path => fields[-4].include?(path)?fields[-4]:(path + "/"+ fields[-4]),
76 #:path => fields[-4].include?(path)?fields[-4]:(path + "/"+ fields[-4]),
77 :path => "#{path}/#{fields[-5]}",
77 :path => "#{path}/#{fields[-5]}",
78 :kind => 'file',
78 :kind => 'file',
79 :size => nil,
79 :size => nil,
80 :lastrev => Revision.new({
80 :lastrev => Revision.new({
81 :revision => fields[-4],
81 :revision => fields[-4],
82 :name => fields[-4],
82 :name => fields[-4],
83 :time => Time.parse(fields[-3]),
83 :time => Time.parse(fields[-3]),
84 :author => ''
84 :author => ''
85 })
85 })
86 })
86 })
87 else
87 else
88 entries << Entry.new({:name => fields[1],
88 entries << Entry.new({:name => fields[1],
89 :path => "#{path}/#{fields[1]}",
89 :path => "#{path}/#{fields[1]}",
90 :kind => 'dir',
90 :kind => 'dir',
91 :size => nil,
91 :size => nil,
92 :lastrev => nil
92 :lastrev => nil
93 })
93 })
94 end
94 end
95 }
95 }
96 end
96 end
97 return nil if $? && $?.exitstatus != 0
97 return nil if $? && $?.exitstatus != 0
98 entries.sort_by_name
98 entries.sort_by_name
99 end
99 end
100
100
101 STARTLOG="----------------------------"
101 STARTLOG="----------------------------"
102 ENDLOG ="============================================================================="
102 ENDLOG ="============================================================================="
103
103
104 # Returns all revisions found between identifier_from and identifier_to
104 # Returns all revisions found between identifier_from and identifier_to
105 # in the repository. both identifier have to be dates or nil.
105 # in the repository. both identifier have to be dates or nil.
106 # these method returns nothing but yield every result in block
106 # these method returns nothing but yield every result in block
107 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}, &block)
107 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}, &block)
108 logger.debug "<cvs> revisions path:'#{path}',identifier_from #{identifier_from}, identifier_to #{identifier_to}"
108 logger.debug "<cvs> revisions path:'#{path}',identifier_from #{identifier_from}, identifier_to #{identifier_to}"
109
109
110 path_with_project="#{url}#{with_leading_slash(path)}"
110 path_with_project="#{url}#{with_leading_slash(path)}"
111 cmd = "#{CVS_BIN} -d #{root_url} rlog"
111 cmd = "#{CVS_BIN} -d #{root_url} rlog"
112 cmd << " -d\">#{time_to_cvstime(identifier_from)}\"" if identifier_from
112 cmd << " -d\">#{time_to_cvstime(identifier_from)}\"" if identifier_from
113 cmd << " #{path_with_project}"
113 cmd << " #{shell_quote path_with_project}"
114 shellout(cmd) do |io|
114 shellout(cmd) do |io|
115 state="entry_start"
115 state="entry_start"
116
116
117 commit_log=String.new
117 commit_log=String.new
118 revision=nil
118 revision=nil
119 date=nil
119 date=nil
120 author=nil
120 author=nil
121 entry_path=nil
121 entry_path=nil
122 entry_name=nil
122 entry_name=nil
123 file_state=nil
123 file_state=nil
124 branch_map=nil
124 branch_map=nil
125
125
126 io.each_line() do |line|
126 io.each_line() do |line|
127
127
128 if state!="revision" && /^#{ENDLOG}/ =~ line
128 if state!="revision" && /^#{ENDLOG}/ =~ line
129 commit_log=String.new
129 commit_log=String.new
130 revision=nil
130 revision=nil
131 state="entry_start"
131 state="entry_start"
132 end
132 end
133
133
134 if state=="entry_start"
134 if state=="entry_start"
135 branch_map=Hash.new
135 branch_map=Hash.new
136 # gsub(/^:.*@[^:]+:\d*/, '') is here to remove :pserver:anonymous@foo.bar: string if present in the url
136 # gsub(/^:.*@[^:]+:\d*/, '') is here to remove :pserver:anonymous@foo.bar: string if present in the url
137 if /^RCS file: #{Regexp.escape(root_url.gsub(/^:.*@[^:]+:\d*/, ''))}\/#{Regexp.escape(path_with_project)}(.+),v$/ =~ line
137 if /^RCS file: #{Regexp.escape(root_url.gsub(/^:.*@[^:]+:\d*/, ''))}\/#{Regexp.escape(path_with_project)}(.+),v$/ =~ line
138 entry_path = normalize_cvs_path($1)
138 entry_path = normalize_cvs_path($1)
139 entry_name = normalize_path(File.basename($1))
139 entry_name = normalize_path(File.basename($1))
140 logger.debug("Path #{entry_path} <=> Name #{entry_name}")
140 logger.debug("Path #{entry_path} <=> Name #{entry_name}")
141 elsif /^head: (.+)$/ =~ line
141 elsif /^head: (.+)$/ =~ line
142 entry_headRev = $1 #unless entry.nil?
142 entry_headRev = $1 #unless entry.nil?
143 elsif /^symbolic names:/ =~ line
143 elsif /^symbolic names:/ =~ line
144 state="symbolic" #unless entry.nil?
144 state="symbolic" #unless entry.nil?
145 elsif /^#{STARTLOG}/ =~ line
145 elsif /^#{STARTLOG}/ =~ line
146 commit_log=String.new
146 commit_log=String.new
147 state="revision"
147 state="revision"
148 end
148 end
149 next
149 next
150 elsif state=="symbolic"
150 elsif state=="symbolic"
151 if /^(.*):\s(.*)/ =~ (line.strip)
151 if /^(.*):\s(.*)/ =~ (line.strip)
152 branch_map[$1]=$2
152 branch_map[$1]=$2
153 else
153 else
154 state="tags"
154 state="tags"
155 next
155 next
156 end
156 end
157 elsif state=="tags"
157 elsif state=="tags"
158 if /^#{STARTLOG}/ =~ line
158 if /^#{STARTLOG}/ =~ line
159 commit_log = ""
159 commit_log = ""
160 state="revision"
160 state="revision"
161 elsif /^#{ENDLOG}/ =~ line
161 elsif /^#{ENDLOG}/ =~ line
162 state="head"
162 state="head"
163 end
163 end
164 next
164 next
165 elsif state=="revision"
165 elsif state=="revision"
166 if /^#{ENDLOG}/ =~ line || /^#{STARTLOG}/ =~ line
166 if /^#{ENDLOG}/ =~ line || /^#{STARTLOG}/ =~ line
167 if revision
167 if revision
168
168
169 revHelper=CvsRevisionHelper.new(revision)
169 revHelper=CvsRevisionHelper.new(revision)
170 revBranch="HEAD"
170 revBranch="HEAD"
171
171
172 branch_map.each() do |branch_name,branch_point|
172 branch_map.each() do |branch_name,branch_point|
173 if revHelper.is_in_branch_with_symbol(branch_point)
173 if revHelper.is_in_branch_with_symbol(branch_point)
174 revBranch=branch_name
174 revBranch=branch_name
175 end
175 end
176 end
176 end
177
177
178 logger.debug("********** YIELD Revision #{revision}::#{revBranch}")
178 logger.debug("********** YIELD Revision #{revision}::#{revBranch}")
179
179
180 yield Revision.new({
180 yield Revision.new({
181 :time => date,
181 :time => date,
182 :author => author,
182 :author => author,
183 :message=>commit_log.chomp,
183 :message=>commit_log.chomp,
184 :paths => [{
184 :paths => [{
185 :revision => revision,
185 :revision => revision,
186 :branch=> revBranch,
186 :branch=> revBranch,
187 :path=>entry_path,
187 :path=>entry_path,
188 :name=>entry_name,
188 :name=>entry_name,
189 :kind=>'file',
189 :kind=>'file',
190 :action=>file_state
190 :action=>file_state
191 }]
191 }]
192 })
192 })
193 end
193 end
194
194
195 commit_log=String.new
195 commit_log=String.new
196 revision=nil
196 revision=nil
197
197
198 if /^#{ENDLOG}/ =~ line
198 if /^#{ENDLOG}/ =~ line
199 state="entry_start"
199 state="entry_start"
200 end
200 end
201 next
201 next
202 end
202 end
203
203
204 if /^branches: (.+)$/ =~ line
204 if /^branches: (.+)$/ =~ line
205 #TODO: version.branch = $1
205 #TODO: version.branch = $1
206 elsif /^revision (\d+(?:\.\d+)+).*$/ =~ line
206 elsif /^revision (\d+(?:\.\d+)+).*$/ =~ line
207 revision = $1
207 revision = $1
208 elsif /^date:\s+(\d+.\d+.\d+\s+\d+:\d+:\d+)/ =~ line
208 elsif /^date:\s+(\d+.\d+.\d+\s+\d+:\d+:\d+)/ =~ line
209 date = Time.parse($1)
209 date = Time.parse($1)
210 author = /author: ([^;]+)/.match(line)[1]
210 author = /author: ([^;]+)/.match(line)[1]
211 file_state = /state: ([^;]+)/.match(line)[1]
211 file_state = /state: ([^;]+)/.match(line)[1]
212 #TODO: linechanges only available in CVS.... maybe a feature our SVN implementation. i'm sure, they are
212 #TODO: linechanges only available in CVS.... maybe a feature our SVN implementation. i'm sure, they are
213 # useful for stats or something else
213 # useful for stats or something else
214 # linechanges =/lines: \+(\d+) -(\d+)/.match(line)
214 # linechanges =/lines: \+(\d+) -(\d+)/.match(line)
215 # unless linechanges.nil?
215 # unless linechanges.nil?
216 # version.line_plus = linechanges[1]
216 # version.line_plus = linechanges[1]
217 # version.line_minus = linechanges[2]
217 # version.line_minus = linechanges[2]
218 # else
218 # else
219 # version.line_plus = 0
219 # version.line_plus = 0
220 # version.line_minus = 0
220 # version.line_minus = 0
221 # end
221 # end
222 else
222 else
223 commit_log << line unless line =~ /^\*\*\* empty log message \*\*\*/
223 commit_log << line unless line =~ /^\*\*\* empty log message \*\*\*/
224 end
224 end
225 end
225 end
226 end
226 end
227 end
227 end
228 end
228 end
229
229
230 def diff(path, identifier_from, identifier_to=nil)
230 def diff(path, identifier_from, identifier_to=nil)
231 logger.debug "<cvs> diff path:'#{path}',identifier_from #{identifier_from}, identifier_to #{identifier_to}"
231 logger.debug "<cvs> diff path:'#{path}',identifier_from #{identifier_from}, identifier_to #{identifier_to}"
232 path_with_project="#{url}#{with_leading_slash(path)}"
232 path_with_project="#{url}#{with_leading_slash(path)}"
233 cmd = "#{CVS_BIN} -d #{root_url} rdiff -u -r#{identifier_to} -r#{identifier_from} #{path_with_project}"
233 cmd = "#{CVS_BIN} -d #{root_url} rdiff -u -r#{identifier_to} -r#{identifier_from} #{shell_quote path_with_project}"
234 diff = []
234 diff = []
235 shellout(cmd) do |io|
235 shellout(cmd) do |io|
236 io.each_line do |line|
236 io.each_line do |line|
237 diff << line
237 diff << line
238 end
238 end
239 end
239 end
240 return nil if $? && $?.exitstatus != 0
240 return nil if $? && $?.exitstatus != 0
241 diff
241 diff
242 end
242 end
243
243
244 def cat(path, identifier=nil)
244 def cat(path, identifier=nil)
245 identifier = (identifier) ? identifier : "HEAD"
245 identifier = (identifier) ? identifier : "HEAD"
246 logger.debug "<cvs> cat path:'#{path}',identifier #{identifier}"
246 logger.debug "<cvs> cat path:'#{path}',identifier #{identifier}"
247 path_with_project="#{url}#{with_leading_slash(path)}"
247 path_with_project="#{url}#{with_leading_slash(path)}"
248 cmd = "#{CVS_BIN} -d #{root_url} co -r#{identifier} -p #{path_with_project}"
248 cmd = "#{CVS_BIN} -d #{root_url} co -r#{identifier} -p #{shell_quote path_with_project}"
249 cat = nil
249 cat = nil
250 shellout(cmd) do |io|
250 shellout(cmd) do |io|
251 cat = io.read
251 cat = io.read
252 end
252 end
253 return nil if $? && $?.exitstatus != 0
253 return nil if $? && $?.exitstatus != 0
254 cat
254 cat
255 end
255 end
256
256
257 def annotate(path, identifier=nil)
257 def annotate(path, identifier=nil)
258 identifier = (identifier) ? identifier : "HEAD"
258 identifier = (identifier) ? identifier : "HEAD"
259 logger.debug "<cvs> annotate path:'#{path}',identifier #{identifier}"
259 logger.debug "<cvs> annotate path:'#{path}',identifier #{identifier}"
260 path_with_project="#{url}#{with_leading_slash(path)}"
260 path_with_project="#{url}#{with_leading_slash(path)}"
261 cmd = "#{CVS_BIN} -d #{root_url} rannotate -r#{identifier} #{path_with_project}"
261 cmd = "#{CVS_BIN} -d #{root_url} rannotate -r#{identifier} #{shell_quote path_with_project}"
262 blame = Annotate.new
262 blame = Annotate.new
263 shellout(cmd) do |io|
263 shellout(cmd) do |io|
264 io.each_line do |line|
264 io.each_line do |line|
265 next unless line =~ %r{^([\d\.]+)\s+\(([^\)]+)\s+[^\)]+\):\s(.*)$}
265 next unless line =~ %r{^([\d\.]+)\s+\(([^\)]+)\s+[^\)]+\):\s(.*)$}
266 blame.add_line($3.rstrip, Revision.new(:revision => $1, :author => $2.strip))
266 blame.add_line($3.rstrip, Revision.new(:revision => $1, :author => $2.strip))
267 end
267 end
268 end
268 end
269 return nil if $? && $?.exitstatus != 0
269 return nil if $? && $?.exitstatus != 0
270 blame
270 blame
271 end
271 end
272
272
273 private
273 private
274
274
275 # convert a date/time into the CVS-format
275 # convert a date/time into the CVS-format
276 def time_to_cvstime(time)
276 def time_to_cvstime(time)
277 return nil if time.nil?
277 return nil if time.nil?
278 unless time.kind_of? Time
278 unless time.kind_of? Time
279 time = Time.parse(time)
279 time = Time.parse(time)
280 end
280 end
281 return time.strftime("%Y-%m-%d %H:%M:%S")
281 return time.strftime("%Y-%m-%d %H:%M:%S")
282 end
282 end
283
283
284 def normalize_cvs_path(path)
284 def normalize_cvs_path(path)
285 normalize_path(path.gsub(/Attic\//,''))
285 normalize_path(path.gsub(/Attic\//,''))
286 end
286 end
287
287
288 def normalize_path(path)
288 def normalize_path(path)
289 path.sub(/^(\/)*(.*)/,'\2').sub(/(.*)(,v)+/,'\1')
289 path.sub(/^(\/)*(.*)/,'\2').sub(/(.*)(,v)+/,'\1')
290 end
290 end
291 end
291 end
292
292
293 class CvsRevisionHelper
293 class CvsRevisionHelper
294 attr_accessor :complete_rev, :revision, :base, :branchid
294 attr_accessor :complete_rev, :revision, :base, :branchid
295
295
296 def initialize(complete_rev)
296 def initialize(complete_rev)
297 @complete_rev = complete_rev
297 @complete_rev = complete_rev
298 parseRevision()
298 parseRevision()
299 end
299 end
300
300
301 def branchPoint
301 def branchPoint
302 return @base
302 return @base
303 end
303 end
304
304
305 def branchVersion
305 def branchVersion
306 if isBranchRevision
306 if isBranchRevision
307 return @base+"."+@branchid
307 return @base+"."+@branchid
308 end
308 end
309 return @base
309 return @base
310 end
310 end
311
311
312 def isBranchRevision
312 def isBranchRevision
313 !@branchid.nil?
313 !@branchid.nil?
314 end
314 end
315
315
316 def prevRev
316 def prevRev
317 unless @revision==0
317 unless @revision==0
318 return buildRevision(@revision-1)
318 return buildRevision(@revision-1)
319 end
319 end
320 return buildRevision(@revision)
320 return buildRevision(@revision)
321 end
321 end
322
322
323 def is_in_branch_with_symbol(branch_symbol)
323 def is_in_branch_with_symbol(branch_symbol)
324 bpieces=branch_symbol.split(".")
324 bpieces=branch_symbol.split(".")
325 branch_start="#{bpieces[0..-3].join(".")}.#{bpieces[-1]}"
325 branch_start="#{bpieces[0..-3].join(".")}.#{bpieces[-1]}"
326 return (branchVersion==branch_start)
326 return (branchVersion==branch_start)
327 end
327 end
328
328
329 private
329 private
330 def buildRevision(rev)
330 def buildRevision(rev)
331 if rev== 0
331 if rev== 0
332 @base
332 @base
333 elsif @branchid.nil?
333 elsif @branchid.nil?
334 @base+"."+rev.to_s
334 @base+"."+rev.to_s
335 else
335 else
336 @base+"."+@branchid+"."+rev.to_s
336 @base+"."+@branchid+"."+rev.to_s
337 end
337 end
338 end
338 end
339
339
340 # Interpretiert die cvs revisionsnummern wie z.b. 1.14 oder 1.3.0.15
340 # Interpretiert die cvs revisionsnummern wie z.b. 1.14 oder 1.3.0.15
341 def parseRevision()
341 def parseRevision()
342 pieces=@complete_rev.split(".")
342 pieces=@complete_rev.split(".")
343 @revision=pieces.last.to_i
343 @revision=pieces.last.to_i
344 baseSize=1
344 baseSize=1
345 baseSize+=(pieces.size/2)
345 baseSize+=(pieces.size/2)
346 @base=pieces[0..-baseSize].join(".")
346 @base=pieces[0..-baseSize].join(".")
347 if baseSize > 2
347 if baseSize > 2
348 @branchid=pieces[-2]
348 @branchid=pieces[-2]
349 end
349 end
350 end
350 end
351 end
351 end
352 end
352 end
353 end
353 end
354 end
354 end
General Comments 0
You need to be logged in to leave comments. Login now