Skip to content

Commit

Permalink
Added a WorkingCopy class to allow for more than just individual file…
Browse files Browse the repository at this point in the history
…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
Brian Donovan committed Feb 22, 2006
1 parent ad6caf4 commit 31c9e71
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
38 changes: 30 additions & 8 deletions Support/versioned_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand All @@ -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
18 changes: 18 additions & 0 deletions Support/working_copy.rb
Original file line number Diff line number Diff line change
@@ -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.