Class: PVN::Diff::Differ

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/pvn/diff/differ.rb

Direct Known Subclasses

LocalDiffer, RepositoryDiffer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Differ

Returns a new instance of Differ.



18
19
# File 'lib/pvn/diff/differ.rb', line 18

def initialize options
end

Instance Attribute Details

#revisionObject (readonly)

Returns the value of attribute revision.



16
17
18
# File 'lib/pvn/diff/differ.rb', line 16

def revision
  @revision
end

#whitespaceObject (readonly)

Returns the value of attribute whitespace.



15
16
17
# File 'lib/pvn/diff/differ.rb', line 15

def whitespace
  @whitespace
end

Instance Method Details

#run_diff(displaypath, fromlines, fromrev, tolines, torev) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/pvn/diff/differ.rb', line 65

def run_diff displaypath, fromlines, fromrev, tolines, torev
  Tempfile.open('pvn') do |from|
    if fromlines
      from.puts fromlines
    end
    from.close

    Tempfile.open('pvn') do |to|
      if tolines
        to.puts tolines
      end
      to.close
      
      run_diff_command displaypath, fromrev, torev, from.path, to.path
    end
  end
end

#run_diff_command(displaypath, fromrev, torev, frompath, topath) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pvn/diff/differ.rb', line 43

def run_diff_command displaypath, fromrev, torev, frompath, topath
  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 << " #{frompath}"
  cmd << " #{topath}"

  info "cmd: #{cmd}"

  $io.puts "Index: #{displaypath}"
  $io.puts "==================================================================="
  IO.popen(cmd) do |io|
    $io.puts io.readlines
  end
end

#to_revision_string(rev) ⇒ Object



21
22
23
# File 'lib/pvn/diff/differ.rb', line 21

def to_revision_string rev
  rev ? "revision #{rev}" : "working copy"
end

#write_to_temp(entry, lines) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pvn/diff/differ.rb', line 25

def write_to_temp entry, lines
  Tempfile.open('pvn') do |to|
    topath = to.path
    to.puts lines
    to.close
    cmd = "diff -u"
    label = " -L '#{entry.path} (revision 0)'"
    2.times do
      cmd << label
    end
    cmd << " #{frpath}"
    cmd << " #{entry.path}"
    IO.popen(cmd) do |io|
      puts io.readlines
    end
  end
end