Skip to content
Browse files

Added a WorkingCopy class to allow for more than just individual file…

…s, and updated VersionedFile to work with it.

git-svn-id: http://svn.textmate.org/trunk/Bundles/CVS.tmbundle@2742 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information...
1 parent ad6caf4 commit 31c9e71abeebb545e0c4b6e32a49c029e07ab19e Brian Donovan committed Feb 22, 2006
Showing with 48 additions and 8 deletions.
  1. +30 −8 Support/versioned_file.rb
  2. +18 −0 Support/working_copy.rb
View
38 Support/versioned_file.rb
@@ -17,12 +17,7 @@ def basename
end
def status
- case cvs :status
- when /Status: Up-to-date/i then :current
- when /Status: Locally Modified/i then :modified
- when /Status: Locally Added/i then :added
- when /Status: Needs Merge/i then :stale
- end
+ status_from_line cvs(:update, :pretend => true, :quiet => true)
end
def revision
@@ -48,8 +43,23 @@ def version(revision)
cvs(:update, "-p -r #{expand_revision(revision)}")
end
- def cvs(command, options='')
- %x{cd "#{dirname}"; "#{CVS_PATH}" #{command} #{options} "#{basename}"}
+ def commit(options={})
+ options = options.dup
+ options[:command_options] = "-m '#{options.delete(:message).gsub(/'/, "\\'")}'" if options.key?(:message)
+ cvs(:commit, options)
+ end
+
+ def cvs(command, options={})
+ options = {:command_options => options} if options.is_a? String
+ cvs_options = [options[:cvs_options]].flatten.compact
+ cvs_options << '-n' if options[:pretend]
+ cvs_options << '-q' if options[:quiet]
+ cvs_options << '-Q' if options[:silent]
+ cvs_options = cvs_options.join(' ')
+
+ files = options[:files] || [basename]
+ files = files.map { |file| %("#{file.gsub(/"/, '\\"')}") }.join(' ')
+ %x{cd "#{dirname}"; "#{CVS_PATH}" #{cvs_options} #{command} #{options[:command_options]} #{files} 2> /dev/null}
end
%w(status revisions diff revision version cvs).each do |method|
@@ -66,5 +76,17 @@ def expand_revision(revision)
else revision
end
end
+
+ def status_from_line(line)
+ case line
+ when /^(U|P) /i then :stale
+ when /^A /i then :added
+ when /^M /i then :modified
+ when /^C /i then :conflicted
+ when /^\? /i then :unknown
+ when /^R /i then :removed
+ else :current
+ end
+ end
end
end
View
18 Support/working_copy.rb
@@ -0,0 +1,18 @@
+module CVS
+ class WorkingCopy < VersionedFile
+ def initialize(path)
+ @path = (path =~ %r{/$}) ? path : "#{path}/" # add / if not there
+ end
+
+ def basename
+ '.'
+ end
+
+ def status
+ cvs(:update, :pretend => true, :quiet => true).inject([]) do |files,line|
+ files << {$1 => status_for_line line} if line =~ /^\S (.*)$/
+ files
+ end
+ end
+ end
+end

0 comments on commit 31c9e71

Please sign in to comment.
Something went wrong with that request. Please try again.