au 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -1
- data/bin/au +9 -14
- data/lib/au.rb +1 -1
- data/lib/au/models/commit.rb +3 -2
- data/lib/au/models/repository.rb +40 -35
- data/lib/au/models/staging.rb +4 -3
- data/lib/au/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa95d04570850dee2f2925f15f73e3bcec71cece8d85fd3a96eed234615df6e9
|
4
|
+
data.tar.gz: a2ad2985e381758e42dda23e14781d47fcb16dabcf2539a720e67c5823f1fb0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a3430e195cd66c77a7b8e6228e459d6c75fa3bb0d42f4d1e305d152b37b6c63d714e05a2410314d2144916e6871202576ecc2089d66b1fa56aebb2c8064e5ef
|
7
|
+
data.tar.gz: 07d9fa7e97ca6b3f80937ee5a0e16d3e2480935fe11e5caf62708030b7d4ef7c2b07125f97245d1bcb856b7c3ac68fd84648e2d5816e2dc3ac5372f0622e9945
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,7 +26,7 @@ To install
|
|
26
26
|
**any older version will error**. If your system comes with an older version, please either
|
27
27
|
update your Ruby installation or use [rbenv](https://github.com/rbenv/rbenv). You may need to use `sudo`. Additionally, if you are on an outdated Ruby installation, please make sure your load path is updated for Ruby executable.
|
28
28
|
|
29
|
-
##
|
29
|
+
## Design Document
|
30
30
|
|
31
31
|
A simple get-started [tutorial video](https://www.useloom.com/share/6372bf5d22b8482299f3c788559d4173).
|
32
32
|
|
@@ -96,6 +96,8 @@ Again, this project requires Ruby 2.5.0 or higher.
|
|
96
96
|
|
97
97
|
Unit specs are written in RSpec. Use `bundle exec rspec` to run all unit specs.
|
98
98
|
|
99
|
+
Use `ruby -Ilib:test test/integration_test.rb` to run integration test.
|
100
|
+
|
99
101
|
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
100
102
|
|
101
103
|
## Dependencies
|
data/bin/au
CHANGED
@@ -86,7 +86,7 @@ module Au
|
|
86
86
|
|
87
87
|
desc "heads", "Show current HEAD"
|
88
88
|
def heads
|
89
|
-
Repository.instance.heads
|
89
|
+
puts Repository.instance.heads
|
90
90
|
end
|
91
91
|
|
92
92
|
desc "diff PATH", "Diff between tracked version and current version"
|
@@ -142,28 +142,23 @@ module Au
|
|
142
142
|
|
143
143
|
desc "pull REMOTE_PATH", "Pull changes from remote repo"
|
144
144
|
def pull(remote_repo_root)
|
145
|
-
remote = nil
|
146
145
|
begin
|
147
|
-
remote = Repository.
|
148
|
-
|
149
|
-
|
150
|
-
|
146
|
+
remote = Repository.new(remote_repo_root, false)
|
147
|
+
Repository.instance.pull(remote)
|
148
|
+
rescue => e
|
149
|
+
puts e.message
|
151
150
|
end
|
152
|
-
Repository.instance.pull(remote)
|
153
151
|
end
|
154
152
|
|
155
153
|
desc "push REMOTE_PATH", "Push changes to remote repo"
|
156
154
|
def push(remote_repo_root)
|
157
|
-
remote = nil
|
158
155
|
begin
|
159
|
-
remote = Repository.
|
160
|
-
|
161
|
-
|
162
|
-
|
156
|
+
remote = Repository.new(remote_repo_root, false)
|
157
|
+
Repository.instance.push(remote)
|
158
|
+
rescue => e
|
159
|
+
puts e.message
|
163
160
|
end
|
164
|
-
Repository.instance.push(remote)
|
165
161
|
end
|
166
|
-
|
167
162
|
end
|
168
163
|
end
|
169
164
|
|
data/lib/au.rb
CHANGED
data/lib/au/models/commit.rb
CHANGED
@@ -217,9 +217,10 @@ module Au
|
|
217
217
|
|
218
218
|
private
|
219
219
|
|
220
|
-
def self.db(repo_path =
|
220
|
+
def self.db(repo_path = Repository.path)
|
221
221
|
# in this pstore file, each key is a commit id
|
222
|
-
@db ||=
|
222
|
+
@db ||= {}
|
223
|
+
@db[repo_path] ||= PStore.new(File.join(repo_path, 'commits.pstore'))
|
223
224
|
end
|
224
225
|
|
225
226
|
def self.build_commit_id
|
data/lib/au/models/repository.rb
CHANGED
@@ -97,7 +97,7 @@ module Au
|
|
97
97
|
|
98
98
|
def pull(remote_repo)
|
99
99
|
# Initialize local and remote db and commit list
|
100
|
-
remote_commit_db = Commit.db(remote_repo.
|
100
|
+
remote_commit_db = Commit.db(remote_repo.path)
|
101
101
|
remote_commit_list = remote_commit_db.transaction do
|
102
102
|
remote_commit_db.roots
|
103
103
|
end
|
@@ -124,31 +124,35 @@ module Au
|
|
124
124
|
|
125
125
|
# Find documents and their diff_id in those commits that only existed remotely
|
126
126
|
remote_diff_id_to_add_list = {}
|
127
|
-
commits_to_add.each do |commit|
|
128
|
-
commit[:doc_diff_ids].each do |doc_path, diff_id|
|
127
|
+
commits_to_add.each do |_, commit|
|
128
|
+
commit[:doc_diff_ids].each do |doc_path, diff_id|
|
129
129
|
remote_diff_id_to_add_list[doc_path] = diff_id
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
# Write these information to
|
133
|
+
# Write these information to local
|
134
134
|
remote_diff_id_to_add_list.each do |doc_path, diff_id|
|
135
135
|
diff_pstore_remote = PStore.new(diff_db_name_remote(doc_path, remote_repo.path))
|
136
136
|
diff_pstore_remote.transaction(true) do
|
137
137
|
diff_pstore_local = PStore.new(diff_db_name_remote(doc_path, @path))
|
138
138
|
diff_pstore_local.transaction do
|
139
|
-
if diff_pstore_local[
|
140
|
-
diff_pstore_local[
|
141
|
-
elsif diff_pstore_local[
|
139
|
+
if diff_pstore_local[diff_id] == nil
|
140
|
+
diff_pstore_local[diff_id] = diff_pstore_remote[diff_id]
|
141
|
+
elsif diff_pstore_local[diff_id] != diff_pstore_remote[diff_id]
|
142
142
|
raise "Error: Remote and local reposiroty have different content in a same diff"
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
147
|
+
|
148
|
+
# Find heads that only exist on remote repo
|
149
|
+
heads_to_add = remote_repo.heads.reject{|x| heads.include?(x)}
|
150
|
+
heads_to_add.each{|x| update_leaves_pstore(x)}
|
147
151
|
end
|
148
152
|
|
149
153
|
def push(remote_repo)
|
150
154
|
# Initialize local and remote db and commit list
|
151
|
-
remote_commit_db = Commit.db(remote_repo.
|
155
|
+
remote_commit_db = Commit.db(remote_repo.path)
|
152
156
|
remote_commit_list = remote_commit_db.transaction do
|
153
157
|
remote_commit_db.roots
|
154
158
|
end
|
@@ -164,8 +168,8 @@ module Au
|
|
164
168
|
# Find commits that only exist locally
|
165
169
|
commit_id_to_add_list = local_commit_list.reject{|x| remote_commit_list.include?(x)}
|
166
170
|
commits_to_add = {}
|
167
|
-
|
168
|
-
commit_id_to_add_list.each{|commit_id| commits_to_add[commit_id] =
|
171
|
+
local_commit_db.transaction(true) do
|
172
|
+
commit_id_to_add_list.each{|commit_id| commits_to_add[commit_id] = local_commit_db[commit_id]}
|
169
173
|
end
|
170
174
|
|
171
175
|
# Write those commits to remote commit db
|
@@ -175,8 +179,8 @@ module Au
|
|
175
179
|
|
176
180
|
# Find documents and their diff_id in those commits that only existed locally
|
177
181
|
local_diff_id_to_add_list = {}
|
178
|
-
commits_to_add.each do |commit|
|
179
|
-
commit[:doc_diff_ids].each do |doc_path, diff_id|
|
182
|
+
commits_to_add.each do |_, commit|
|
183
|
+
commit[:doc_diff_ids].each do |doc_path, diff_id|
|
180
184
|
local_diff_id_to_add_list[doc_path] = diff_id
|
181
185
|
end
|
182
186
|
end
|
@@ -187,14 +191,17 @@ module Au
|
|
187
191
|
diff_pstore_local.transaction(true) do
|
188
192
|
diff_pstore_remote = PStore.new(diff_db_name_remote(doc_path, remote_repo.path))
|
189
193
|
diff_pstore_remote.transaction do
|
190
|
-
if diff_pstore_remote[
|
191
|
-
diff_pstore_remote[
|
192
|
-
elsif diff_pstore_local[
|
194
|
+
if diff_pstore_remote[diff_id] == nil
|
195
|
+
diff_pstore_remote[diff_id] = diff_pstore_local[diff_id]
|
196
|
+
elsif diff_pstore_local[diff_id] != diff_pstore_remote[diff_id]
|
193
197
|
raise "Error: Remote and local reposiroty have different content in a same diff"
|
194
198
|
end
|
195
199
|
end
|
196
200
|
end
|
197
201
|
end
|
202
|
+
# Find heads that only exist on remote repo
|
203
|
+
heads_to_add = heads.reject{|x| remote_repo.heads.include?(x)}
|
204
|
+
heads_to_add.each{|x| remote_repo.update_leaves_pstore(x)}
|
198
205
|
end
|
199
206
|
|
200
207
|
# def clone
|
@@ -207,20 +214,30 @@ module Au
|
|
207
214
|
end
|
208
215
|
end
|
209
216
|
|
210
|
-
private
|
211
|
-
|
212
|
-
def diff_db_name_remote(file_path, remote_path)
|
213
|
-
paths = [Repository(remote_path, false).path, "diff_#{file_path.gsub('/', '.')}.pstore"].compact
|
214
|
-
File.join(*paths)
|
215
|
-
end
|
216
|
-
|
217
|
-
|
218
217
|
def update_head_var
|
219
218
|
@head = @head_pstore.transaction(true) do
|
220
219
|
@head_pstore[:head]
|
221
220
|
end
|
222
221
|
end
|
223
222
|
|
223
|
+
def update_leaves_pstore(commit_id)
|
224
|
+
@leaves_pstore.transaction do
|
225
|
+
commit = Commit.find(commit_id)
|
226
|
+
if commit
|
227
|
+
parent_commit_id_1, parent_commit_id_2 = commit.parent_id_1, commit.parent_id_2
|
228
|
+
@leaves_pstore.delete(parent_commit_id_1)
|
229
|
+
@leaves_pstore.delete(parent_commit_id_2)
|
230
|
+
@leaves_pstore[commit_id] = 1
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
private
|
236
|
+
def diff_db_name_remote(file_path, remote_path)
|
237
|
+
paths = [remote_path, "diff_#{file_path.gsub('/', '.')}.pstore"].compact
|
238
|
+
File.join(*paths)
|
239
|
+
end
|
240
|
+
|
224
241
|
def update_head_pstore(commit_id)
|
225
242
|
@head = @head_pstore.transaction do
|
226
243
|
@head_pstore[:head] = commit_id
|
@@ -239,18 +256,6 @@ module Au
|
|
239
256
|
end
|
240
257
|
end
|
241
258
|
|
242
|
-
def update_leaves_pstore(commit_id)
|
243
|
-
@leaves_pstore.transaction do
|
244
|
-
commit = Commit.find(commit_id)
|
245
|
-
if commit
|
246
|
-
parent_commit_id_1, parent_commit_id_2 = commit.parent_id_1, commit.parent_id_2
|
247
|
-
@leaves_pstore.delete(parent_commit_id_1)
|
248
|
-
@leaves_pstore.delete(parent_commit_id_2)
|
249
|
-
@leaves_pstore[commit_id] = 1
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
259
|
def self.resolve_conflict_fname
|
255
260
|
File.join(Repository.instance.path, 'resolve_conflict')
|
256
261
|
end
|
data/lib/au/models/staging.rb
CHANGED
@@ -24,9 +24,10 @@ module Au
|
|
24
24
|
|
25
25
|
def self.stage(relative_paths, last_commit = Repository.head)
|
26
26
|
relative_paths = relative_paths.each_with_object([]) do |staged_path, accum|
|
27
|
-
if File.directory?(staged_path)
|
28
|
-
Dir.glob('**/*', base: staged_path) do |sub_path|
|
29
|
-
accum << (File.join(staged_path, sub_path)) unless File.directory?(
|
27
|
+
if File.directory?(File.join(Repository.root, staged_path))
|
28
|
+
Dir.glob('**/*', base: File.join(Repository.root, staged_path)) do |sub_path|
|
29
|
+
accum << (File.join(staged_path, sub_path)) unless File.directory?(File.join(
|
30
|
+
Repository.root, staged_path, sub_path))
|
30
31
|
end
|
31
32
|
else
|
32
33
|
accum << staged_path
|
data/lib/au/version.rb
CHANGED