diff --git a/lib/strokedb/stores/file_storage.rb b/lib/strokedb/stores/file_storage.rb index 1ab1df1d..6a1df201 100644 --- a/lib/strokedb/stores/file_storage.rb +++ b/lib/strokedb/stores/file_storage.rb @@ -1,5 +1,10 @@ module StrokeDB - RAW_HEAD_VERSION_UUID = Util.sha1_uuid("strokedb-internal:head-version").to_raw_uuid + + def self.head(branch="master") + Util.sha1_uuid(branch).to_raw_uuid + end + + RAW_MASTER_HEAD_VERSION_UUID = head() class FileStorage < Storage @@ -14,7 +19,7 @@ def save_as_head!(document, timestamp) def find(uuid, version=nil, opts = {}, &block) uuid_version = uuid + (version ? ".#{version}" : "") - key = uuid.to_raw_uuid + (version ? version.to_raw_uuid : RAW_HEAD_VERSION_UUID) + key = uuid.to_raw_uuid + (version ? version.to_raw_uuid : RAW_MASTER_HEAD_VERSION_UUID) if (ptr = @uindex.find(key)) && (ptr[0,20] != "\x00" * 20) # no way ptr will be zero raw_doc = StrokeDB::deserialize(read_at_ptr(ptr[0,20])) unless opts[:no_instantiation] @@ -28,7 +33,7 @@ def find(uuid, version=nil, opts = {}, &block) end def include?(uuid,version=nil) - key = uuid.to_raw_uuid + (version ? version.to_raw_uuid : RAW_HEAD_VERSION_UUID) + key = uuid.to_raw_uuid + (version ? version.to_raw_uuid : RAW_MASTER_HEAD_VERSION_UUID) !@uindex.find(key).nil? end @@ -47,7 +52,7 @@ def each(options = {}) @uindex.each do |key, value| timestamp = StrokeDB.deserialize(read_at_ptr(value[20,20])) next if after && (timestamp <= after) - if key[16,16] == RAW_HEAD_VERSION_UUID || include_versions + if key[16,16] == RAW_MASTER_HEAD_VERSION_UUID || include_versions yield Document.from_raw(options[:store],StrokeDB.deserialize(read_at_ptr(value[0,20]))) end end @@ -59,7 +64,7 @@ def perform_save!(document, timestamp, options = {}) ts_ptr = DistributedPointer.pack(@archive.raw_uuid,ts_position) ptr = DistributedPointer.pack(@archive.raw_uuid,position) uuid = document.raw_uuid - @uindex.insert(uuid + RAW_HEAD_VERSION_UUID, ptr + ts_ptr) if options[:head] || !document.is_a?(VersionedDocument) + @uindex.insert(uuid + RAW_MASTER_HEAD_VERSION_UUID, ptr + ts_ptr) if options[:head] || !document.is_a?(VersionedDocument) @uindex.insert(uuid + document.version.to_raw_uuid, ptr + ts_ptr) unless options[:head] rescue ArchiveVolume::VolumeCapacityExceeded create_new_archive!