comparison lib/redmine/scm/adapters/.svn/text-base/abstract_adapter.rb.svn-base @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 051f544170fe
children 0c939c159af4
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 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 'cgi' 18 require 'cgi'
88 end 88 end
89 89
90 def url 90 def url
91 @url 91 @url
92 end 92 end
93 93
94 def path_encoding
95 nil
96 end
97
94 # get info about the svn repository 98 # get info about the svn repository
95 def info 99 def info
96 return nil 100 return nil
97 end 101 end
98 102
99 # Returns the entry identified by path and revision identifier 103 # Returns the entry identified by path and revision identifier
100 # or nil if entry doesn't exist in the repository 104 # or nil if entry doesn't exist in the repository
101 def entry(path=nil, identifier=nil) 105 def entry(path=nil, identifier=nil)
102 parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?} 106 parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?}
103 search_path = parts[0..-2].join('/') 107 search_path = parts[0..-2].join('/')
109 # Search for the entry in the parent directory 113 # Search for the entry in the parent directory
110 es = entries(search_path, identifier) 114 es = entries(search_path, identifier)
111 es ? es.detect {|e| e.name == search_name} : nil 115 es ? es.detect {|e| e.name == search_name} : nil
112 end 116 end
113 end 117 end
114 118
115 # Returns an Entries collection 119 # Returns an Entries collection
116 # or nil if the given path doesn't exist in the repository 120 # or nil if the given path doesn't exist in the repository
117 def entries(path=nil, identifier=nil) 121 def entries(path=nil, identifier=nil, options={})
118 return nil 122 return nil
119 end 123 end
120 124
121 def branches 125 def branches
122 return nil 126 return nil
123 end 127 end
124 128
125 def tags 129 def tags
126 return nil 130 return nil
127 end 131 end
128 132
129 def default_branch 133 def default_branch
130 return nil 134 return nil
131 end 135 end
132 136
133 def properties(path, identifier=nil) 137 def properties(path, identifier=nil)
134 return nil 138 return nil
135 end 139 end
136 140
137 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) 141 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
138 return nil 142 return nil
139 end 143 end
140 144
141 def diff(path, identifier_from, identifier_to=nil) 145 def diff(path, identifier_from, identifier_to=nil)
142 return nil 146 return nil
143 end 147 end
144 148
145 def cat(path, identifier=nil) 149 def cat(path, identifier=nil)
146 return nil 150 return nil
147 end 151 end
148 152
149 def with_leading_slash(path) 153 def with_leading_slash(path)
150 path ||= '' 154 path ||= ''
151 (path[0,1]!="/") ? "/#{path}" : path 155 (path[0,1]!="/") ? "/#{path}" : path
152 end 156 end
153 157
173 private 177 private
174 def retrieve_root_url 178 def retrieve_root_url
175 info = self.info 179 info = self.info
176 info ? info.root_url : nil 180 info ? info.root_url : nil
177 end 181 end
178 182
179 def target(path) 183 def target(path)
180 path ||= '' 184 path ||= ''
181 base = path.match(/^\//) ? root_url : url 185 base = path.match(/^\//) ? root_url : url
182 shell_quote("#{base}/#{path}".gsub(/[?<>\*]/, '')) 186 shell_quote("#{base}/#{path}".gsub(/[?<>\*]/, ''))
183 end 187 end
221 # Hides username/password in a given command 225 # Hides username/password in a given command
222 def self.strip_credential(cmd) 226 def self.strip_credential(cmd)
223 q = (Redmine::Platform.mswin? ? '"' : "'") 227 q = (Redmine::Platform.mswin? ? '"' : "'")
224 cmd.to_s.gsub(/(\-\-(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx') 228 cmd.to_s.gsub(/(\-\-(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx')
225 end 229 end
226 230
227 def strip_credential(cmd) 231 def strip_credential(cmd)
228 self.class.strip_credential(cmd) 232 self.class.strip_credential(cmd)
229 end 233 end
230 234
231 def scm_iconv(to, from, str) 235 def scm_iconv(to, from, str)
240 end 244 end
241 end 245 end
242 246
243 class Entries < Array 247 class Entries < Array
244 def sort_by_name 248 def sort_by_name
245 sort {|x,y| 249 sort {|x,y|
246 if x.kind == y.kind 250 if x.kind == y.kind
247 x.name.to_s <=> y.name.to_s 251 x.name.to_s <=> y.name.to_s
248 else 252 else
249 x.kind <=> y.kind 253 x.kind <=> y.kind
250 end 254 end
251 } 255 }
252 end 256 end
253 257
254 def revisions 258 def revisions
255 revisions ||= Revisions.new(collect{|entry| entry.lastrev}.compact) 259 revisions ||= Revisions.new(collect{|entry| entry.lastrev}.compact)
256 end 260 end
257 end 261 end
258 262
259 class Info 263 class Info
260 attr_accessor :root_url, :lastrev 264 attr_accessor :root_url, :lastrev
261 def initialize(attributes={}) 265 def initialize(attributes={})
262 self.root_url = attributes[:root_url] if attributes[:root_url] 266 self.root_url = attributes[:root_url] if attributes[:root_url]
263 self.lastrev = attributes[:lastrev] 267 self.lastrev = attributes[:lastrev]
264 end 268 end
265 end 269 end
266 270
267 class Entry 271 class Entry
268 attr_accessor :name, :path, :kind, :size, :lastrev 272 attr_accessor :name, :path, :kind, :size, :lastrev
269 def initialize(attributes={}) 273 def initialize(attributes={})
270 self.name = attributes[:name] if attributes[:name] 274 self.name = attributes[:name] if attributes[:name]
271 self.path = attributes[:path] if attributes[:path] 275 self.path = attributes[:path] if attributes[:path]
272 self.kind = attributes[:kind] if attributes[:kind] 276 self.kind = attributes[:kind] if attributes[:kind]
273 self.size = attributes[:size].to_i if attributes[:size] 277 self.size = attributes[:size].to_i if attributes[:size]
274 self.lastrev = attributes[:lastrev] 278 self.lastrev = attributes[:lastrev]
275 end 279 end
276 280
277 def is_file? 281 def is_file?
278 'file' == self.kind 282 'file' == self.kind
279 end 283 end
280 284
281 def is_dir? 285 def is_dir?
282 'dir' == self.kind 286 'dir' == self.kind
283 end 287 end
284 288
285 def is_text? 289 def is_text?
286 Redmine::MimeType.is_type?('text', name) 290 Redmine::MimeType.is_type?('text', name)
287 end 291 end
288 end 292 end
289 293
290 class Revisions < Array 294 class Revisions < Array
291 def latest 295 def latest
292 sort {|x,y| 296 sort {|x,y|
293 unless x.time.nil? or y.time.nil? 297 unless x.time.nil? or y.time.nil?
294 x.time <=> y.time 298 x.time <=> y.time
295 else 299 else
296 0 300 0
297 end 301 end
298 }.last 302 }.last
299 end 303 end
300 end 304 end
301 305
302 class Revision 306 class Revision
303 attr_accessor :scmid, :name, :author, :time, :message, :paths, :revision, :branch 307 attr_accessor :scmid, :name, :author, :time, :message,
304 attr_writer :identifier 308 :paths, :revision, :branch, :identifier
305 309
306 def initialize(attributes={}) 310 def initialize(attributes={})
307 self.identifier = attributes[:identifier] 311 self.identifier = attributes[:identifier]
308 self.scmid = attributes[:scmid] 312 self.scmid = attributes[:scmid]
309 self.name = attributes[:name] || self.identifier 313 self.name = attributes[:name] || self.identifier
310 self.author = attributes[:author] 314 self.author = attributes[:author]
311 self.time = attributes[:time] 315 self.time = attributes[:time]
312 self.message = attributes[:message] || "" 316 self.message = attributes[:message] || ""
313 self.paths = attributes[:paths] 317 self.paths = attributes[:paths]
314 self.revision = attributes[:revision] 318 self.revision = attributes[:revision]
315 self.branch = attributes[:branch] 319 self.branch = attributes[:branch]
316 end
317
318 # Returns the identifier of this revision; see also Changeset model
319 def identifier
320 (@identifier || revision).to_s
321 end 320 end
322 321
323 # Returns the readable identifier. 322 # Returns the readable identifier.
324 def format_identifier 323 def format_identifier
325 identifier 324 self.identifier.to_s
326 end 325 end
327 end 326 end
328 327
329 class Annotate 328 class Annotate
330 attr_reader :lines, :revisions 329 attr_reader :lines, :revisions
331 330
332 def initialize 331 def initialize
333 @lines = [] 332 @lines = []
334 @revisions = [] 333 @revisions = []
335 end 334 end
336 335
337 def add_line(line, revision) 336 def add_line(line, revision)
338 @lines << line 337 @lines << line
339 @revisions << revision 338 @revisions << revision
340 end 339 end
341 340
342 def content 341 def content
343 content = lines.join("\n") 342 content = lines.join("\n")
344 end 343 end
345 344
346 def empty? 345 def empty?
347 lines.empty? 346 lines.empty?
348 end 347 end
349 end 348 end
350 end 349 end