copernicium 0.0.1 → 0.0.2
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/lib/RevLog.rb +36 -55
- data/lib/banners.rb +35 -9
- data/lib/pushpull.rb +19 -0
- data/lib/repos.rb +94 -94
- data/lib/required.rb +2 -0
- data/lib/ui.rb +54 -21
- data/lib/workspace.rb +116 -121
- metadata +24 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7ec43a07b4f3d15b9d556319b6d7afd72e5cc7f
|
4
|
+
data.tar.gz: ed07ade71e83ac560723852e8b81bfee6dc58946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7f2f92fbb43d8d08babd1d201396ca896f7e4e9418d8ea3c6fd1ae2dc4e0df6a2b52c9899ac57e58d1bc3578ceaa6b1794d3efbb1a08bafd4d278fef50e2062
|
7
|
+
data.tar.gz: 563d55b11341b39786aeea08cf535677476c7bc96ba6d08ea8c4c2577a5c499baa1c52a2655eb41eba4b31f85f2e565bfbb9f7afe609b8cc5a440e8a412780b8
|
data/lib/RevLog.rb
CHANGED
@@ -26,37 +26,35 @@
|
|
26
26
|
|
27
27
|
module Copernicium
|
28
28
|
class RevLog
|
29
|
-
def initialize(
|
30
|
-
@
|
31
|
-
@cop_path = File.join(
|
32
|
-
@log_path = File.join(@cop_path,
|
33
|
-
@hash_path = File.join(@cop_path,
|
34
|
-
if File.exist?(@log_path)
|
35
|
-
@logmap =
|
36
|
-
@hashmap =
|
29
|
+
def initialize(root)
|
30
|
+
@root = root
|
31
|
+
@cop_path = File.join(root, '.cn')
|
32
|
+
@log_path = File.join(@cop_path, 'logmap.yaml')
|
33
|
+
@hash_path = File.join(@cop_path, 'hashmap.yaml')
|
34
|
+
if File.exist?(@log_path) && File.exist?(@hash_path)
|
35
|
+
@logmap = hash_array.merge(YAML.load_file(@log_path))
|
36
|
+
@hashmap = hash_array.merge(YAML.load_file(@hash_path))
|
37
37
|
else
|
38
|
-
@logmap =
|
39
|
-
@hashmap =
|
40
|
-
unless File.exist?(@cop_path)
|
41
|
-
Dir.mkdir(@cop_path)
|
42
|
-
end
|
38
|
+
@logmap = hash_array
|
39
|
+
@hashmap = hash_array
|
40
|
+
Dir.mkdir(@cop_path) unless File.exist?(@cop_path)
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
def hash_array
|
45
|
+
Hash.new {[]}
|
46
|
+
end
|
49
47
|
|
50
48
|
def add_file(file_name, content)
|
51
49
|
hash = hash_file(file_name, content)
|
52
|
-
File.open(File.join(@cop_path, hash),
|
50
|
+
File.open(File.join(@cop_path, hash), 'w') { |f|
|
53
51
|
f.write(content)
|
54
52
|
}
|
55
53
|
@logmap[file_name] = @logmap[file_name] << {:time => Time.now,
|
56
54
|
:hash => hash}
|
57
55
|
@hashmap[hash] = @hashmap[hash] << {:time => Time.now,
|
58
56
|
:filename => file_name}
|
59
|
-
update_log_file
|
57
|
+
update_log_file
|
60
58
|
return hash
|
61
59
|
end
|
62
60
|
|
@@ -64,13 +62,9 @@ module Copernicium
|
|
64
62
|
def delete_file(file_id)
|
65
63
|
begin
|
66
64
|
file_name = @hashmap[file_id][0][:filename]
|
67
|
-
@hashmap[file_id].delete_if { |e|
|
68
|
-
|
69
|
-
|
70
|
-
@logmap[file_name].delete_if { |e|
|
71
|
-
e[:hash] == file_id
|
72
|
-
}
|
73
|
-
update_log_file()
|
65
|
+
@hashmap[file_id].delete_if { |e| e[:filename] == file_name }
|
66
|
+
@logmap[file_name].delete_if { |e| e[:hash] == file_id }
|
67
|
+
update_log_file
|
74
68
|
File.delete(File.join(@cop_path, file_id))
|
75
69
|
return 1
|
76
70
|
rescue Exception
|
@@ -79,54 +73,41 @@ module Copernicium
|
|
79
73
|
end
|
80
74
|
|
81
75
|
|
82
|
-
def get_file(
|
83
|
-
file_path = File.join(@cop_path,
|
84
|
-
if File.exist?
|
85
|
-
File.open(file_path,
|
86
|
-
return f.read
|
87
|
-
}
|
76
|
+
def get_file(id)
|
77
|
+
file_path = File.join(@cop_path, id)
|
78
|
+
if File.exist? file_path
|
79
|
+
File.open(file_path, 'r') { |f| return f.read }
|
88
80
|
else
|
89
|
-
raise Exception,
|
81
|
+
raise Exception, 'Invalid id!'
|
90
82
|
end
|
91
83
|
end
|
92
84
|
|
93
85
|
|
94
86
|
def diff_files(file_id1, file_id2)
|
95
|
-
|
96
|
-
get_file(file_id2)).to_s()
|
87
|
+
Diffy::Diff.new(get_file(file_id1), get_file(file_id2)).to_s()
|
97
88
|
end
|
98
89
|
|
99
90
|
def hash_file(file_name, content)
|
100
91
|
Digest::SHA256.hexdigest(file_name + content.to_s)
|
101
92
|
end
|
102
93
|
|
103
|
-
def merge(
|
104
|
-
diff_a = Diffy::Diff.new(get_file(
|
105
|
-
|
106
|
-
if diff_a.all? { |d| d[0]!=
|
107
|
-
|
108
|
-
end
|
109
|
-
# if diff_a.all? { |d| d[0]!="+"}
|
110
|
-
# return get_file(file_id1)
|
111
|
-
# end
|
112
|
-
return diff_a
|
94
|
+
def merge(id1, id2)
|
95
|
+
diff_a = Diffy::Diff.new(get_file(id1), get_file(id2)).each_chunk.to_a
|
96
|
+
return get_file(id2) if diff_a.all? { |d| d[0]!='-'}
|
97
|
+
# return get_file(id1) if diff_a.all? { |d| d[0]!='+'}
|
98
|
+
diff_a
|
113
99
|
end
|
114
100
|
|
115
101
|
def history(file_name)
|
116
102
|
hashs = []
|
117
|
-
|
118
|
-
|
119
|
-
end
|
120
|
-
return hashs
|
103
|
+
@logmap[file_name].each { |m| hashs << m[:hash] }
|
104
|
+
hashs
|
121
105
|
end
|
122
106
|
|
123
|
-
def update_log_file
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
File.open(File.join(@cop_path, "hashmap.yaml"), "w") { |f|
|
128
|
-
f.write(@hashmap.to_yaml)
|
129
|
-
}
|
107
|
+
def update_log_file
|
108
|
+
# writeFile defined in workspace.rb
|
109
|
+
writeFile(File.join(@cop_path, 'logmap.yaml'), @logmap.to_yaml)
|
110
|
+
writeFile(File.join(@cop_path, 'hashmap.yaml'), @hashmap.to_yaml)
|
130
111
|
end
|
131
112
|
|
132
113
|
# def alterFile(fileObject, fileReferenceString, versionReferenceString)
|
data/lib/banners.rb
CHANGED
@@ -1,23 +1,49 @@
|
|
1
|
-
#
|
1
|
+
# open up string class, enable terminal colors
|
2
|
+
# add some colors, windowing methods
|
2
3
|
|
4
|
+
class String
|
5
|
+
def colorize(color, mod)
|
6
|
+
"\033[#{mod};#{color};49m#{self}\033[0;0m"
|
7
|
+
end
|
8
|
+
|
9
|
+
def reset() colorize(0,0) end
|
10
|
+
def blu() colorize(34,0) end
|
11
|
+
def yel() colorize(33,0) end
|
12
|
+
def grn() colorize(32,0) end
|
13
|
+
def red() colorize(31,0) end
|
14
|
+
end
|
15
|
+
|
16
|
+
# create large constant strings
|
3
17
|
|
4
18
|
HELP_BANNER = <<-EOS
|
5
|
-
Copernicium - simple DVCS
|
19
|
+
Copernicium (cn) - simple DVCS
|
6
20
|
|
7
|
-
Starting:
|
21
|
+
Starting out:
|
8
22
|
init - create a new repository
|
9
23
|
status - check repo status
|
24
|
+
help - show more commands
|
25
|
+
EOS
|
10
26
|
|
27
|
+
|
28
|
+
COMMAND_BANNER = <<-EOS
|
29
|
+
#{HELP_BANNER}
|
11
30
|
Commands:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
31
|
+
clean [files]
|
32
|
+
commit [files] -m <message>
|
33
|
+
checkout [files] <commit id>
|
34
|
+
branch [opt] [branchname]
|
35
|
+
-r | rename current branch
|
36
|
+
-c | create a new branch
|
37
|
+
merge <branch name>
|
38
|
+
clone <remote url>
|
39
|
+
push [remote name]
|
40
|
+
pull [remote name]
|
18
41
|
|
19
42
|
Options:
|
20
43
|
-v: print version
|
21
44
|
-h: show help
|
45
|
+
|
46
|
+
Note: [optional] <required>
|
47
|
+
|
22
48
|
EOS
|
23
49
|
|
data/lib/pushpull.rb
CHANGED
@@ -7,6 +7,25 @@
|
|
7
7
|
module Copernicium
|
8
8
|
class PushPull
|
9
9
|
|
10
|
+
# Chris's edit
|
11
|
+
# Takes in Ethan's UICommandCommunicator object and calls
|
12
|
+
# a method based on the command
|
13
|
+
def UICommandParser(ui_comm)
|
14
|
+
case ui_comm.command
|
15
|
+
when "clone"
|
16
|
+
#clone()
|
17
|
+
when "merge"
|
18
|
+
# do merge stuff
|
19
|
+
when "push"
|
20
|
+
#push(ui_comm.)
|
21
|
+
when "pull"
|
22
|
+
#pull(ui_comm.branchname,)
|
23
|
+
else
|
24
|
+
print "Error: Invalid command supplied to PushPull!" # Bad error handling, will fix later
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
10
29
|
def connect(remote, user = nil, passwd = nil, &block)
|
11
30
|
exit_code = false
|
12
31
|
if(block.nil?)
|
data/lib/repos.rb
CHANGED
@@ -1,14 +1,8 @@
|
|
1
|
-
# repos module
|
2
|
-
|
3
|
-
#require 'marshal'
|
4
|
-
# Details from this link:
|
5
|
-
# https://docs.google.com/document/d/1r3-NquhyRLbCncqTOQPwsznSZ-en6G6xzLbWIAmxhys/edit#heading=h.7pyingf1unu
|
6
|
-
|
7
|
-
|
8
1
|
# Repos Top Level Function Definitions (Logan)
|
9
2
|
|
10
3
|
# make_snapshot: Creates new snapshot from current files and versions
|
11
|
-
# in - array of file objects. file object = array of all versions:
|
4
|
+
# in - array of file objects. file object = array of all versions:
|
5
|
+
# {id, content}
|
12
6
|
# out - hash id of snapshot
|
13
7
|
|
14
8
|
# restore_snapshot: Set current file versions to specified snapshot
|
@@ -39,127 +33,133 @@
|
|
39
33
|
|
40
34
|
module Copernicium
|
41
35
|
class Snapshot
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
36
|
+
attr_accessor :id, :files
|
37
|
+
# id is computed after creation
|
38
|
+
def initialize(files = [])
|
39
|
+
@files = files
|
40
|
+
@id = id
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Repos
|
45
|
+
attr_reader :snaps
|
46
|
+
# read in file of snapshots (.cn/history)
|
47
|
+
# check the current branch (.cn/branch)
|
48
|
+
def initialize(root, branch = 'master')
|
49
|
+
@root = root
|
50
|
+
@copn = File.join(@root, '.cn')
|
51
|
+
@bpath = File.join(@copn, 'branch')
|
52
|
+
@spath = File.join(@copn, 'history')
|
53
|
+
|
54
|
+
# check if files exist, read them
|
55
|
+
if File.exist?(@spath) && File.exist?(@bpath)
|
56
|
+
@snaps = Marshal.read readFile(@spath)
|
57
|
+
@branch = readFile(@bpath)
|
58
|
+
else # use defaults
|
59
|
+
@snaps = {branch => []}
|
60
|
+
@branch = branch
|
61
|
+
end
|
46
62
|
end
|
47
63
|
|
48
|
-
|
49
|
-
|
64
|
+
# returns the hash if of an object
|
65
|
+
def hasher(obj)
|
66
|
+
Digest::SHA256.hexdigest Marshal.dump(obj)
|
50
67
|
end
|
51
68
|
|
52
|
-
#
|
53
|
-
def
|
54
|
-
|
69
|
+
# array of hashes constructor
|
70
|
+
def hash_array
|
71
|
+
Hash.new {[]}
|
55
72
|
end
|
56
73
|
|
57
|
-
|
58
|
-
|
74
|
+
# Return string array of what branches we have
|
75
|
+
def branches
|
76
|
+
@snaps.keys
|
59
77
|
end
|
60
|
-
# Initialize hash at startup
|
61
|
-
# Possible? Or problem with self object?
|
62
|
-
end
|
63
78
|
|
64
|
-
|
65
|
-
|
66
|
-
# Create manifest
|
67
|
-
# It's a list of snapshots in chronological order
|
68
|
-
@manifest = {"default" => []}
|
69
|
-
@curr_branch = "default"
|
70
|
-
# what to do about branch IDs?
|
71
|
-
# Read in project path and make manifest file?
|
72
|
-
# Create current
|
79
|
+
def update_snap
|
80
|
+
writeFile(@spath, Marshal.dump(@snaps))
|
73
81
|
end
|
74
82
|
|
75
|
-
def
|
76
|
-
@
|
83
|
+
def update_branch
|
84
|
+
writeFile(@bpath, @branch)
|
77
85
|
end
|
78
86
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
# Update
|
86
|
-
|
87
|
+
# Create snapshot, and return hash ID of snapshot
|
88
|
+
def make_snapshot(files = [])
|
89
|
+
snap = Snapshot.new(files)
|
90
|
+
snap.id = hasher snap
|
91
|
+
@snaps[@branch] << snap
|
92
|
+
|
93
|
+
# Update snaps file
|
94
|
+
update_snap
|
95
|
+
snap.id
|
87
96
|
end
|
88
97
|
|
98
|
+
# Find snapshot, return snapshot (or just contents) given id
|
89
99
|
def get_snapshot(target_id)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
# Handle not found case
|
94
|
-
# Return it
|
95
|
-
if(found_index)
|
96
|
-
return @manifest[@curr_branch][found_index]
|
100
|
+
found_index = @snaps[@branch].index { |x| x.id == target_id }
|
101
|
+
if found_index
|
102
|
+
@snaps[@branch][found_index]
|
97
103
|
else
|
98
|
-
|
104
|
+
Snapshot.new
|
99
105
|
end
|
100
|
-
#return ret_snap
|
101
106
|
end
|
102
107
|
|
103
|
-
#
|
108
|
+
# Return comm object with status
|
109
|
+
# change files in workspace back to specified commit
|
110
|
+
# get clear the current workspace
|
111
|
+
# revert back to given commit
|
104
112
|
def restore_snapshot(target_id)
|
105
|
-
#
|
106
|
-
# Need a way to change files in workspace
|
107
|
-
return 1
|
113
|
+
# todo
|
108
114
|
end
|
109
115
|
|
110
|
-
#
|
111
|
-
def history()
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
+
# Return array of snapshot IDs
|
117
|
+
def history(branch_name = nil)
|
118
|
+
snapids = []
|
119
|
+
if branch_name.nil?
|
120
|
+
@snaps[@branch].each {|x| snapids << x.id }
|
121
|
+
else
|
122
|
+
@snaps[branch_name].each{|x| snapids << x.id }
|
123
|
+
end
|
124
|
+
snapids
|
116
125
|
end
|
117
126
|
|
127
|
+
# Find snapshot, delete from snaps/memory
|
118
128
|
def delete_snapshot(target_id)
|
119
|
-
|
120
|
-
|
121
|
-
@manifest[@curr_branch].delete_if { |x| x.get_id() == target_id }
|
122
|
-
# catch error
|
123
|
-
# update manifest file?
|
129
|
+
@snaps[@branch].delete_if { |x| x.id == target_id }
|
130
|
+
update_snap
|
124
131
|
end
|
125
132
|
|
126
|
-
#
|
127
|
-
# Consider using diffy?
|
133
|
+
# Return list of filenames and versions
|
128
134
|
def diff_snapshots(id1, id2)
|
129
|
-
|
130
|
-
|
135
|
+
diffed = []
|
136
|
+
|
131
137
|
# Put in error catching
|
132
|
-
files1 = get_snapshot(id1).
|
133
|
-
files2 = get_snapshot(id2).
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
diff_files.push(x)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
return diff_files
|
141
|
-
# Use revlog diff on each set of files? Look at Diffy
|
142
|
-
end
|
138
|
+
files1 = get_snapshot(id1).files
|
139
|
+
files2 = get_snapshot(id2).files
|
140
|
+
|
141
|
+
# Find difference between snapshot1 and snapshot2
|
142
|
+
files1.each { |x| diffed << x unless !files2.include?(x) }
|
143
143
|
|
144
|
-
|
145
|
-
# Return hash ID of new branch
|
146
|
-
# Not sure where to store branches
|
147
|
-
# What goes in to the hash?
|
148
|
-
@manifest[branch_name] = @manifest[@curr_branch]
|
149
|
-
@curr_branch = branch_name
|
150
|
-
return 1
|
144
|
+
diffed
|
151
145
|
end
|
152
146
|
|
153
|
-
|
154
|
-
|
155
|
-
@
|
147
|
+
# Return hash ID of new branch
|
148
|
+
def make_branch(branch)
|
149
|
+
@snaps[branch] = @snaps[@branch]
|
150
|
+
@branch = branch
|
151
|
+
hasher 1
|
156
152
|
end
|
157
153
|
|
158
|
-
|
159
|
-
|
154
|
+
# Merge the target branch into current
|
155
|
+
def merge_branch(branch)
|
156
|
+
# todo
|
160
157
|
end
|
161
158
|
|
162
|
-
|
159
|
+
# Exit status code
|
160
|
+
def delete_branch(branch)
|
161
|
+
@snaps.delete(branch)
|
162
|
+
end
|
163
|
+
end # repo class
|
163
164
|
end
|
164
165
|
|
165
|
-
|
data/lib/required.rb
CHANGED
@@ -9,6 +9,8 @@ require 'socket' # Socket needed for communicating over the network
|
|
9
9
|
require 'io/console' # Needed to hide password at console
|
10
10
|
require 'net/ssh' # Needed to communicate with the remote
|
11
11
|
require 'net/scp' # Needed for file transfer between servers
|
12
|
+
#require 'marshal'
|
13
|
+
|
12
14
|
|
13
15
|
# coperncicium files
|
14
16
|
|
data/lib/ui.rb
CHANGED
@@ -2,9 +2,15 @@
|
|
2
2
|
# integrates all modules, central module
|
3
3
|
|
4
4
|
|
5
|
-
VERSION = "0.0.
|
5
|
+
VERSION = "0.0.2"
|
6
6
|
|
7
7
|
module Copernicium
|
8
|
+
# Print and exit with a specific code
|
9
|
+
def pexit(msg, sig)
|
10
|
+
puts msg
|
11
|
+
exit sig
|
12
|
+
end
|
13
|
+
|
8
14
|
class Driver
|
9
15
|
# Get some info from the user when they dont specify it
|
10
16
|
def get(info)
|
@@ -12,12 +18,6 @@ module Copernicium
|
|
12
18
|
gets.chomp # read a line from user, and return it
|
13
19
|
end
|
14
20
|
|
15
|
-
# Print and exit with a specific code
|
16
|
-
def pexit(msg, sig)
|
17
|
-
puts msg
|
18
|
-
exit sig
|
19
|
-
end
|
20
|
-
|
21
21
|
# Executes the required action for a given user command.
|
22
22
|
#
|
23
23
|
# Parameters:
|
@@ -37,7 +37,7 @@ module Copernicium
|
|
37
37
|
cmd = args.shift
|
38
38
|
|
39
39
|
# if no arguments given show help information
|
40
|
-
pexit
|
40
|
+
pexit COMMAND_BANNER, 0 if (cmd == '-h' || cmd == 'help')
|
41
41
|
|
42
42
|
# if -v flag givem show version
|
43
43
|
pexit VERSION, 0 if cmd == '-v'
|
@@ -48,6 +48,10 @@ module Copernicium
|
|
48
48
|
init args
|
49
49
|
when 'status'
|
50
50
|
status args
|
51
|
+
when 'branch'
|
52
|
+
branch args
|
53
|
+
when 'clean'
|
54
|
+
clean args
|
51
55
|
when 'clone'
|
52
56
|
clone args
|
53
57
|
when 'commit'
|
@@ -61,18 +65,34 @@ module Copernicium
|
|
61
65
|
when 'pull'
|
62
66
|
pull args
|
63
67
|
else # handle an unrecognized argument, show help and exit
|
64
|
-
pexit "Unrecognized command #{cmd}\n" +
|
68
|
+
pexit "Unrecognized command #{cmd}\n" + COMMAND_BANNER, 1
|
65
69
|
end
|
66
70
|
end # run
|
67
71
|
|
68
72
|
def init(args)
|
73
|
+
if args.nil?
|
74
|
+
Workspace.new
|
75
|
+
else # init into a folder
|
76
|
+
target = File.join Dir.pwd, args.join(' ')
|
77
|
+
Dir.mkdir target if !File.exists? target
|
78
|
+
Dir.chdir target
|
79
|
+
Workspace.new
|
80
|
+
end
|
81
|
+
puts "Created Copernicium repo in " + Dir.pwd
|
69
82
|
UIComm.new(command: 'init', opts: args)
|
70
|
-
# todo - make call to repos to create repo
|
71
83
|
end
|
72
84
|
|
73
85
|
def status(args)
|
74
|
-
UIComm.new(command: 'status', opts: args)
|
75
|
-
|
86
|
+
ui = UIComm.new(command: 'status', opts: args)
|
87
|
+
st = Workspace.new.status(ui)
|
88
|
+
puts "added:".grn + st[0].join(', ') unless st[0].empty?
|
89
|
+
puts "edited:".yel + st[1].join(', ') unless st[1].empty?
|
90
|
+
puts "removed:".red + st[2].join(', ') unless st[2].empty?
|
91
|
+
ui
|
92
|
+
end
|
93
|
+
|
94
|
+
def branch(args)
|
95
|
+
# todo - switch branches, create branches
|
76
96
|
end
|
77
97
|
|
78
98
|
def push(args)
|
@@ -93,12 +113,20 @@ module Copernicium
|
|
93
113
|
files = args
|
94
114
|
end
|
95
115
|
|
96
|
-
# todo - call repos checkout the given / branch
|
97
116
|
# todo - also, figure out if is branch or rev id
|
98
117
|
# this can be done by checking if it is a branch, and if not, then just
|
99
118
|
# assume it is a rev id. if it isnt, then something will break :/
|
100
119
|
|
101
|
-
|
120
|
+
# call workspace checkout the given / branch
|
121
|
+
ui = UIComm.new(command: 'checkout', rev: rev, files: files)
|
122
|
+
Workspace.new.checkout(ui)
|
123
|
+
ui
|
124
|
+
end
|
125
|
+
|
126
|
+
def clean(args = [])
|
127
|
+
ui = UIComm.new(command: 'clean', files: args)
|
128
|
+
Workspace.new.clean(ui)
|
129
|
+
ui
|
102
130
|
end
|
103
131
|
|
104
132
|
def clone(args)
|
@@ -118,21 +146,26 @@ module Copernicium
|
|
118
146
|
messflag = args.find_index('-m')
|
119
147
|
if messflag.nil?
|
120
148
|
message = get 'commit message'
|
121
|
-
|
149
|
+
elsif message == 0 # commit everything
|
150
|
+
# mash everything after -m into a string
|
122
151
|
message = args[messflag + 1..-1].join ' '
|
152
|
+
else # commit only some files
|
153
|
+
files = args[0..messflag - 1]
|
123
154
|
end
|
124
155
|
|
125
|
-
#
|
126
|
-
|
127
|
-
# todo call repos, update commit
|
156
|
+
# specified the -m flag, but didnt give anything
|
157
|
+
message = get 'commit message' if message.nil?
|
128
158
|
|
129
|
-
|
159
|
+
# perform the commit, with workspace
|
160
|
+
ui = UIComm.new(command: 'commit', files: files, commit_message: message)
|
161
|
+
Workspace.new.commit(ui)
|
162
|
+
ui
|
130
163
|
end
|
131
164
|
|
132
165
|
def merge(args)
|
133
166
|
if args.empty?
|
134
|
-
puts 'I need a commit to merge.'
|
135
|
-
rev = get 'single commit to merge'
|
167
|
+
puts 'I need a commit or branch to merge.'
|
168
|
+
rev = get 'single commit or branch to merge'
|
136
169
|
else # use given
|
137
170
|
rev = args.first
|
138
171
|
end
|
data/lib/workspace.rb
CHANGED
@@ -1,12 +1,24 @@
|
|
1
|
-
#
|
2
|
-
# The functions are clean, commit, checkout and status
|
1
|
+
# workspace module - linfeng and qiguang
|
3
2
|
|
4
3
|
module Copernicium
|
4
|
+
def writeFile(path, content)
|
5
|
+
f = open(path, 'w')
|
6
|
+
f.write(content)
|
7
|
+
f.close
|
8
|
+
end
|
9
|
+
|
10
|
+
def readFile(path)
|
11
|
+
f = open(path, 'r')
|
12
|
+
txt = f.read
|
13
|
+
f.close
|
14
|
+
txt
|
15
|
+
end
|
16
|
+
|
5
17
|
class FileObj
|
6
|
-
attr_reader :path, :
|
18
|
+
attr_reader :path, :history
|
7
19
|
def initialize(path, ids)
|
20
|
+
@history = ids
|
8
21
|
@path = path
|
9
|
-
@history_hash_ids = ids
|
10
22
|
end
|
11
23
|
|
12
24
|
def ==(rhs)
|
@@ -19,30 +31,35 @@ module Copernicium
|
|
19
31
|
end
|
20
32
|
|
21
33
|
class Workspace
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
attr_reader :repos, :revlog
|
35
|
+
def initialize(bname = 'master')
|
36
|
+
@files = []
|
37
|
+
@cwd = Dir.pwd
|
38
|
+
@root = getroot
|
39
|
+
Dir.chdir(@cwd)
|
40
|
+
@root = @cwd if @root.nil?
|
41
|
+
@cwd.sub!(@root, '.')
|
42
|
+
@branch = bname
|
43
|
+
@repo = Repos.new(@cwd)
|
44
|
+
@revlog = RevLog.new(@cwd)
|
45
|
+
|
46
|
+
pexit 'Copernicium folder (.cn) not found.', 1 if @root.nil?
|
33
47
|
end
|
34
48
|
|
35
|
-
#
|
36
|
-
|
49
|
+
# find where the root .cn folder is
|
50
|
+
def getroot
|
51
|
+
max = 0
|
52
|
+
def notroot() Dir.pwd != '/' end
|
53
|
+
def notcn() File.exists? File.join(Dir.pwd, '.cn') end
|
54
|
+
while max < 10 && notroot && notcn
|
55
|
+
Dir.chdir(File.join(Dir.pwd, '..'))
|
56
|
+
max += 1
|
57
|
+
end
|
37
58
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@repos = Copernicium::Repos.new
|
43
|
-
@root = rootdir
|
44
|
-
if !File.directory?(@root)
|
45
|
-
Dir.mkdir(@root)
|
59
|
+
if notcn # return where cn was found
|
60
|
+
Dir.pwd
|
61
|
+
else # directory not found
|
62
|
+
nil
|
46
63
|
end
|
47
64
|
end
|
48
65
|
|
@@ -58,70 +75,53 @@ module Copernicium
|
|
58
75
|
end
|
59
76
|
|
60
77
|
# if include all the elements in list_files
|
61
|
-
def include?(
|
62
|
-
|
63
|
-
if indexOf(x) == -1
|
64
|
-
return false
|
65
|
-
end
|
66
|
-
end
|
78
|
+
def include?(files)
|
79
|
+
files.each { |x| return false if indexOf(x) == -1 }
|
67
80
|
true
|
68
81
|
end
|
69
82
|
|
83
|
+
# get all files currently in workspace
|
84
|
+
def ws_files
|
85
|
+
Dir[ File.join(@root, '**', '*') ].reject { |p| File.directory? p }
|
86
|
+
end
|
87
|
+
|
88
|
+
# Clear the current workspace
|
89
|
+
def clear
|
90
|
+
@files.each{ |x| File.delete(x.path) }
|
91
|
+
@files = []
|
92
|
+
end
|
93
|
+
|
94
|
+
# reset first: delete them from disk and reset @files
|
95
|
+
# restore it with checkout() if we have had a branch name
|
96
|
+
# or it is the initial state, no commit and no checkout
|
70
97
|
# if list_files is nil, then rollback the list of files from the branch
|
71
98
|
# or rollback to the entire branch head pointed
|
72
99
|
def clean(comm)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
# restore it with checkout() if we have had a branch name
|
78
|
-
if @branch_name != ''
|
79
|
-
# or it is the initial state, no commit and no checkout
|
80
|
-
return checkout(@branch_name)
|
81
|
-
else
|
82
|
-
return 0
|
83
|
-
end
|
100
|
+
if comm.files.empty?
|
101
|
+
clear # reset, checkout last commit
|
102
|
+
checkout
|
103
|
+
else # list_files are not nil
|
84
104
|
|
85
|
-
|
86
|
-
|
87
|
-
#workspace_files_paths = @files.each{|x| x.path}
|
88
|
-
return -1 if (self.include? list_files) == false
|
105
|
+
# exit if the specified file is not in the workspace
|
106
|
+
return -1 if (self.include? comm.files) == false
|
89
107
|
|
90
108
|
# the actual action, delete all of them from the workspace first
|
91
|
-
|
109
|
+
comm.files.each do |x|
|
92
110
|
File.delete(x)
|
93
111
|
idx = indexOf(x)
|
94
|
-
if !idx
|
95
|
-
@files.delete_at(idx)
|
96
|
-
end
|
112
|
+
@files.delete_at(idx) if !idx == -1
|
97
113
|
end
|
98
114
|
|
99
115
|
# if we have had a branch, first we get the latest snapshot of it
|
100
116
|
# and then checkout with the restored version of them
|
101
|
-
|
102
|
-
return checkout(list_files)
|
103
|
-
else
|
104
|
-
return 0
|
105
|
-
end
|
117
|
+
checkout
|
106
118
|
end
|
107
119
|
end
|
108
120
|
|
109
121
|
# commit a list of files or the entire workspace to make a new snapshot
|
110
122
|
def commit(comm)
|
111
|
-
|
112
|
-
|
113
|
-
# Linfeng Song
|
114
|
-
#list_files = @files.each{|x| x.path}
|
115
|
-
#if comm.files != nil
|
116
|
-
# comm.files.each do |x|
|
117
|
-
# if indexOf(x) == -1
|
118
|
-
# list_files.push(x)
|
119
|
-
# end
|
120
|
-
# end
|
121
|
-
#end
|
122
|
-
list_files = Dir[ File.join(@root, '**', '*') ].reject { |p| File.directory? p }
|
123
|
-
if list_files != nil
|
124
|
-
list_files.each do |x|
|
123
|
+
unless ws_files.empty?
|
124
|
+
ws_files.each do |x|
|
125
125
|
if indexOf(x) == -1
|
126
126
|
content = readFile(x)
|
127
127
|
hash = @revlog.add_file(x, content)
|
@@ -130,82 +130,77 @@ module Copernicium
|
|
130
130
|
else
|
131
131
|
content = readFile(x)
|
132
132
|
hash = @revlog.add_file(x, content)
|
133
|
-
if @files[indexOf(x)].
|
134
|
-
@files[indexOf(x)].
|
133
|
+
if @files[indexOf(x)].history[-1] != hash
|
134
|
+
@files[indexOf(x)].history << hash
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
139
|
-
|
139
|
+
@repo.make_snapshot(@files) # return snapshot id
|
140
140
|
end
|
141
141
|
|
142
|
-
def checkout(comm)
|
143
|
-
|
144
|
-
#
|
145
|
-
if argu
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
142
|
+
def checkout(comm = UIComm.new(rev: @branch))
|
143
|
+
=begin
|
144
|
+
# just support branches for now
|
145
|
+
# if argu is an Array Object, we assume it is a list of files to be added
|
146
|
+
# # to the workspace # we add the list of files to @files regardless
|
147
|
+
# whether it has been in # it. that means there may be multiple versions
|
148
|
+
# of a file.
|
149
|
+
unless comm.files.nil?
|
150
|
+
list_files = comm.files
|
151
|
+
returned_snapshot = @repo.get_snapshot(@repo.history.last)
|
152
|
+
list_files_last_commit = returned_snapshot.files
|
152
153
|
list_files_last_commit.each do |x|
|
153
154
|
if list_files.include? x.path
|
154
|
-
|
155
|
-
content = @revlog.get_file(x.history_hash_ids[-1])
|
155
|
+
content = @revlog.get_file(x.history.last)
|
156
156
|
idx = indexOf(x.path)
|
157
157
|
if idx == -1
|
158
|
-
@files
|
158
|
+
@files << x
|
159
159
|
else
|
160
160
|
@files[idx] = x
|
161
161
|
end
|
162
|
-
writeFile(path,content)
|
162
|
+
writeFile(x.path, content)
|
163
163
|
end
|
164
164
|
end
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
path = fff.path
|
180
|
-
content = @revlog.get_file(fff.history_hash_ids[-1])
|
181
|
-
writeFile(path,content)
|
165
|
+
else # if argu is not an Array, we assume it is a String, representing the
|
166
|
+
end
|
167
|
+
=end
|
168
|
+
|
169
|
+
clear # reset workspace
|
170
|
+
|
171
|
+
# we first get the last snapshot id of the branch, and then get the commit
|
172
|
+
# object and finally push all files of it to the # workspace
|
173
|
+
@repo.get_snapshot(@repo.history.last).files.each do |file|
|
174
|
+
idx = indexOf(file.path)
|
175
|
+
if idx == -1
|
176
|
+
@files << file
|
177
|
+
else
|
178
|
+
@files[idx] = file
|
182
179
|
end
|
180
|
+
content = @revlog.get_file(file.history.last)
|
181
|
+
writeFile(file.path, content)
|
183
182
|
end
|
184
183
|
end
|
185
184
|
|
186
185
|
def status(comm)
|
187
|
-
|
188
|
-
deletes = []
|
186
|
+
added = []
|
189
187
|
edits = []
|
190
|
-
|
191
|
-
|
188
|
+
remov = []
|
189
|
+
ws_files.each do |f|
|
192
190
|
idx = indexOf(f)
|
193
|
-
if idx
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
else
|
200
|
-
adds.push(f)
|
191
|
+
if idx == -1 # new file
|
192
|
+
added << f
|
193
|
+
else # changed file?
|
194
|
+
x2 = readFile(f) # get the current version
|
195
|
+
x1 = @revlog.get_file(@files[idx].history.last)
|
196
|
+
edits << f if x1 != x2
|
201
197
|
end
|
202
198
|
end
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
return [adds, edits, deletes]
|
199
|
+
|
200
|
+
# any deleted files from the last commit?
|
201
|
+
@files.each { |f| remov << f.path unless (ws_files.include? f.path) }
|
202
|
+
|
203
|
+
[added, edits, remov]
|
209
204
|
end
|
210
205
|
end
|
211
206
|
end
|
metadata
CHANGED
@@ -1,113 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copernicium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Team Copernicium
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diffy
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
-
- -
|
20
|
+
- - '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 3.0.7
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '3.0'
|
30
|
-
- -
|
30
|
+
- - '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 3.0.7
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: net-scp
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - ~>
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '1.2'
|
40
|
-
- -
|
40
|
+
- - '>='
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 1.2.1
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ~>
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '1.2'
|
50
|
-
- -
|
50
|
+
- - '>='
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 1.2.1
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: net-ssh
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
|
-
- -
|
57
|
+
- - ~>
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '3.0'
|
60
|
-
- -
|
60
|
+
- - '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: 3.0.1
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '3.0'
|
70
|
-
- -
|
70
|
+
- - '>='
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: 3.0.1
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: minitest
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
|
-
- -
|
77
|
+
- - ~>
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '5.8'
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 5.8.1
|
83
83
|
type: :development
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '5.8'
|
90
|
-
- -
|
90
|
+
- - '>='
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: 5.8.1
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: minitest-reporters
|
95
95
|
requirement: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
-
- -
|
97
|
+
- - ~>
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '1.1'
|
100
|
-
- -
|
100
|
+
- - '>='
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: 1.1.4
|
103
103
|
type: :development
|
104
104
|
prerelease: false
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- -
|
107
|
+
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '1.1'
|
110
|
-
- -
|
110
|
+
- - '>='
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: 1.1.4
|
113
113
|
description: A simple distributed version control system written in Ruby.
|
@@ -135,12 +135,12 @@ require_paths:
|
|
135
135
|
- lib
|
136
136
|
required_ruby_version: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
|
-
- -
|
138
|
+
- - '>='
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - '>='
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
requirements: []
|