Class: SVNx::Revision::RelativeArgument

Inherits:
FixnumArgument show all
Defined in:
lib/svnx/revision/argument.rb

Overview

this is of the form -3, which is revision (second one from the most recent; -1 is the most recent).

Constant Summary

Constants inherited from Argument

Argument::DATE_REGEXP, Argument::SVN_ARGUMENT_WORDS

Instance Attribute Summary

Attributes inherited from Argument

#value

Instance Method Summary collapse

Methods inherited from Argument

#<=>, matches_relative?, new, orig_new, #to_s

Constructor Details

#initialize(value, args) ⇒ RelativeArgument

Returns a new instance of RelativeArgument.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/svnx/revision/argument.rb', line 96

def initialize value, args
  entries = args[:entries]
  
  unless entries
    raise RevisionError.new "cannot determine relative revision without entries"
  end
  
  nentries = entries.size

  # logentries are in descending order, so the most recent one is index 0

  if value.abs > nentries
    raise RevisionError.new "ERROR: no entry for revision: #{value.abs}; number of entries: #{nentries}"
  else
    idx = value < 0 ? -1 + value.abs : nentries - value
    log_entry = entries[idx]
    super log_entry.revision.to_i
  end
end