Class: Amp::RevlogSupport::Index
- Includes:
- Support, Enumerable
- Defined in:
- lib/amp/revlogs/index.rb
Overview
Index
The Index is a file that keeps track of the revision data. All revisions go through an index. This class, Index, is the most basic class. It provides an Index.parse method so that you can read a file in, and the class will figure out which version it is, and all that jazz.
Direct Known Subclasses
Constant Summary collapse
- VERSION_FORMAT =
This is the packed format of the version number of the index.
"N"
Constants included from Support
Support::REVLOG_DEFAULT_FLAGS, Support::REVLOG_DEFAULT_FORMAT, Support::REVLOG_DEFAULT_VERSION, Support::REVLOG_NG_INLINE_DATA, Support::REVLOG_VERSION_0, Support::REVLOG_VERSION_NG
Instance Attribute Summary collapse
-
#cache ⇒ Object
This is the raw cache data.
-
#chunk_cache ⇒ Object
readonly
This allows a couple neat caching tricks to speed up acces and cut down on IO.
-
#index ⇒ Object
readonly
The actual lookup array.
-
#indexfile ⇒ Object
readonly
This is the path to the index file.
-
#node_map ⇒ Object
readonly
This node_map lets you look up node_id’s (NOT INDEX-NUMBERS), which are strings, and get the index into @index of the node you’re looking up.
-
#version ⇒ Object
readonly
The version (either Support::REVLOG_VERSION_0 or Support::REVLOG_VERSION_NG).
Class Method Summary collapse
-
.parse(opener, inputfile) ⇒ Index
This method will parse the file at the provided path and return an appropriate Index object.
Instance Method Summary collapse
-
#<<(item) ⇒ Object
Adds an item to the index safely.
-
#[](index) ⇒ IndexEntry
This provides quick lookup into the index, based on revision number.
-
#each(&b) ⇒ Object
Iterates over each entry in the index, including the null revision.
-
#has_node?(node) ⇒ Boolean
Returns whether a given node ID exists, without throwing a lookup error.
-
#size ⇒ Object
Returns the number of entries in the index, including the null revision.
-
#write_entry(index_file, journal) ⇒ Object
This method writes the index to file.
Methods included from Enumerable
Methods included from Support
#compress, #decompress, #get_offset, #get_version, #history_hash, #offset_version
Instance Attribute Details
#cache ⇒ Object
This is the raw cache data. Another helpful bit.
106 107 108 |
# File 'lib/amp/revlogs/index.rb', line 106 def cache @cache end |
#chunk_cache ⇒ Object (readonly)
This allows a couple neat caching tricks to speed up acces and cut down on IO.
101 102 103 |
# File 'lib/amp/revlogs/index.rb', line 101 def chunk_cache @chunk_cache end |
#index ⇒ Object (readonly)
The actual lookup array. Each revision has an index in this list, and that list also happens to be relatively chronological.
94 95 96 |
# File 'lib/amp/revlogs/index.rb', line 94 def index @index end |
#indexfile ⇒ Object (readonly)
This is the path to the index file. Can be a URL. I don’t care and neither should you.
104 105 106 |
# File 'lib/amp/revlogs/index.rb', line 104 def indexfile @indexfile end |
#node_map ⇒ Object (readonly)
This node_map lets you look up node_id’s (NOT INDEX-NUMBERS), which are strings, and get the index into @index of the node you’re looking up.
98 99 100 |
# File 'lib/amp/revlogs/index.rb', line 98 def node_map @node_map end |
#version ⇒ Object (readonly)
The version (either Support::REVLOG_VERSION_0 or Support::REVLOG_VERSION_NG)
91 92 93 |
# File 'lib/amp/revlogs/index.rb', line 91 def version @version end |
Class Method Details
.parse(opener, inputfile) ⇒ Index
This method will parse the file at the provided path and return an appropriate Index object. The object will be of the class that fits the file provided, based on version and whether it is inline.
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 |
# File 'lib/amp/revlogs/index.rb', line 116 def self.parse(opener, inputfile) versioninfo = REVLOG_DEFAULT_VERSION i = "" begin opener.open(inputfile) do |f| i = f.read(4) end versioninfo = i.unpack(VERSION_FORMAT).first if i.size > 0 # Check if the data is with the index info. inline = (versioninfo & REVLOG_NG_INLINE_DATA > 0) # Get the version number of the index file. version = Support.get_version versioninfo rescue inline = true version = REVLOG_VERSION_NG end # Pick a subclass for the version and in-line-icity we found. case [version, inline] when [REVLOG_VERSION_0, false] IndexVersion0.new opener, inputfile when [REVLOG_VERSION_NG, false] IndexVersionNG.new opener, inputfile when [REVLOG_VERSION_NG, true] IndexInlineNG.new opener, inputfile else raise RevlogError.new("Invalid format: #{version} flags: #{get_flags(versioninfo)}") end end |
Instance Method Details
#<<(item) ⇒ Object
Adds an item to the index safely. DO NOT USE some_index.index <<. It’s some_index << entry.
180 181 182 183 184 |
# File 'lib/amp/revlogs/index.rb', line 180 def <<(item) @index.insert(-2, IndexEntry.new(*item)) if item.is_a? Array @index.insert(-2, item) if item.is_a? IndexEntry # leave the terminating entry intact end |
#[](index) ⇒ IndexEntry
This provides quick lookup into the index, based on revision number. NOT ID’s, index numbers.
161 162 163 |
# File 'lib/amp/revlogs/index.rb', line 161 def [](index) @index[index] end |
#each(&b) ⇒ Object
Iterates over each entry in the index, including the null revision
192 193 194 |
# File 'lib/amp/revlogs/index.rb', line 192 def each(&b) @index.each(&b) end |
#has_node?(node) ⇒ Boolean
Returns whether a given node ID exists, without throwing a lookup error.
151 152 153 |
# File 'lib/amp/revlogs/index.rb', line 151 def has_node?(node) @node_map[node] end |
#size ⇒ Object
Returns the number of entries in the index, including the null revision
187 188 189 |
# File 'lib/amp/revlogs/index.rb', line 187 def size @index.size end |
#write_entry(index_file, journal) ⇒ Object
This method writes the index to file. Pretty 1337h4><.
168 169 170 171 |
# File 'lib/amp/revlogs/index.rb', line 168 def write_entry(index_file, journal) raise abort("Use a concrete class. Yeah, I called it a concrete class. I hate" + " Java too, but you tried to use an abstract class.") end |