scvcs 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ require 'vcs_toolkit/objects/label'
2
+
3
+ module SCV
4
+ module Objects
5
+
6
+ class Label < VCSToolkit::Objects::Label
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'vcs_toolkit/objects/tree'
2
+
3
+ module SCV
4
+ module Objects
5
+
6
+ class Tree < VCSToolkit::Objects::Tree
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,124 @@
1
+ require 'vcs_toolkit/repository'
2
+
3
+ module SCV
4
+ class Repository < VCSToolkit::Repository
5
+ attr_reader :config
6
+
7
+ def initialize(path, init: false)
8
+ repository_path = "#{path}/.scv"
9
+
10
+ working_directory = FileStore.new path
11
+ object_store = ObjectStore.new FileStore.new(repository_path)
12
+ @config = Config.new FileStore.new(repository_path), 'config.yml'
13
+
14
+ super object_store,
15
+ working_directory,
16
+ commit_class: Objects::Commit,
17
+ tree_class: Objects::Tree,
18
+ blob_class: Objects::Blob,
19
+ label_class: Objects::Label
20
+
21
+ if init
22
+ set_label :master, nil
23
+ set_label :head, :master
24
+
25
+ @config['version'] = SCV::VERSION
26
+ @config.save
27
+ end
28
+
29
+ self.head = get_object(:head).reference_id
30
+ end
31
+
32
+ ##
33
+ # Resolve references from `object_id` to the first
34
+ # object of type `to_type`.
35
+ # Examples:
36
+ # label -> commit
37
+ # label -> label -> commit
38
+ # label -> commit -> tree
39
+ #
40
+ # If `object_id` contains '~n' suffix, where `n` >= 0 and
41
+ # the reference path contains a commit, the `parent` pointer
42
+ # of the commit is followed and the `n`-th commit is picked.
43
+ #
44
+ def resolve(object_id, to_type, parent_offset: 0)
45
+ if object_id =~ /^(.+)~([0-9]+)$/
46
+ object_id = $1
47
+ parent_offset = $2.to_i
48
+ end
49
+
50
+ object = self[object_id]
51
+
52
+ raise KeyError, "Cannot find object #{object_id}" if object.nil?
53
+
54
+ if object.object_type == :commit and parent_offset > 0
55
+ parent_offset.times do
56
+ raise "Commit #{object.id} has more than one parent" if object.parents.size > 1
57
+ raise "Commit #{object_id} has no parents" if object.parents.size.zero?
58
+
59
+ object = self[object.parents.first]
60
+ end
61
+ end
62
+
63
+ case object.object_type
64
+ when to_type
65
+ object
66
+ when :label
67
+ resolve object.reference_id, to_type, parent_offset: parent_offset
68
+ when :commit
69
+ resolve object.tree, to_type
70
+ else
71
+ raise "Cannot resolve #{object_id} to a #{to_type}"
72
+ end
73
+ end
74
+
75
+ ##
76
+ # Convenience method to resolve objects
77
+ #
78
+ def [](object_id, to_type=nil)
79
+ return super(object_id) if to_type.nil?
80
+
81
+ resolve object_id, to_type
82
+ end
83
+
84
+ ##
85
+ # Delete a label (only).
86
+ #
87
+ def delete_label(name)
88
+ label = get_object name
89
+
90
+ raise 'The object is not a label' if label.object_type != :label
91
+
92
+ object_store.remove name
93
+ end
94
+
95
+ ##
96
+ # Push history to remote repository
97
+ #
98
+ def push(remote_store, local_branch, remote_branch)
99
+ VCSToolkit::Utils::Sync.sync object_store, local_branch, remote_store, remote_branch
100
+ end
101
+
102
+ ##
103
+ # Fetch history from remote repository
104
+ #
105
+ def fetch(remote_store, remote_branch, local_branch)
106
+ VCSToolkit::Utils::Sync.sync remote_store, remote_branch, object_store, local_branch
107
+ end
108
+
109
+ ##
110
+ # Create an empty repository in the specified directory.
111
+ #
112
+ # Initializes the directory structure and creates a head label.
113
+ #
114
+ def self.create_at(working_directory)
115
+ directories = %w(.scv/objects .scv/refs .scv/blobs)
116
+
117
+ directories.each do |directory|
118
+ FileUtils.mkdir_p File.join(working_directory, directory)
119
+ end
120
+
121
+ new working_directory, init: true
122
+ end
123
+ end
124
+ end
data/lib/scv/server.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'rack'
2
+
3
+ module SCV
4
+
5
+ ##
6
+ # This is only intended to be a very basic web server
7
+ # that serves files from the `.scv` directory and also
8
+ # allows uploading files there.
9
+ #
10
+ # Wihout! Any! Authentication!
11
+ #
12
+ # You do understand what this means, right?
13
+ #
14
+ class Server
15
+ attr_reader :port
16
+
17
+ def initialize(repository_path, port: 4242)
18
+ @repository_path = repository_path
19
+ @port = port
20
+ end
21
+
22
+ def start
23
+ Rack::Handler::WEBrick.run method(:request_handler), {Port: @port}
24
+ end
25
+
26
+ private
27
+
28
+ def request_handler(env)
29
+ request = Rack::Request.new(env)
30
+
31
+ if request.get?
32
+ fetch File.join(@repository_path, env['REQUEST_PATH']), request
33
+ elsif request.put?
34
+ store File.join(@repository_path, env['REQUEST_PATH']), request
35
+ elsif request.head?
36
+ head File.join(@repository_path, env['REQUEST_PATH']), request
37
+ else
38
+ [405, {Allow: 'GET, POST, HEAD'}, ['Unsupported HTTP method!']]
39
+ end
40
+ end
41
+
42
+ def fetch(path, request)
43
+ return [404, {}, []] unless File.file?(path)
44
+
45
+ file = File.new path, 'rb'
46
+
47
+ [200, {}, file]
48
+ end
49
+
50
+ def store(path, request)
51
+ content = request.body.read
52
+
53
+ FileUtils.mkdir_p File.dirname(path)
54
+ File.write path, content
55
+
56
+ [200, {}, []]
57
+ end
58
+
59
+ def head(path, request)
60
+ status = File.file?(path) ? 200 : 404
61
+
62
+ [status, {}, []]
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,3 @@
1
+ module SCV
2
+ VERSION = '0.2.0'
3
+ end
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scvcs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Georgy Angelov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: vcs_toolkit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fakefs
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fuubar
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: ''
154
+ email:
155
+ - georgyangelov@gmail.com
156
+ executables:
157
+ - scv
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - LICENSE
162
+ - README.md
163
+ - bin/commands/branch.rb
164
+ - bin/commands/commit.rb
165
+ - bin/commands/config.rb
166
+ - bin/commands/diff.rb
167
+ - bin/commands/history.rb
168
+ - bin/commands/init.rb
169
+ - bin/commands/merge.rb
170
+ - bin/commands/remote.rb
171
+ - bin/commands/restore.rb
172
+ - bin/commands/server.rb
173
+ - bin/commands/status.rb
174
+ - bin/formatters/changeset.rb
175
+ - bin/formatters/hierarchy.rb
176
+ - bin/formatters/merge_report.rb
177
+ - bin/scv
178
+ - bin/utilities/output.rb
179
+ - bin/utilities/shell.rb
180
+ - lib/scv.rb
181
+ - lib/scv/config.rb
182
+ - lib/scv/file_store.rb
183
+ - lib/scv/http_file_store.rb
184
+ - lib/scv/object_store.rb
185
+ - lib/scv/objects.rb
186
+ - lib/scv/objects/blob.rb
187
+ - lib/scv/objects/commit.rb
188
+ - lib/scv/objects/label.rb
189
+ - lib/scv/objects/tree.rb
190
+ - lib/scv/repository.rb
191
+ - lib/scv/server.rb
192
+ - lib/scv/version.rb
193
+ homepage: http://github.com/stormbreakerbg/scv
194
+ licenses:
195
+ - MIT
196
+ metadata: {}
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 2.2.1
214
+ signing_key:
215
+ specification_version: 4
216
+ summary: A Ruby gem designed implementing a simple Git-like version control system
217
+ on top of vcs-toolkit.
218
+ test_files: []