Class: XMigra::SubversionSpecifics::VersionComparator

Inherits:
Object
  • Object
show all
Defined in:
lib/xmigra/vcs_support/svn.rb

Instance Method Summary collapse

Constructor Details

#initialize(vcs_object, options = {}) ⇒ VersionComparator

vcs_object.kind_of?(SubversionSpecifics)



237
238
239
240
241
242
243
244
245
# File 'lib/xmigra/vcs_support/svn.rb', line 237

def initialize(vcs_object, options={})
  @object = vcs_object
  @expected_content_method = options[:expected_content_method]
  @path_status = Hash.new do |h, file_path|
    file_path = Pathname(file_path).expand_path
    next h[file_path] if h.has_key?(file_path)
    h[file_path] = @object.subversion_retrieve_status(file_path)
  end
end

Instance Method Details

#relative_version(file_path) ⇒ Object



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
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/xmigra/vcs_support/svn.rb', line 247

def relative_version(file_path)
  # Comparing @object.file_path (a) to file_path (b)
  #
  # returns: :newer, :equal, :older, or :missing
  
  b_status = @path_status[file_path].elements['entry/wc-status']
  
  return :missing if b_status.nil? || ['deleted', 'missing'].include?(b_status.attributes['item'])
  
  a_status = @path_status[@object.file_path].elements['entry/wc-status']
  
  if ['unversioned', 'added'].include? a_status.attributes['item']
    if ['unversioned', 'added', 'modified'].include? b_status.attributes['item']
      return relative_version_by_content(file_path)
    end
    
    return :older
  elsif a_status.attributes['item'] == 'normal'
    # Look for re-introduction of a declarative that was previously destroyed or renounced
    if (['unversioned', 'added'].include? b_status.attributes['item']) && [:renunciation, :destruction].include?(@object.goal)
      return :unimplemented
    end
    
    return :newer unless b_status.attributes['item'] == 'normal'
    
    return begin
      a_revision = a_status.elements['commit'].attributes['revision'].to_i
      b_revision = b_status.elements['commit'].attributes['revision'].to_i
      
      if a_revision < b_revision
        :newer
      elsif b_revision < a_revision
        :older
      else
        :equal
      end
    end
  elsif b_status.attributes['item'] == 'normal'
    return :older
  else
    return relative_version_by_content(file_path)
  end
end

#relative_version_by_content(file_path) ⇒ Object



291
292
293
294
295
296
297
298
# File 'lib/xmigra/vcs_support/svn.rb', line 291

def relative_version_by_content(file_path)
  ec_method = @expected_content_method
  if !ec_method || @object.send(ec_method, file_path)
    return :equal
  else
    return :newer
  end
end