Class: Redmine::Scm::Adapters::CvsAdapter
- Inherits:
-
AbstractAdapter
show all
- Defined in:
- lib/redmine/scm/adapters/cvs_adapter.rb
Defined Under Namespace
Classes: ScmCommandAborted
Constant Summary
- CVS_BIN =
Redmine::Configuration['scm_cvs_command'] || "cvs"
- STARTLOG =
"----------------------------"
- ENDLOG =
"============================================================================="
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
-
- (Object) annotate(path, identifier = nil)
-
- (Object) cat(path, identifier = nil)
-
- (Object) diff(path, identifier_from, identifier_to = nil)
-
- (Object) entries(path = nil, identifier = nil)
Returns an Entries collection or nil if the given path doesn't exist in
the repository this method is used by the repository-browser (aka LIST).
-
- (Object) get_previous_revision(revision)
-
- (Object) info
-
- (CvsAdapter) initialize(url, root_url = nil, login = nil, password = nil, path_encoding = nil)
constructor
Guidelines for the input:.
-
- (Object) revisions(path = nil, identifier_from = nil, identifier_to = nil, options = {}, &block)
Returns all revisions found between identifier_from and identifier_to in
the repository.
-
- (Object) root_url
-
- (Object) url
#adapter_name, #branches, client_version_above?, client_version_string, #default_branch, #entry, #properties, shell_quote, #shell_quote, #supports_annotate?, #supports_cat?, #tags, #with_leading_slash, #with_trailling_slash, #without_leading_slash, #without_trailling_slash
Constructor Details
- (CvsAdapter) initialize(url, root_url = nil, login = nil, password = nil, path_encoding = nil)
Guidelines for the input:
url -> the project-path, relative to the cvsroot (eg. module name)
root_url -> the good old, sometimes damned, CVSROOT
login -> unnecessary
password -> unnecessary too
65
66
67
68
69
70
71
72
73
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 65
def initialize(url, root_url=nil, login=nil, password=nil,
path_encoding=nil)
@url = url
@login = login if login && !login.empty?
@password = (password || "") if @login
raise CommandFailed if root_url.blank?
@root_url = root_url
end
|
Class Method Details
+ (Object) client_available
41
42
43
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 41
def client_available
client_version_above?([1, 12])
end
|
+ (Object) client_command
29
30
31
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 29
def client_command
@@bin ||= CVS_BIN
end
|
+ (Object) client_version
37
38
39
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 37
def client_version
@@client_version ||= (scm_command_version || [])
end
|
+ (Object) scm_command_version
45
46
47
48
49
50
51
52
53
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 45
def scm_command_version
scm_version = scm_version_from_command_line.dup
if scm_version.respond_to?(:force_encoding)
scm_version.force_encoding('ASCII-8BIT')
end
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)}m)
m[2].scan(%r{\d+}).collect(&:to_i)
end
end
|
+ (Object) scm_version_from_command_line
55
56
57
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 55
def scm_version_from_command_line
shellout("#{sq_bin} --version") { |io| io.read }.to_s
end
|
+ (Object) sq_bin
33
34
35
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 33
def sq_bin
@@sq_bin ||= shell_quote(CVS_BIN)
end
|
Instance Method Details
- (Object) annotate(path, identifier = nil)
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 309
def annotate(path, identifier=nil)
identifier = (identifier) ? identifier.to_i : "HEAD"
logger.debug "<cvs> annotate path:'#{path}',identifier #{identifier}"
path_with_project="#{url}#{with_leading_slash(path)}"
cmd = "#{self.class.sq_bin} -d #{shell_quote root_url} rannotate -r#{identifier} #{shell_quote path_with_project}"
blame = Annotate.new
shellout(cmd) do |io|
io.each_line do |line|
next unless line =~ %r{^([\d\.]+)\s+\(([^\)]+)\s+[^\)]+\):\s(.*)$}
blame.add_line($3.rstrip, Revision.new(:revision => $1, :author => $2.strip))
end
end
return nil if $? && $?.exitstatus != 0
blame
end
|
- (Object) cat(path, identifier = nil)
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 293
def cat(path, identifier=nil)
identifier = (identifier) ? identifier : "HEAD"
logger.debug "<cvs> cat path:'#{path}',identifier #{identifier}"
path_with_project="#{url}#{with_leading_slash(path)}"
cmd = "#{self.class.sq_bin} -d #{shell_quote root_url} co"
cmd << " -D \"#{time_to_cvstime(identifier)}\"" if identifier
cmd << " -p #{shell_quote path_with_project}"
cat = nil
shellout(cmd) do |io|
io.binmode
cat = io.read
end
return nil if $? && $?.exitstatus != 0
cat
end
|
- (Object) diff(path, identifier_from, identifier_to = nil)
279
280
281
282
283
284
285
286
287
288
289
290
291
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 279
def diff(path, identifier_from, identifier_to=nil)
logger.debug "<cvs> diff path:'#{path}',identifier_from #{identifier_from}, identifier_to #{identifier_to}"
path_with_project="#{url}#{with_leading_slash(path)}"
cmd = "#{self.class.sq_bin} -d #{shell_quote root_url} rdiff -u -r#{identifier_to} -r#{identifier_from} #{shell_quote path_with_project}"
diff = []
shellout(cmd) do |io|
io.each_line do |line|
diff << line
end
end
return nil if $? && $?.exitstatus != 0
diff
end
|
- (Object) entries(path = nil, identifier = nil)
Returns an Entries collection or nil if the given path doesn't exist in
the repository this method is used by the repository-browser (aka LIST)
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 95
def entries(path=nil, identifier=nil)
logger.debug "<cvs> entries '#{path}' with identifier '#{identifier}'"
path_with_project="#{url}#{with_leading_slash(path)}"
entries = Entries.new
cmd_args = %w|rls -e|
cmd_args << "-D" << time_to_cvstime_rlog(identifier) if identifier
cmd_args << path_with_project
scm_cmd(*cmd_args) do |io|
io.each_line() do |line|
fields = line.chop.split('/',-1)
logger.debug(">>InspectLine #{fields.inspect}")
if fields[0]!="D"
time = nil
time_l = fields[-3].split(' ')
if time_l.size == 5 && time_l[4].length == 4
begin
time = Time.parse(
"#{time_l[1]} #{time_l[2]} #{time_l[3]} GMT #{time_l[4]}")
rescue
end
end
entries << Entry.new(
{
:name => fields[-5],
:path => "#{path}/#{fields[-5]}",
:kind => 'file',
:size => nil,
:lastrev => Revision.new(
{
:revision => fields[-4],
:name => fields[-4],
:time => time,
:author => ''
})
})
else
entries << Entry.new(
{
:name => fields[1],
:path => "#{path}/#{fields[1]}",
:kind => 'dir',
:size => nil,
:lastrev => nil
})
end
end
end
entries.sort_by_name
rescue ScmCommandAborted
nil
end
|
- (Object) get_previous_revision(revision)
88
89
90
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 88
def get_previous_revision(revision)
CvsRevisionHelper.new(revision).prevRev
end
|
- (Object) info
83
84
85
86
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 83
def info
logger.debug "<cvs> info"
Info.new({:root_url => @root_url, :lastrev => nil})
end
|
- (Object) revisions(path = nil, identifier_from = nil, identifier_to = nil, options = {}, &block)
Returns all revisions found between identifier_from and identifier_to in
the repository. both identifier have to be dates or nil. these method
returns nothing but yield every result in block
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 155
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}, &block)
logger.debug "<cvs> revisions path:'#{path}',identifier_from #{identifier_from}, identifier_to #{identifier_to}"
path_with_project="#{url}#{with_leading_slash(path)}"
cmd_args = %w|rlog|
cmd_args << "-d" << ">#{time_to_cvstime_rlog(identifier_from)}" if identifier_from
cmd_args << path_with_project
scm_cmd(*cmd_args) do |io|
state="entry_start"
commit_log=String.new
revision=nil
date=nil
author=nil
entry_path=nil
entry_name=nil
file_state=nil
branch_map=nil
io.each_line() do |line|
if state!="revision" && /^#{ENDLOG}/ =~ line
commit_log=String.new
revision=nil
state="entry_start"
end
if state=="entry_start"
branch_map=Hash.new
if /^RCS file: #{Regexp.escape(root_url_path)}\/#{Regexp.escape(path_with_project)}(.+),v$/ =~ line
entry_path = normalize_cvs_path($1)
entry_name = normalize_path(File.basename($1))
logger.debug("Path #{entry_path} <=> Name #{entry_name}")
elsif /^head: (.+)$/ =~ line
entry_headRev = $1 elsif /^symbolic names:/ =~ line
state="symbolic" elsif /^#{STARTLOG}/ =~ line
commit_log=String.new
state="revision"
end
next
elsif state=="symbolic"
if /^(.*):\s(.*)/ =~ (line.strip)
branch_map[$1]=$2
else
state="tags"
next
end
elsif state=="tags"
if /^#{STARTLOG}/ =~ line
commit_log = ""
state="revision"
elsif /^#{ENDLOG}/ =~ line
state="head"
end
next
elsif state=="revision"
if /^#{ENDLOG}/ =~ line || /^#{STARTLOG}/ =~ line
if revision
revHelper=CvsRevisionHelper.new(revision)
revBranch="HEAD"
branch_map.each() do |branch_name,branch_point|
if revHelper.is_in_branch_with_symbol(branch_point)
revBranch=branch_name
end
end
logger.debug("********** YIELD Revision #{revision}::#{revBranch}")
yield Revision.new({
:time => date,
:author => author,
:message=>commit_log.chomp,
:paths => [{
:revision => revision,
:branch=> revBranch,
:path=>entry_path,
:name=>entry_name,
:kind=>'file',
:action=>file_state
}]
})
end
commit_log=String.new
revision=nil
if /^#{ENDLOG}/ =~ line
state="entry_start"
end
next
end
if /^branches: (.+)$/ =~ line
elsif /^revision (\d+(?:\.\d+)+).*$/ =~ line
revision = $1
elsif /^date:\s+(\d+.\d+.\d+\s+\d+:\d+:\d+)/ =~ line
date = Time.parse($1)
author = /author: ([^;]+)/.match(line)[1]
file_state = /state: ([^;]+)/.match(line)[1]
else
commit_log << line unless line =~ /^\*\*\* empty log message \*\*\*/
end
end
end
end
rescue ScmCommandAborted
Revisions.new
end
|
- (Object) root_url
75
76
77
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 75
def root_url
@root_url
end
|
- (Object) url
79
80
81
|
# File 'lib/redmine/scm/adapters/cvs_adapter.rb', line 79
def url
@url
end
|