Class: Origen::RevisionControl::DesignSync
- Inherits:
-
Base
show all
- Defined in:
- lib/origen/revision_control/design_sync.rb
Instance Attribute Summary
Attributes inherited from Base
#local, #remote
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#dssc?, #git?, #initialize, #svn?
Class Method Details
.remote_check_in(dir, options = {}) ⇒ Object
Check in the contents of the given directory to a remote vault location, meaning a vault location that is not necessarily associated with the current workspace that the given files are in.
Anything found in the given directory will be checked in, even files which are not currently under revision control.
No attempt will be made to merge the current vault contents with the local data, the local data will always be checked in as latest.
A tag can be optionally supplied and if present will be applied to the files post check in.
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/origen/revision_control/design_sync.rb', line 18
def self.remote_check_in(dir, options = {})
options = {
force: true
}.merge(options)
dir = Pathname.new(dir)
fail "Directory does not exist: #{dir}" unless dir.exist?
fail "Only directories are supported by remote_check_in, this is not a directory: #{dir}" unless dir.directory?
fail 'No vault option supplied to remote_check_in!' unless options[:vault]
scratch = Pathname.new("#{Origen.app.workspace_manager.imports_directory}/design_sync/scratch")
FileUtils.rm_rf(scratch) if scratch.exist?
FileUtils.mkdir_p(scratch)
FileUtils.cp_r("#{dir}/.", scratch)
remove_dot_syncs!(scratch)
ds = new(remote: options[:vault], local: scratch)
ds.checkin(options)
ds.tag(options[:tag], options) if options[:tag]
FileUtils.rm_rf(scratch)
end
|
.remove_dot_syncs!(dir, options = {}) ⇒ Object
Recursively remove all .SYNC directories from the given directory
39
40
41
42
43
44
45
46
|
# File 'lib/origen/revision_control/design_sync.rb', line 39
def self.remove_dot_syncs!(dir, options = {})
dir = Pathname.new(dir)
fail "Directory does not exist: #{dir}" unless dir.exist?
fail "Only directories are supported by remove_dot_syncs, this is not a directory: #{dir}" unless dir.directory?
Dir.glob("#{dir}/**/.SYNC").sort.each do |dot_sync|
FileUtils.rm_rf(dot_sync)
end
end
|
Instance Method Details
#build(options = {}) ⇒ Object
48
49
50
|
# File 'lib/origen/revision_control/design_sync.rb', line 48
def build(options = {})
checkout(options)
end
|
#changes(dir = nil, options = {}) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/origen/revision_control/design_sync.rb', line 88
def changes(dir = nil, options = {})
paths, options = clean_path(dir, options)
options = {
verbose: false
}.merge(options)
cmd = 'compare -rec -path -report silent'
if options[:version]
cmd += " -selector #{prefix_tag(options[:version])}"
end
cmd += " #{paths.first}"
objects = {
added: [], removed: [], changed: []
}
dssc(cmd, options).each do |line|
unless line =~ /Unmanaged/
if line =~ /\s*(\S+)\s+First only\s+(\S+)\s*/
objects[:added] << Regexp.last_match[2]
elsif line =~ /\s*(\S+)\s+Second only\s+(\S+)\s*/
objects[:removed] << Regexp.last_match[2]
elsif line =~ /\s*\S+\s+(\(Locally Modified\))?\s*(\S+)\s+Different (versions|states)\s+(\S+)\s*/
objects[:changed] << Regexp.last_match[4]
end
end
end
objects[:present] = !objects[:added].empty? || !objects[:removed].empty? || !objects[:changed].empty?
objects[:added].map! { |i| "#{paths.first}/" + i }
objects[:removed].map! { |i| "#{paths.first}/" + i }
objects[:changed].map! { |i| "#{paths.first}/" + i }
objects
end
|
#checkin(path = nil, options = {}) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/origen/revision_control/design_sync.rb', line 69
def checkin(path = nil, options = {})
paths, options = clean_path(path, options)
cmd = 'ci'
cmd += ' -rec -keep'
cmd += ' -skip' if options[:force]
cmd += ' -new' if options[:unmanaged] || options[:force]
if options[:comment] && !options[:comment].strip.empty?
cmd += " -com \"#{options[:comment].strip}\""
else
cmd += ' -com None'
end
paths = paths.join(' ')
dssc("#{cmd} #{paths}", options)
`chmod a+w -R #{paths}`
paths
end
|
#checkout(path = nil, options = {}) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/origen/revision_control/design_sync.rb', line 52
def checkout(path = nil, options = {})
paths, options = clean_path(path, options)
cmd = 'pop'
cmd += ' -rec -get -uni'
cmd += ' -force' if options[:force]
if options[:version]
cmd += " -version #{prefix_tag(options[:version])}"
else
cmd += ' -merge' unless options[:force]
end
paths = paths.join(' ')
dssc("#{cmd} #{paths}", options)
`chmod a+w -R #{paths}`
paths
end
|
#current_branch ⇒ Object
235
236
237
|
# File 'lib/origen/revision_control/design_sync.rb', line 235
def current_branch
dssc("url selector #{local}", verbose: false).first
end
|
#diff_cmd(file, version) ⇒ Object
174
175
176
|
# File 'lib/origen/revision_control/design_sync.rb', line 174
def diff_cmd(file, version)
"dssc diff -gui -ver #{prefix_tag(version)} #{file}"
end
|
#local_modifications(dir = nil, options = {}) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/origen/revision_control/design_sync.rb', line 135
def local_modifications(dir = nil, options = {})
paths, options = clean_path(dir, options)
options = {
verbose: false
}.merge(options)
cmd = 'ls -rec -managed -path -report N -modified -format text'
cmd += " #{paths.first}"
files = dssc(cmd, options).reject do |item|
item.strip.empty? ||
item =~ /^(Name|Directory|---)/
end
files.map! do |file|
file.strip! file.sub!(/^#{full_path_prefix}/, '')
file.sub('|', ':')
file.sub!(/^/, "#{paths.first}/")
end
end
|
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/origen/revision_control/design_sync.rb', line 189
def root
Origen.app.session.dssc["root-#{local}"] ||= begin
root = local
temp_parent_array = Array.new(0)
temp_parent_vault_array = Array.new(0)
resolved = false
vault = dssc("url vault #{root}").first
until resolved || root.root?
parent = root.parent
temp_parent_array.push(parent.to_s)
if File.exist?("#{parent}/.SYNC")
parent_vault = dssc("url vault #{parent}").first
temp_parent_vault_array.push(parent_vault.to_s)
if vault.to_s =~ /^#{parent_vault}/ && vault.to_s != parent_vault.to_s
root = parent
else
if temp_parent_vault_array.uniq.length == temp_parent_vault_array.length
resolved = true
else
fault_dir = temp_parent_array[-2]
fault_dir_name = fault_dir.split('/')[-1]
Origen.log.error 'DesignSync returns same vault locations for two directories.'
Origen.log.error 'Please resolve the workspace conflicts before continuing'
Origen.app.session.dssc["root-#{local}"] = nil
scratch = Pathname.new("#{local}/.ref")
FileUtils.rm_rf(scratch) if scratch.exist?
abort
end
end
else
resolved = true
end
end
root
end
end
|
#tag(id, options = {}) ⇒ Object
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/origen/revision_control/design_sync.rb', line 178
def tag(id, options = {})
id = VersionString.new(id)
id = id.prefixed if id.semantic?
replace = options[:force] ? '-replace' : ''
dssc "tag #{id} -rec #{replace} *"
dssc "tag #{id} #{replace} .*"
end
|
#unmanaged(dir = nil, options = {}) ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/origen/revision_control/design_sync.rb', line 156
def unmanaged(dir = nil, options = {})
paths, options = clean_path(dir, options)
options = {
verbose: false
}.merge(options)
cmd = 'ls -rec -unmanaged -fullpath -report N -modified -format text'
cmd += " #{paths.first}"
files = dssc(cmd, options).reject do |item|
item =~ /^(Name|Directory|---)/ || item.strip.empty?
end
files.map! do |file|
file.strip! file.sub!(/^#{full_path_prefix}/, '')
file.sub('|', ':')
end
end
|