Class: PVN::Diff::Cmd
- Inherits:
-
Object
- Object
- PVN::Diff::Cmd
- Includes:
- Logue::Loggable
- Defined in:
- lib/pvn/diff/diffcmd.rb
Instance Method Summary collapse
-
#initialize(displaypath, fromrev, torev, fromlines, tolines, whitespace) ⇒ Cmd
constructor
A new instance of Cmd.
- #open_temp_file(lines, &blk) ⇒ Object
- #to_revision_string(rev) ⇒ Object
Constructor Details
#initialize(displaypath, fromrev, torev, fromlines, tolines, whitespace) ⇒ Cmd
Returns a new instance of Cmd.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pvn/diff/diffcmd.rb', line 11 def initialize displaypath, fromrev, torev, fromlines, tolines, whitespace open_temp_file(fromlines) do |from| open_temp_file(tolines) do |to| cmd = "diff -u" if whitespace cmd << " -w" end [ fromrev, torev ].each do |rev| revstr = to_revision_string rev cmd << " -L '#{displaypath}\t(#{revstr})'" end cmd << " #{from.path}" cmd << " #{to.path}" info "cmd: #{cmd}" $io.puts "Index: #{displaypath}" $io.puts "===================================================================" IO.popen(cmd) do |io| $io.puts io.readlines end end end end |
Instance Method Details
#open_temp_file(lines, &blk) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pvn/diff/diffcmd.rb', line 37 def open_temp_file lines, &blk Tempfile.open('pvn') do |tmpfile| if lines tmpfile.puts lines end tmpfile.close blk.call tmpfile end end |
#to_revision_string(rev) ⇒ Object
48 49 50 |
# File 'lib/pvn/diff/diffcmd.rb', line 48 def to_revision_string rev rev ? "revision #{rev}" : "working copy" end |