Class: RSCM::Cvs

Inherits:
Base
  • Object
show all
Defined in:
lib/rscm/scm/cvs.rb

Overview

RSCM implementation for CVS.

You need a cvs executable on the PATH in order for it to work.

NOTE: On Cygwin this has to be the win32 build of cvs and not the Cygwin one.

Constant Summary

Constants inherited from Base

Base::DEFAULT_QUIET_PERIOD, Base::THIRTY_TWO_WEEKS_AGO, Base::TWO_WEEKS_AGO

Instance Attribute Summary collapse

Attributes inherited from Base

#default_options, #logger

Instance Method Summary collapse

Methods inherited from Base

#==, #checkout, #checkout_commandline, #checkout_dir, #checkout_dir=, #destroy_working_copy, #edit, #file, #poll_new_revisions, #rootdir, #to_identifier, #to_yaml_properties, #transactional?, #update_commandline

Constructor Details

#initialize(root = nil, mod = nil, branch = nil, password = nil) ⇒ Cvs

Returns a new instance of Cvs.



20
21
22
# File 'lib/rscm/scm/cvs.rb', line 20

def initialize(root=nil, mod=nil, branch=nil, password=nil)
  @root, @mod, @branch, @password = root, mod, branch, password
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



17
18
19
# File 'lib/rscm/scm/cvs.rb', line 17

def branch
  @branch
end

#modObject

Returns the value of attribute mod.



16
17
18
# File 'lib/rscm/scm/cvs.rb', line 16

def mod
  @mod
end

#passwordObject

Returns the value of attribute password.



18
19
20
# File 'lib/rscm/scm/cvs.rb', line 18

def password
  @password
end

#rootObject

Returns the value of attribute root.



15
16
17
# File 'lib/rscm/scm/cvs.rb', line 15

def root
  @root
end

Instance Method Details

#add(relative_filename, options = {}) ⇒ Object



29
30
31
# File 'lib/rscm/scm/cvs.rb', line 29

def add(relative_filename, options={})
  cvs("add #{relative_filename}", options)
end

#apply_label(label) ⇒ Object



90
91
92
# File 'lib/rscm/scm/cvs.rb', line 90

def apply_label(label)
  cvs("tag -c #{label}")
end

#can_create_central?Boolean

Returns:

  • (Boolean)


180
181
182
183
184
185
186
# File 'lib/rscm/scm/cvs.rb', line 180

def can_create_central?
  begin
    local?
  rescue
    false
  end
end

#central_exists?Boolean

Returns:

  • (Boolean)


171
172
173
174
175
176
177
178
# File 'lib/rscm/scm/cvs.rb', line 171

def central_exists?
  if(local?)
    File.exists?("#{path}/CVSROOT/loginfo")
  else
    # don't know. assume yes.
    true
  end
end

#checked_out?Boolean

Returns:

  • (Boolean)


192
193
194
195
# File 'lib/rscm/scm/cvs.rb', line 192

def checked_out?
  rootcvs = File.expand_path("#{checkout_dir}/CVS/Root")
  File.exists?(rootcvs)
end

#commit(message, options = {}) ⇒ Object



40
41
42
# File 'lib/rscm/scm/cvs.rb', line 40

def commit(message, options={})
  cvs(commit_command(message), options)
end

#create_central(options = {}) ⇒ Object



156
157
158
159
160
161
# File 'lib/rscm/scm/cvs.rb', line 156

def create_central(options={})
  options = options.dup.merge({:dir => path})
  raise "Can't create central CVS repository for #{root}" unless can_create_central?
  File.mkpath(path)
  cvs("init", options)
end

#destroy_centralObject



163
164
165
166
167
168
169
# File 'lib/rscm/scm/cvs.rb', line 163

def destroy_central
  if(File.exist?(path) && local?)
    FileUtils.rm_rf(path)
  else
    raise "Cannot destroy central repository. '#{path}' doesn't exist or central repo isn't local to this machine"
  end
end

#diff(revision_file, options = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rscm/scm/cvs.rb', line 68

def diff(revision_file, options={})
  opts = case revision_file.status
    when /#{RevisionFile::MODIFIED}/; "#{revision_option(revision_file.previous_native_revision_identifier)} #{revision_option(revision_file.native_revision_identifier)}"
    when /#{RevisionFile::DELETED}/; "#{revision_option(revision_file.previous_native_revision_identifier)}"
    when /#{RevisionFile::ADDED}/; "#{revision_option(Time.epoch)} #{revision_option(revision_file.native_revision_identifier)}"
  end

  # IMPORTANT! CVS NT has a bug in the -N diff option
  # http://www.cvsnt.org/pipermail/cvsnt-bugs/2004-November/000786.html
  cmd = command_line("diff -Nu #{opts} #{revision_file.path}")
  execute(cmd, options.dup.merge({:exitstatus => 1})) do |io|
    yield io
  end
end

#import_central(options = {}) ⇒ Object



24
25
26
27
# File 'lib/rscm/scm/cvs.rb', line 24

