Class RSCM::ClearCase
In: lib/rscm/scm/clearcase.rb
Parent: Base

Methods

Constants

LOG_FORMAT = "- !ruby/object:RSCM::RevisionFile\\n developer: %u\\n time: \\\"%Nd\\\"\\n native_revision_identifier: %Vn\\n previous_native_revision_identifier: %PVn\\n path: %En\\n status: %o\\n message: \\\"%Nc\\\"\\n\\n"
TIME_FORMAT = "%d-%b-%Y.%H:%M:%S"
MAGIC_TOKEN = "9q8w7e6r5t4y"
STATUSES = { "checkin" => RevisionFile::MODIFIED, "mkelem" => RevisionFile::ADDED, "rmelem" => RevisionFile::DELETED, }
DEFAULT_CONFIG_SPEC = "element * CHECKEDOUT\nelement * /main/LATEST"

Attributes

config_spec  [RW] 
stgloc  [RW] 
stream  [RW] 
tag  [RW] 

Public Class methods

[Source]

    # File lib/rscm/scm/clearcase.rb, line 23
23:     def initialize(stream=nil, stgloc=nil, tag=nil, config_spec=DEFAULT_CONFIG_SPEC)
24:       @stream, @stgloc, @tag, @config_spec = stream, stgloc, tag, config_spec
25:     end

Public Instance methods

[Source]

     # File lib/rscm/scm/clearcase.rb, line 115
115:     def catcs(options={})
116:       Dir.chdir(checkout_dir) do
117:         catcs_cmd = "cleartool catcs"
118:         execute(catcs_cmd, options) do |io|
119:           yield io
120:         end
121:       end
122:     end

[Source]

    # File lib/rscm/scm/clearcase.rb, line 74
74:     def checked_out?
75:       !Dir["#{checkout_dir}/*"].empty?
76:     end

[Source]

    # File lib/rscm/scm/clearcase.rb, line 78
78:     def destroy_working_copy(options={})
79:       execute("cleartool rmview #{checkout_dir}", options) do |io|
80:         io.read
81:       end
82:     end

[Source]

    # File lib/rscm/scm/clearcase.rb, line 84
84:     def import_central(options={})
85:       execute("clearfsimport -recurse -nsetevent #{options[:dir]} #{checkout_dir}", options) do |io|
86:         io.read
87:       end
88:     end

What’s loaded into view

[Source]

     # File lib/rscm/scm/clearcase.rb, line 133
133:     def load_rules
134:       result = []
135:       catcs do |io|
136:         io.each_line do |line|
137:           if(line =~ /^load[\s]*(.*)$/)
138:             return result << $1
139:           end
140:         end
141:       end
142:       result
143:     end

Non-RSCM API methods

[Source]

    # File lib/rscm/scm/clearcase.rb, line 92
92:     def mkview!(options={})
93:        # Create view (working copy)
94:        mkview_cmd = "cleartool mkview -snapshot -stream #{@stream} -stgloc #{@stgloc} -tag #{@tag} #{@checkout_dir}"
95:        execute(mkview_cmd, options) do |io|
96:          puts io.read
97:        end
98:     end

[Source]

    # File lib/rscm/scm/clearcase.rb, line 27
27:     def revisions(from_identifier, options={})
28:       options = {
29:         :from_identifier => from_identifier,
30:         :to_identifier => Time.infinity, 
31:         :relative_path => nil
32:       }.merge(options)
33: 
34:       checkout unless checked_out?
35:       rules = load_rules
36:       vob = vob(rules[0])
37:       result = Revisions.new
38:       
39:       unless vob
40:         STDERR.puts "No vob found. Please set load rules in the view: #{checkout_dir}"
41:         return result 
42:       end
43:       with_working_dir(checkout_dir) do
44:         since = (from_identifier + 1).strftime(TIME_FORMAT)
45:         cmd = "cleartool lshistory -recurse -nco -since #{since} -fmt \"#{LOG_FORMAT}\" -pname #{vob}"
46:         execute(cmd, options) do |io|
47:           # escape all quotes, except the one at the beginning and end. this is a bit ugly...
48:           raw_yaml = io.read
49:           fixed_yaml = raw_yaml.gsub(/^  message: \"/, "  message: #{MAGIC_TOKEN}")
50:           fixed_yaml = fixed_yaml.gsub(/\"\n\n/, "#{MAGIC_TOKEN}\n\n")
51:           fixed_yaml = fixed_yaml.gsub(/\"/, "\\\"")
52:           fixed_yaml = fixed_yaml.gsub(MAGIC_TOKEN, "\"")
53:  
54:           files = YAML.load(fixed_yaml)
55:           files.each do |file|
56:             file.path.gsub!(/\\/, "/")
57:             file.status = STATUSES[file.status]
58:             rev = revision(file.native_revision_identifier)
59:             if(rev && matches_load_rules?(rules, file.path))
60:               file.native_revision_identifier = rev
61:               file.previous_native_revision_identifier = revision(file.previous_native_revision_identifier)
62:               t = file.time
63:               # the time now has escaped quotes..
64:               file.time = Time.utc(t[2..5],t[6..7],t[8..9],t[11..12],t[13..14],t[15..16])
65:               file.message.strip!
66:               result.add(file)
67:             end
68:           end
69:         end
70:       end
71:       result
72:     end

[Source]

     # File lib/rscm/scm/clearcase.rb, line 100
100:     def update_load_rules!(options={})
101:       Dir.chdir(checkout_dir) do
102:         # tempfile is broken on windows (!!)
103:         cfg_spec_file = "__rscm.cfgspec"
104:         config_spec_file = File.open(cfg_spec_file, "w") do |io|
105:           io.write(@config_spec)
106:         end
107: 
108:         setcs_cmd = "cleartool setcs #{cfg_spec_file}"
109:         Better.popen(setcs_cmd, "w") do |io|
110:           io.write "yes\n"
111:         end
112:       end
113:     end

[Source]

     # File lib/rscm/scm/clearcase.rb, line 124
124:     def vob(load_rule)
125:       if(load_rule =~ /[\\\/]*([\w]*)/)
126:         $1
127:       else
128:         nil
129:       end
130:     end

Protected Instance methods

[Source]

     # File lib/rscm/scm/clearcase.rb, line 147
147:     def checkout_silent(to_identifier, options={}, &proc)
148:       if(checked_out?)
149:         execute("cleartool update .", options)
150:       else
151:         mkview!
152:  
153:         # Set load rules (by setting config spec)
154:         #update_load_rules!
155:       end
156:     end

Administrative files that should be ignored when counting files.

[Source]

     # File lib/rscm/scm/clearcase.rb, line 159
159:     def ignore_paths
160:       return [/.*\.updt/]
161:     end

[Validate]