Class: PVN::Diff::LocalDiffer

Inherits:
Differ
  • Object
show all
Defined in:
lib/pvn/diff/local_differ.rb

Instance Attribute Summary

Attributes inherited from Differ

#revision, #whitespace

Instance Method Summary collapse

Methods inherited from Differ

#run_diff, #run_diff_command, #to_revision_string, #write_to_temp

Constructor Details

#initialize(options) ⇒ LocalDiffer

Returns a new instance of LocalDiffer.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pvn/diff/local_differ.rb', line 10

def initialize options
  super
  
  paths = options.paths
  paths = %w{ . } if paths.empty?

  allentries = Array.new

  # we sort only the sub-entries, so the order in which paths were specified
  # is preserved

  @whitespace = options.whitespace

  paths.each do |path|
    elmt = PVN::IO::Element.new :local => path
    entries = elmt.find_files_by_status
    
    allentries.concat entries.sort_by { |n| n.path }
  end

  allentries.each do |entry|
    show_entry entry
  end
end

Instance Method Details

#against_head?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/pvn/diff/local_differ.rb', line 52

def against_head?
  @options.change.value.nil? && @options.revision.head?
end

#cat(elmt) ⇒ Object



65
66
67
68
# File 'lib/pvn/diff/local_differ.rb', line 65

def cat elmt
  elmt = PVN::IO::Element.new :local => elmt.local
  elmt.cat nil, :use_cache => false
end

#create_element(entry) ⇒ Object



61
62
63
# File 'lib/pvn/diff/local_differ.rb', line 61

def create_element entry
  PVN::IO::Element.new :local => entry.path
end

#get_latest_revision(elmt) ⇒ Object



77
78
79
80
# File 'lib/pvn/diff/local_differ.rb', line 77

def get_latest_revision elmt
  svninfo = elmt.get_info
  svninfo.revision
end

#read_working_copy(entry) ⇒ Object



56
57
58
59
# File 'lib/pvn/diff/local_differ.rb', line 56

def read_working_copy entry
  pn = Pathname.new entry.path
  pn.readlines
end

#show_as_added(entry) ⇒ Object



70
71
72
73
74
75
# File 'lib/pvn/diff/local_differ.rb', line 70

def show_as_added entry
  fromlines = nil
  tolines = read_working_copy entry

  run_diff entry.path, fromlines, 0, tolines, 0
end

#show_as_deleted(entry) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/pvn/diff/local_differ.rb', line 82

def show_as_deleted entry
  elmt = create_element entry

  fromrev = get_latest_revision elmt
  lines = cat elmt

  run_diff entry.path, lines, fromrev, nil, nil
end

#show_as_modified(entry) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/pvn/diff/local_differ.rb', line 91

def show_as_modified entry
  elmt = create_element entry
  remotelines = cat elmt
  fromrev = get_latest_revision elmt
  wclines = read_working_copy entry
  run_diff entry.path, remotelines, fromrev, wclines, nil
end

#show_entry(entry) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pvn/diff/local_differ.rb', line 35

def show_entry entry
  info "entry: #{entry.inspect}"
  case entry.status
  when 'modified'
    show_as_modified entry
  when 'deleted'
    show_as_deleted entry
  when 'added'
    show_as_added entry
  end
end

#use_cache?Boolean

$$$ todo: integrate these, from old diff/diffcmd

Returns:

  • (Boolean)


48
49
50
# File 'lib/pvn/diff/local_differ.rb', line 48

def use_cache?
  super && !against_head?
end