lense 0.1.42 → 0.1.43
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lense.rb +46 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f42192d4855d217e54d3dfc54dc0de59450e7b42
|
4
|
+
data.tar.gz: 410af56c080571b1c261b431239121cb90822bc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea1a22f30d4addf2799d89b2beee9ff20da740814fb2391e7f5f70f8a911d41f2011c438f049207c4097bb3b7a62814bd0972cd5ff521d2746c9dcecc8b9fb07
|
7
|
+
data.tar.gz: 30299fc6253c6effab8171832d0cdfb4fdf7aa4274519c983f68707f5855721e1e9b7fa0f56bc3ee9ca00015b47be3ad76c4778c6a55b585d975c658e7ed4c0d
|
data/lib/lense.rb
CHANGED
@@ -6,7 +6,7 @@ require 'sqlite3'
|
|
6
6
|
class LENSE
|
7
7
|
attr_reader :config, :current_course, :lense_file_hash
|
8
8
|
|
9
|
-
VERSION = '0.1.
|
9
|
+
VERSION = '0.1.43'
|
10
10
|
LENSE_DIR = File.join(ENV['HOME'],'.lense')
|
11
11
|
COURSES_DIR = File.join(LENSE_DIR,'courses')
|
12
12
|
CURRENT_COURSE_FILE = File.join(LENSE_DIR,'current_course')
|
@@ -28,7 +28,7 @@ class LENSE
|
|
28
28
|
|
29
29
|
@current_course = File.read(CURRENT_COURSE_FILE).strip()
|
30
30
|
@current_course = '> NOT SET <' if @current_course.empty?
|
31
|
-
@lense_file_hash =
|
31
|
+
@lense_file_hash = hash_file(LENSE_FILE) if File.file?(LENSE_FILE)
|
32
32
|
@DB = SQLite3::Database.new File.join(LOCAL_LENSE_DIR,'db') if File.file? File.join(LOCAL_LENSE_DIR,'db')
|
33
33
|
end
|
34
34
|
|
@@ -153,6 +153,39 @@ class LENSE
|
|
153
153
|
def commit(msg)
|
154
154
|
# check that we have items in staging
|
155
155
|
rows = @DB.execute 'select path from staging;'
|
156
|
+
rows.map! do |r|
|
157
|
+
path = r[0]
|
158
|
+
{
|
159
|
+
path: path,
|
160
|
+
hash: hash_file(path)
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
files = rows.select do |file|
|
165
|
+
dependency = get_dependency(file[:path])
|
166
|
+
dependency.nil? || dependency.file_hash != file[:hash]
|
167
|
+
end
|
168
|
+
|
169
|
+
combined_hash = files.map {|f| f[:hash]}.join ''
|
170
|
+
commit_hash = Digest::SHA256.hexdigest "#{DateTime.now.to_s}#{combined_hash}"
|
171
|
+
@DB.execute 'insert into commits (dependency_id,hash,created_at) values (?,?,?);',[dependency_id,commit_hash,DateTime.now.to_s]
|
172
|
+
commit_id = @DB.last_insert_row_id
|
173
|
+
|
174
|
+
files.each do |file|
|
175
|
+
@DB.transaction
|
176
|
+
dependency = get_dependency(file[:path])
|
177
|
+
if dependency.nil?
|
178
|
+
@DB.execute 'insert into dependencies (path,added_at) values (?,?);',[file[:path],DateTime.now.to_s]
|
179
|
+
dependency_id = @DB.last_insert_row_id
|
180
|
+
else
|
181
|
+
dependency_id = dependency.id
|
182
|
+
end
|
183
|
+
@DB.execute 'insert into revisions (commit_id,dependency_id,hash,created_at) values (?,?,?,?);',[commit_id,dependency_id,file[:hash],DateTime.now.to_s]
|
184
|
+
@DB.commit
|
185
|
+
end
|
186
|
+
@DB.transaction
|
187
|
+
@DB.execute 'truncate staging;'
|
188
|
+
@DB.commit
|
156
189
|
# add new files to dependancies
|
157
190
|
# create a hash for the commit and add to commits
|
158
191
|
# for all dependancies add current hashes to revisions
|
@@ -165,7 +198,7 @@ class LENSE
|
|
165
198
|
if dependency.nil?
|
166
199
|
should_stage = true
|
167
200
|
else
|
168
|
-
current_hash =
|
201
|
+
current_hash = hash_file(file)
|
169
202
|
# is it modified?
|
170
203
|
if dependency.file_hash == current_hash
|
171
204
|
say "Not Staging because we've seen this file"
|
@@ -177,9 +210,13 @@ class LENSE
|
|
177
210
|
end
|
178
211
|
|
179
212
|
if should_stage
|
180
|
-
|
181
|
-
|
182
|
-
|
213
|
+
begin
|
214
|
+
@DB.transaction
|
215
|
+
@DB.execute "insert into staging (path) values (?);", file
|
216
|
+
@DB.commit
|
217
|
+
rescue
|
218
|
+
say "File already staged!"
|
219
|
+
end
|
183
220
|
end
|
184
221
|
end
|
185
222
|
end
|
@@ -196,6 +233,9 @@ class LENSE
|
|
196
233
|
end
|
197
234
|
|
198
235
|
private
|
236
|
+
def hash_file(file)
|
237
|
+
Digest::SHA256.hexdigest(File.read(file))
|
238
|
+
end
|
199
239
|
def get_dependency(file)
|
200
240
|
rows = @DB.execute("
|
201
241
|
select d.id, d.path, d.added_at, r.hash, r.created_at, c.hash
|