Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored diff commands to use cvs_diff, which uses versioned_file. …

…At the end of each diff output using the progress dialog I got a 'nil', which I found out was because of a line in progress.rb. I changed it to output the result only if there is one. If this breaks anyone else's code then we can find some other solution.

git-svn-id: http://svn.textmate.org/trunk/Bundles/CVS.tmbundle@2737 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information...
commit ad6caf4a1b5e2225fbf986341f587f4d13ac0dc7 1 parent 17aa8f0
Brian Donovan authored
View
11 Commands/Diff With Newest (HEAD).plist
@@ -7,8 +7,15 @@
<key>command</key>
<string>require_cmd "${TM_CVS:=cvs}" "If you have installed cvs, then you need to either update your &lt;tt&gt;PATH&lt;/tt&gt; or set the &lt;tt&gt;TM_CVS&lt;/tt&gt; shell variable (e.g. in Preferences / Advanced)"
-cd "$TM_DIRECTORY" &amp;&amp;
-cvs diff -r HEAD "$TM_FILENAME"</string>
+"${TM_RUBY:-ruby}" &lt;&lt;'END'
+
+ENV['CVS_PATH'] = ENV['TM_CVS']
+$LOAD_PATH &lt;&lt; ENV['TM_BUNDLE_SUPPORT']
+require 'cvs_diff'
+
+CVS::diff_active_file(:head, "Diff With Newest")
+END
+</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
View
11 Commands/Diff With Previous Revision (PREV).plist
@@ -7,8 +7,15 @@
<key>command</key>
<string>require_cmd "${TM_CVS:=cvs}" "If you have installed cvs, then you need to either update your &lt;tt&gt;PATH&lt;/tt&gt; or set the &lt;tt&gt;TM_CVS&lt;/tt&gt; shell variable (e.g. in Preferences / Advanced)"
-cd "$TM_DIRECTORY" &amp;&amp;
-cvs diff -r PREV "$TM_FILENAME"</string>
+"${TM_RUBY:-ruby}" &lt;&lt;'END'
+
+ENV['CVS_PATH'] = ENV['TM_CVS']
+$LOAD_PATH &lt;&lt; ENV['TM_BUNDLE_SUPPORT']
+require 'cvs_diff'
+
+CVS::diff_active_file(:prev, "Diff With Previous Revision")
+END
+</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
View
11 Commands/Diff With Revision....plist
@@ -35,8 +35,15 @@ if [[ $revs = "false" ]]; then
osascript -e 'tell app "TextMate" to activate' &amp;&gt;/dev/null &amp; exit_discard
fi
-cd $TM_DIRECTORY &amp;&amp;
-"$TM_CVS" diff -r $revs $TM_FILENAME</string>
+export REVS="$revs"
+"${TM_RUBY:-ruby}" &lt;&lt;'END'
+
+ENV['CVS_PATH'] = ENV['TM_CVS']
+$LOAD_PATH &lt;&lt; ENV['TM_BUNDLE_SUPPORT']
+require 'cvs_diff'
+
+CVS::diff_active_file(ENV['REVS'], "Diff With Revision...")
+END</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
View
11 Commands/Diff With Working Copy (BASE).plist
@@ -7,8 +7,15 @@
<key>command</key>
<string>require_cmd "${TM_CVS:=cvs}" "If you have installed cvs, then you need to either update your &lt;tt&gt;PATH&lt;/tt&gt; or set the &lt;tt&gt;TM_CVS&lt;/tt&gt; shell variable (e.g. in Preferences / Advanced)"
-cd "$TM_DIRECTORY" &amp;&amp;
-cvs diff -r BASE "$TM_FILENAME"</string>
+"${TM_RUBY:-ruby}" &lt;&lt;'END'
+
+ENV['CVS_PATH'] = ENV['TM_CVS']
+$LOAD_PATH &lt;&lt; ENV['TM_BUNDLE_SUPPORT']
+require 'cvs_diff'
+
+CVS::diff_active_file(:base, "Diff With Working Copy")
+END
+</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
View
30 Support/cvs_diff.rb
@@ -0,0 +1,30 @@
+#!/usr/bin/env ruby -w
+
+$LOAD_PATH << ENV['TM_SUPPORT_PATH'] + "/lib"
+require 'progress'
+require 'versioned_file'
+
+module CVS
+ def CVS.diff_active_file(revision, command)
+ target_path = ENV['TM_FILEPATH']
+ output_path = File.basename(target_path) + ".diff"
+
+ TextMate::call_with_progress(:title => command,
+ :message => "Accessing CVS Repository…",
+ :output_filepath => output_path) do
+ have_data = false
+
+ # idea here is to stream the data rather than submit it in one big block
+ VersionedFile.diff(target_path, revision).each_line do |line|
+ have_data = true unless line.empty?
+ puts line
+ end
+
+ if not have_data then
+ # switch to tooltip output to report lack of differences
+ puts "No differences found."
+ exit 206;
+ end
+ end
+ end
+end
View
70 Support/versioned_file.rb
@@ -0,0 +1,70 @@
+module CVS
+ CVS_PATH = ENV['CVS_PATH'] || 'cvs' unless defined?(CVS_PATH)
+
+ class VersionedFile
+ attr_accessor :path
+
+ def initialize(path)
+ @path = path
+ end
+
+ def dirname
+ File.dirname @path
+ end
+
+ def basename
+ File.basename @path
+ 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
+ end
+
+ def revision
+ $1 if cvs(:status) =~ /Working revision:\s*([\d\.]+)/
+ end
+
+ def revisions(reload = false)
+ @revisions = nil if reload
+ @revisions ||= cvs(:log).inject([]) { |list,line| list << $1 if line =~ /^revision ([\d\.]+)/i; list}
+ end
+
+ def diff(revision, other_revision = nil)
+ revision, other_revision = expand_revision(revision), expand_revision(other_revision)
+
+ if other_revision
+ cvs(:diff, "-r #{other_revision} -r #{revision}")
+ else
+ cvs(:diff, "-r #{revision}")
+ end
+ end
+
+ def version(revision)
+ cvs(:update, "-p -r #{expand_revision(revision)}")
+ end
+
+ def cvs(command, options='')
+ %x{cd "#{dirname}"; "#{CVS_PATH}" #{command} #{options} "#{basename}"}
+ end
+
+ %w(status revisions diff revision version cvs).each do |method|
+ class_eval "def self.#{method}(path, *args); new(path).#{method}(*args); end"
+ end
+
+ private
+
+ def expand_revision(revision)
+ case revision
+ when :head then 'HEAD'
+ when :base then 'BASE'
+ when :prev then revisions[revisions.index(self.revision)+1] rescue nil
+ else revision
+ end
+ end
+ end
+end

0 comments on commit ad6caf4

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