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 included from RevisionPoller

RevisionPoller::BASE_INCREMENT, RevisionPoller::CRITICAL_REVISION_SIZE, RevisionPoller::TWENTY_FOUR_HOURS

Instance Attribute Summary collapse

Attributes inherited from Base

#default_options, #store_revisions_command

Attributes included from RevisionPoller

#logger

Instance Method Summary collapse

Methods inherited from Base

#==, #available?, #checked_out_files, #checkout, #checkout_commandline, #checkout_dir, #checkout_dir=, #destroy_working_copy, #edit, #store_revisions_command?, #to_identifier, #to_yaml_properties, #transactional?, #update_commandline

Methods included from RevisionPoller

#poll

Constructor Details

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

Returns a new instance of Cvs.



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

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



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

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

#apply_label(label) ⇒ Object



98
99
100
# File 'lib/rscm/scm/cvs.rb', line 98

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

#can_create_central?Boolean

Returns:

  • (Boolean)


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

def can_create_central?
  begin
    local?
  rescue
    false
  end
end

#central_exists?Boolean

Returns:

  • (Boolean)


182
183
184
185
186
187
188
189
# File 'lib/rscm/scm/cvs.rb', line 182

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

#checked_out?Boolean

Returns:

  • (Boolean)


203
204
205
206
# File 'lib/rscm/scm/cvs.rb', line 203

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

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



51
52
53
# File 'lib/rscm/scm/cvs.rb', line 51

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

#create_central(options = {}) ⇒ Object



167
168
169
170
171
172
# File 'lib/rscm/scm/cvs.rb', line 167

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



174
175
176
177
178
179
180
# File 'lib/rscm/scm/cvs.rb', line 174

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(path, from, to, options = {}, &block) ⇒ Object



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

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

#import_central(dir, options = {}) ⇒ Object



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

def import_central(dir, options={})
  modname = File.basename(dir)
  FileUtils.mkdir_p(@checkout_dir) unless File.exist?(@checkout_dir)
  options = options.dup.merge :dir => dir
  cvs("import -m \"#{options[:message]}\" #{modname} VENDOR START", options)
end

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



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/rscm/scm/cvs.rb', line 131

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

  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

#installed?Boolean

Returns:

  • (Boolean)


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

def installed?
  begin
    cvs("--version", {}) 
    true
  rescue
    false
  end
end

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



44
45
46
47
48
49
# File 'lib/rscm/scm/cvs.rb', line 44

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(path, native_revision_identifier, options = {}, &block) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/rscm/scm/cvs.rb', line 90

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

#revisions(from_identifier = Time.new.utc, options = {}) ⇒ Object



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

def revisions(from_identifier=Time.new.utc, options={})
  raise "from_identifer cannot be nil" if from_identifier.nil?
  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)


199
200
201
# File 'lib/rscm/scm/cvs.rb', line 199

def supports_trigger?
  true
end

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

Returns:

  • (Boolean)


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rscm/scm/cvs.rb', line 106

def trigger_installed?(trigger_command, trigger_files_checkout_dir, options={})
  trigger_command = fix_trigger_command(trigger_command)
  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



102
103
104
# File 'lib/rscm/scm/cvs.rb', line 102

def trigger_mechanism
  "CVSROOT/loginfo"
end

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



154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/rscm/scm/cvs.rb', line 154

def uninstall_trigger(trigger_command, trigger_files_checkout_dir, options={})
  trigger_command = fix_trigger_command(trigger_command)
  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)


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

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