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
.import(path_to_file_in_vault, options = {}) ⇒ Object
Import a file to the local workspace from another vault, where the first argument must include the full path to the requested file in the vault. You can optionally supply a destination for where you want the file to end up via the :local option, if no destination is supplied the file will end up in the PWD.
This is a DesignSync only API and can be used in cases where you would to fetch a file directly from a vault without setting up an association between a local directory and the vault. i.e. it will not create or modify an existing .SYNC in the local destination directory.
Example
file = "sync://sync-15088:15088/Projects/common_tester_blocks/rgen/lib/sys/design_sync.rb"
version = "v0.1.0"
import(file, version: version, local: RGen.root)
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/origen/revision_control/design_sync.rb', line 54
def self.import(path_to_file_in_vault, options = {})
options = {
verbose: true,
version: 'Latest'
}.merge(options)
if options[:verbose]
puts 'Importing from DesignSync...'
puts "#{path_to_file_in_vault} #{options[:version]}"
end
dir = path_to_file_in_vault.split('/')
file = dir.pop
dir = dir.join('/')
cmd = "import -version #{options[:version]} -force #{dir} #{file}"
dssc(cmd, verbose: false)
if Origen.os.windows?
system("move /Y #{file} #{options[:local]}/.") if options[:local]
else
system("mv -f #{file} #{options[:local]}/.") if options[:local]
end
end
|
.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
76
77
78
79
80
81
82
83
|
# File 'lib/origen/revision_control/design_sync.rb', line 76
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
85
86
87
|
# File 'lib/origen/revision_control/design_sync.rb', line 85
def build(options = {})
checkout(options)
end
|
#changes(dir = nil, options = {}) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/origen/revision_control/design_sync.rb', line 125
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/origen/revision_control/design_sync.rb', line 106
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/origen/revision_control/design_sync.rb', line 89
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
272
273
274
|
# File 'lib/origen/revision_control/design_sync.rb', line 272
def current_branch
dssc("url selector #{local}", verbose: false).first
end
|
#diff_cmd(file, version) ⇒ Object
211
212
213
|
# File 'lib/origen/revision_control/design_sync.rb', line 211
def diff_cmd(file, version)
"dssc diff -gui -ver #{prefix_tag(version)} #{file}"
end
|
#local_modifications(dir = nil, options = {}) ⇒ Object
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/origen/revision_control/design_sync.rb', line 172
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
|
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
# File 'lib/origen/revision_control/design_sync.rb', line 226
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
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/origen/revision_control/design_sync.rb', line 215
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/origen/revision_control/design_sync.rb', line 193
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
|