lib/rscm/base.rb in rscm-0.4.3 vs lib/rscm/base.rb in rscm-0.4.4
- old
+ new
@@ -26,11 +26,14 @@
# If +from_identifier+ or +to_identifier+ are +nil+ they should respectively default to
# Time.epoch or Time.infinite.
#
class Base
- attr_accessor :default_options
+ attr_writer :default_options
+ def default_options
+ @default_options ||= {:stdout=>'stdout.log', :stderr=>'stderr.log'}
+ end
# Transforms +raw_identifier+ into the native rype used for revisions.
def to_identifier(raw_identifier)
raw_identifier.to_s
end
@@ -52,16 +55,16 @@
props.delete("@default_options")
props.sort!
end
# Destroys the working copy
- def destroy_working_copy(options={})
+ def destroy_working_copy
FileUtils.rm_rf(checkout_dir) unless checkout_dir.nil?
end
# Whether or not the SCM represented by this instance exists.
- def central_exists?(options={})
+ def central_exists?
# The default implementation assumes yes - override if it can be
# determined programmatically.
true
end
@@ -137,34 +140,32 @@
# This method should be overridden for SCMs that are able to yield checkouts as they happen.
# For some SCMs this is not possible, or at least very hard. In that case, just override
# the checkout_silent method instead of this method (should be protected).
#
def checkout(to_identifier=Time.infinity, options={}) # :yield: file
- to_identifier=Time.infinity if to_identifier.nil?
+ to_identifier = Time.infinity if to_identifier.nil?
- # the OS doesn't store file timestamps with fractions.
- before_checkout_time = Time.now.utc - 1
-
+ before = checked_out_files
# We expect subclasses to implement this as a protected method (unless this whole method is overridden).
checkout_silent(to_identifier, options)
+ after = checked_out_files
+
+ (after - before).sort!
+ end
+
+ def checked_out_files
files = Dir["#{@checkout_dir}/**/*"]
- added = []
- files.each do |file|
- added << file if File.mtime(file).utc > before_checkout_time
- end
+ files.delete_if{|file| File.directory?(file)}
ignore_paths.each do |regex|
- added.delete_if{|path| path =~ regex}
+ files.delete_if{|file| file =~ regex}
end
- added_file_paths = added.find_all do |path|
- File.file?(path)
- end
- relative_added_file_paths = to_relative(checkout_dir, added_file_paths)
- relative_added_file_paths
+ dir = File.expand_path(@checkout_dir)
+ files.collect{|file| File.expand_path(file)[dir.length+1..-1]}
end
- # Returns a Revisions object for the period specified by +from_identifier+ (exclusive, i.e. after)
- # and +to_identifier+ (inclusive). If +relative_path+ is specified, the result will only contain
+ # Returns a Revisions object for the interval specified by +from_identifier+ (exclusive, i.e. after)
+ # and optionally +:to_identifier+ (inclusive). If +relative_path+ is specified, the result will only contain
# revisions pertaining to that path.
#
def revisions(from_identifier, options={})
raise NotImplementedError
end
@@ -272,17 +273,9 @@
CommandLine.execute(cmd, options, &proc)
rescue CommandLine::OptionError => e
e.message += "\nEither specify default_options on the scm object, or pass the required options to the method"
raise e
end
- end
-
- # Takes an array of +absolute_paths+ and turns it into an array
- # of paths relative to +dir+
- #
- def to_relative(dir, absolute_paths)
- dir = File.expand_path(dir)
- absolute_paths.collect{|p| File.expand_path(p)[dir.length+1..-1]}
end
end
end