def import_central(options={})
  modname = File.basename(options[:dir])
  cvs("import -m \"#{options[:message]}\" #{modname} VENDOR START", options)
end

#install_trigger(trigger_command, trigger_files_checkout_dir, options = {}) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/rscm/scm/cvs.rb', line 122

def install_trigger(trigger_command, trigger_files_checkout_dir, options={})
  raise "mod can't be null or empty" if (mod.nil? || mod == "")

  root_cvs = create_root_cvs(trigger_files_checkout_dir)
  root_cvs.checkout(nil, options)
  Dir.chdir(trigger_files_checkout_dir) do
    trigger_line = "#{mod} #{trigger_command}\n"
    File.open("loginfo", File::WRONLY | File::APPEND) do |file|
      file.puts(trigger_line)
    end
  end

  begin
    root_cvs.commit("Installed trigger for CVS module '#{mod}'", options)
  rescue Errno::EACCES
    raise ["Didn't have permission to commit CVSROOT/loginfo.",
          "Try to manually add the following line:",
          trigger_command,
          "Finally make commit the file to the repository"].join("\n")
  end
end

#move(relative_src, relative_dest, options = {}) ⇒ Object



33
34
35
36
37
38
# File 'lib/rscm/scm/cvs.rb', line 33

def move(relative_src, relative_dest, options={})
  FileUtils.mv(@checkout_dir + '/' + relative_src, @checkout_dir + '/' + relative_dest, :force=>true)
  cvs("rm #{relative_src}", options)
  # This will fail if the directories are new. More advanced support for adding can be added if needed.
  cvs("add #{relative_dest}", options)
end

#open(revision_file, options, &block) ⇒ Object



83
84
85
86
87
88
# File 'lib/rscm/scm/cvs.rb', line 83

def open(revision_file, options, &block)
  cmd = "cvs -Q update -p -r #{revision_file.native_revision_identifier} #{revision_file.path}"
  execute(cmd, options) do |io|
    block.call io
  end
end

#revisions(from_identifier, options = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/rscm/scm/cvs.rb', line 58

def revisions(from_identifier, options={})
  options = {
    :from_identifier => from_identifier,
    :to_identifier => Time.infinity, 
    :relative_path => nil
  }.merge(options)
  checkout(options[:to_identifier], options) unless checked_out? # must checkout to get revisions
  parse_log(changes_command(options), options)
end

#supports_trigger?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/rscm/scm/cvs.rb', line 188

def supports_trigger?
  true
end

#trigger_installed?(trigger_command, trigger_files_checkout_dir, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rscm/scm/cvs.rb', line 98

def trigger_installed?(trigger_command, trigger_files_checkout_dir, options={})
  loginfo_line = "#{mod} #{trigger_command}"
  regex = Regexp.new(Regexp.escape(loginfo_line))

  root_cvs = create_root_cvs(trigger_files_checkout_dir)
  begin
    root_cvs.checkout(nil, options)
    loginfo = File.join(trigger_files_checkout_dir, "loginfo")
    return false if !File.exist?(loginfo)

    # returns true if commented out. doesn't modify the file.
    in_local_copy = LineEditor.comment_out(File.new(loginfo), regex, "# ", "")
    # Also verify that loginfo has been committed back to the repo
    entries = File.join(trigger_files_checkout_dir, "CVS", "Entries")
    committed = File.mtime(entries) >= File.mtime(loginfo)

    in_local_copy && committed
  rescue Exception => e
    $stderr.puts(e.message)
    $stderr.puts(e.backtrace.join("\n"))
    false
  end
end

#trigger_mechanismObject



94
95
96
# File 'lib/rscm/scm/cvs.rb', line 94

def trigger_mechanism
  "CVSROOT/loginfo"
end

#uninstall_trigger(trigger_command, trigger_files_checkout_dir, options = {}) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/rscm/scm/cvs.rb', line 144

def uninstall_trigger(trigger_command, trigger_files_checkout_dir, options={})
  loginfo_line = "#{mod} #{trigger_command}"
  regex = Regexp.new(Regexp.escape(loginfo_line))

  root_cvs = create_root_cvs(trigger_files_checkout_dir)
  root_cvs.checkout nil, options
  loginfo_path = File.join(trigger_files_checkout_dir, "loginfo")
  File.comment_out(loginfo_path, regex, "# ")
  root_cvs.commit("Uninstalled trigger for CVS mod '#{mod}'", options)
  raise "Couldn't uninstall/commit trigger to loginfo" if trigger_installed?(trigger_command, trigger_files_checkout_dir, options)
end

#uptodate?(identifier, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rscm/scm/cvs.rb', line 44

def uptodate?(identifier, options={})
  if(!checked_out?)
    return false
  end

  checkout_silent(identifier, options.dup.merge({:simulate => true})) do |io|
    path_regex = /^[U|P|C] (.*)/
    io.each_line do |line|
      return false if(line =~ path_regex)
    end
  end
  return true
end