eternity 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +22 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +18 -0
- data/eternity.gemspec +39 -0
- data/lib/eternity.rb +64 -0
- data/lib/eternity/blob.rb +94 -0
- data/lib/eternity/branch.rb +34 -0
- data/lib/eternity/collection_index.rb +47 -0
- data/lib/eternity/collection_tracker.rb +55 -0
- data/lib/eternity/commit.rb +151 -0
- data/lib/eternity/conflict_resolver.rb +40 -0
- data/lib/eternity/delta.rb +45 -0
- data/lib/eternity/index.rb +29 -0
- data/lib/eternity/log.rb +22 -0
- data/lib/eternity/object_tracker.rb +57 -0
- data/lib/eternity/patch.rb +129 -0
- data/lib/eternity/repository.rb +235 -0
- data/lib/eternity/track_flatter.rb +57 -0
- data/lib/eternity/tracker.rb +38 -0
- data/lib/eternity/version.rb +3 -0
- data/spec/blob_spec.rb +83 -0
- data/spec/branch_spec.rb +71 -0
- data/spec/checkout_spec.rb +110 -0
- data/spec/commit_spec.rb +104 -0
- data/spec/coverage_helper.rb +8 -0
- data/spec/delta_spec.rb +110 -0
- data/spec/index_spec.rb +76 -0
- data/spec/locking_spec.rb +122 -0
- data/spec/log_spec.rb +57 -0
- data/spec/minitest_helper.rb +79 -0
- data/spec/patch_spec.rb +213 -0
- data/spec/pull_spec.rb +292 -0
- data/spec/push_spec.rb +72 -0
- data/spec/repository_spec.rb +73 -0
- data/spec/revert_spec.rb +40 -0
- data/spec/tracker_spec.rb +143 -0
- metadata +270 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae0c0bddc4d901d3dcd08eaeca52e6bfe57795b6
|
4
|
+
data.tar.gz: 96978a1839083f06460ebbf2f42c7b11a0315402
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d617c2fb2ce1a9bfb5f7c6512b475c088b05dc003bfacb2ce05899c84377c7da3f3cf28fd1e950b05b79dc17343168788b0f55c7465dcd0d5b09aaecb20203a
|
7
|
+
data.tar.gz: 2c4c6561199c5784d577d850eaac89455881962fd1864aef2264dfc1eba444a774ef6799bdd62551c0d66b6e7fbde8616e292ccbb8d5f0959177c98da590f88b
|
data/.coveralls.yml
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
eternity
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Gabriel Naiman
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Eternity
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/eternity.png)](https://rubygems.org/gems/eternity)
|
4
|
+
[![Build Status](https://travis-ci.org/gabynaiman/eternity.png?branch=master)](https://travis-ci.org/gabynaiman/eternity)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/gabynaiman/eternity/badge.png?branch=master)](https://coveralls.io/r/gabynaiman/eternity?branch=master)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/gabynaiman/eternity.png)](https://codeclimate.com/github/gabynaiman/eternity)
|
7
|
+
[![Dependency Status](https://gemnasium.com/gabynaiman/eternity.png)](https://gemnasium.com/gabynaiman/eternity)
|
8
|
+
|
9
|
+
Distributed database version control system
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'eternity'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install eternity
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
TODO: Write usage instructions here
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/gabynaiman/eternity/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new(:spec) do |t|
|
5
|
+
t.libs << 'spec'
|
6
|
+
t.pattern = 'spec/**/*_spec.rb'
|
7
|
+
t.verbose = false
|
8
|
+
end
|
9
|
+
|
10
|
+
task :console do
|
11
|
+
require 'pry'
|
12
|
+
require 'eternity'
|
13
|
+
include Eternity
|
14
|
+
ARGV.clear
|
15
|
+
Pry.start
|
16
|
+
end
|
17
|
+
|
18
|
+
task default: :spec
|
data/eternity.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'eternity/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'eternity'
|
8
|
+
spec.version = Eternity::VERSION
|
9
|
+
spec.authors = ['Gabriel Naiman']
|
10
|
+
spec.email = ['gabynaiman@gmail.com']
|
11
|
+
spec.summary = 'Distributed database version control system'
|
12
|
+
spec.description = 'Distributed database version control system'
|
13
|
+
spec.homepage = 'https://github.com/gabynaiman/eternity'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'redic', '~> 1.2.0'
|
22
|
+
spec.add_dependency 'restruct', '~> 0.0.3'
|
23
|
+
spec.add_dependency 'class_config', '~> 0.0.2'
|
24
|
+
spec.add_dependency 'locky', '~> 0.0.3'
|
25
|
+
spec.add_dependency 'transparent_proxy', '~> 0.0.4'
|
26
|
+
|
27
|
+
if RUBY_PLATFORM == 'java'
|
28
|
+
spec.add_dependency 'msgpack-jruby'
|
29
|
+
else
|
30
|
+
spec.add_dependency 'msgpack', '~> 0.5.9'
|
31
|
+
end
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
34
|
+
spec.add_development_dependency 'rake'
|
35
|
+
spec.add_development_dependency 'minitest', '~> 4.7'
|
36
|
+
spec.add_development_dependency 'turn', '~> 0.9'
|
37
|
+
spec.add_development_dependency 'simplecov'
|
38
|
+
spec.add_development_dependency 'pry-nav'
|
39
|
+
end
|
data/lib/eternity.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'redic'
|
2
|
+
require 'digest/sha1'
|
3
|
+
require 'msgpack'
|
4
|
+
require 'class_config'
|
5
|
+
require 'logger'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'forwardable'
|
8
|
+
require 'restruct'
|
9
|
+
require 'base64'
|
10
|
+
require 'locky'
|
11
|
+
require 'transparent_proxy'
|
12
|
+
|
13
|
+
module Eternity
|
14
|
+
|
15
|
+
INSERT = 'insert'.freeze
|
16
|
+
UPDATE = 'update'.freeze
|
17
|
+
DELETE = 'delete'.freeze
|
18
|
+
|
19
|
+
TIME_FORMAT = '%Y-%m-%dT%H:%M:%S%z'
|
20
|
+
|
21
|
+
extend ClassConfig
|
22
|
+
|
23
|
+
attr_config :redis, Redic.new
|
24
|
+
attr_config :keyspace, Restruct::Id.new(:eternity)
|
25
|
+
attr_config :blob_cache_expiration, 24 * 60 * 60 # 1 day in seconds
|
26
|
+
attr_config :blob_path, File.join(Dir.home, '.eternity')
|
27
|
+
attr_config :logger, Logger.new(STDOUT)
|
28
|
+
|
29
|
+
def self.locker_storage
|
30
|
+
@locker_storage ||= Restruct::MarshalHash.new redis: Redic.new(redis.url),
|
31
|
+
id: keyspace[:locker]
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.redis_keys
|
35
|
+
redis.call 'KEYS', keyspace['*']
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.clear_redis
|
39
|
+
redis_keys.each do |key|
|
40
|
+
redis.call 'DEL', key
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.clear_file_system
|
45
|
+
FileUtils.rm_rf blob_path if Dir.exists? blob_path
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
require_relative 'eternity/version'
|
51
|
+
require_relative 'eternity/log'
|
52
|
+
require_relative 'eternity/blob'
|
53
|
+
require_relative 'eternity/repository'
|
54
|
+
require_relative 'eternity/object_tracker'
|
55
|
+
require_relative 'eternity/collection_tracker'
|
56
|
+
require_relative 'eternity/tracker'
|
57
|
+
require_relative 'eternity/collection_index'
|
58
|
+
require_relative 'eternity/index'
|
59
|
+
require_relative 'eternity/commit'
|
60
|
+
require_relative 'eternity/branch'
|
61
|
+
require_relative 'eternity/patch'
|
62
|
+
require_relative 'eternity/track_flatter'
|
63
|
+
require_relative 'eternity/conflict_resolver'
|
64
|
+
require_relative 'eternity/delta'
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Eternity
|
2
|
+
class Blob
|
3
|
+
|
4
|
+
attr_reader :type, :sha1
|
5
|
+
|
6
|
+
def initialize(type, sha1)
|
7
|
+
@type = type
|
8
|
+
@sha1 = sha1
|
9
|
+
end
|
10
|
+
|
11
|
+
def data
|
12
|
+
sha1 ? Blob.read(type, sha1) : {}
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
|
17
|
+
def write(type, data)
|
18
|
+
serialization = serialize data
|
19
|
+
sha1 = digest serialization
|
20
|
+
|
21
|
+
write_redis type, sha1, serialization
|
22
|
+
write_file type, sha1, serialization
|
23
|
+
|
24
|
+
sha1
|
25
|
+
end
|
26
|
+
|
27
|
+
def read(type, sha1)
|
28
|
+
deserialize read_redis(type, sha1) || read_file(type, sha1)
|
29
|
+
end
|
30
|
+
|
31
|
+
def digest(string)
|
32
|
+
Digest::SHA1.hexdigest string
|
33
|
+
end
|
34
|
+
|
35
|
+
def serialize(data)
|
36
|
+
MessagePack.pack normalize(data)
|
37
|
+
end
|
38
|
+
|
39
|
+
def deserialize(string)
|
40
|
+
MessagePack.unpack string
|
41
|
+
end
|
42
|
+
|
43
|
+
def normalize(data)
|
44
|
+
sorted_data = Hash[data.sort_by { |k,v| k.to_s }]
|
45
|
+
sorted_data.each { |k,v| sorted_data[k] = v.utc.strftime TIME_FORMAT if v.respond_to? :utc }
|
46
|
+
end
|
47
|
+
|
48
|
+
def clear_cache
|
49
|
+
Eternity.redis.call('KEYS', Eternity.keyspace[:blob]['*']).each_slice(1000) do |keys|
|
50
|
+
Eternity.redis.call 'DEL', *keys
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def count
|
55
|
+
Eternity.redis.call('KEYS', Eternity.keyspace[:blob]['*']).count
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def write_redis(type, sha1, serialization)
|
61
|
+
Eternity.redis.call 'SET', Eternity.keyspace[:blob][type][sha1], serialization,
|
62
|
+
'EX', Eternity.blob_cache_expiration
|
63
|
+
end
|
64
|
+
|
65
|
+
def read_redis(type, sha1)
|
66
|
+
Eternity.redis.call 'GET', Eternity.keyspace[:blob][type][sha1]
|
67
|
+
end
|
68
|
+
|
69
|
+
def write_file(type, sha1, serialization)
|
70
|
+
filename = file_for type, sha1
|
71
|
+
if !File.exists? filename
|
72
|
+
dirname = File.dirname filename
|
73
|
+
FileUtils.mkpath dirname unless Dir.exists? dirname
|
74
|
+
File.write filename, Base64.encode64(serialization)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def read_file(type, sha1)
|
79
|
+
serialization = Base64.decode64(IO.read(file_for(type, sha1)))
|
80
|
+
write_redis type, sha1, serialization
|
81
|
+
serialization
|
82
|
+
|
83
|
+
rescue Errno::ENOENT
|
84
|
+
raise "Blob not found: #{type} -> #{sha1}"
|
85
|
+
end
|
86
|
+
|
87
|
+
def file_for(type, sha1)
|
88
|
+
File.join Eternity.blob_path, type.to_s, sha1[0..1], sha1[2..-1]
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Eternity
|
2
|
+
class Branch
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def [](name)
|
6
|
+
Commit.new branches[name]
|
7
|
+
end
|
8
|
+
|
9
|
+
def []=(name, commit_id)
|
10
|
+
branches[name] = commit_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def exists?(name)
|
14
|
+
branches.key? name
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete(name)
|
18
|
+
branches.delete name
|
19
|
+
end
|
20
|
+
|
21
|
+
def names
|
22
|
+
branches.keys
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def branches
|
28
|
+
@branches ||= Restruct::Hash.new redis: Eternity.redis,
|
29
|
+
id: Eternity.keyspace[:branches]
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Eternity
|
2
|
+
class CollectionIndex
|
3
|
+
|
4
|
+
extend Forwardable
|
5
|
+
def_delegators :index, :to_h, :to_primitive, :empty?, :dump, :restore, :destroy, :count
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@index = Restruct::Hash.new options
|
9
|
+
end
|
10
|
+
|
11
|
+
def collection_name
|
12
|
+
index.id.sections.last
|
13
|
+
end
|
14
|
+
|
15
|
+
def include?(id)
|
16
|
+
index.key? id
|
17
|
+
end
|
18
|
+
|
19
|
+
def [](id)
|
20
|
+
include?(id) ? Blob.new(:data, index[id]) : nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def insert(id, data)
|
24
|
+
raise "#{collection_name.capitalize} #{id} already exists" if index.key? id
|
25
|
+
index[id] = Blob.write :data, data
|
26
|
+
end
|
27
|
+
|
28
|
+
def update(id, data)
|
29
|
+
raise "#{collection_name.capitalize} #{id} not found" unless index.key? id
|
30
|
+
index[id] = Blob.write :data, data
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete(id)
|
34
|
+
raise "#{collection_name.capitalize} #{id} not found" unless index.key? id
|
35
|
+
index.delete id
|
36
|
+
end
|
37
|
+
|
38
|
+
def ids
|
39
|
+
index.keys
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
attr_reader :index
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Eternity
|
2
|
+
class CollectionTracker
|
3
|
+
|
4
|
+
Changes = Restruct::NestedHash.new ObjectTracker
|
5
|
+
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :changes, :to_h, :to_primitive, :count, :[], :destroy
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@changes = Changes.new options
|
11
|
+
end
|
12
|
+
|
13
|
+
def insert(id, data)
|
14
|
+
changes[id].insert data
|
15
|
+
end
|
16
|
+
|
17
|
+
def update(id, data)
|
18
|
+
changes[id].update data
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(id)
|
22
|
+
changes[id].delete
|
23
|
+
end
|
24
|
+
|
25
|
+
def revert(id)
|
26
|
+
changes[id].revert
|
27
|
+
end
|
28
|
+
|
29
|
+
def revert_all
|
30
|
+
locker.lock! :revert_all do
|
31
|
+
changes.destroy
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def flatten
|
36
|
+
changes.each_with_object({}) do |(id, tracker), hash|
|
37
|
+
change = tracker.flatten
|
38
|
+
hash[id] = change if change
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
attr_reader :changes
|
45
|
+
|
46
|
+
def locker
|
47
|
+
Locky.new repository_name, Eternity.locker_storage
|
48
|
+
end
|
49
|
+
|
50
|
+
def repository_name
|
51
|
+
changes.id.sections.reverse[2]
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|