Class: Svn::Diff

Inherits:
FFI::AutoPointer
  • Object
show all
Defined in:
lib/svn/diffs.rb

Defined Under Namespace

Modules: C Classes: FileOptionsStruct

Constant Summary collapse

FileOptions =

create a mapped type for use elsewhere

FileOptionsStruct.by_ref

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modifiedObject

Returns the value of attribute modified.



65
66
67
# File 'lib/svn/diffs.rb', line 65

def modified
  @modified
end

#modified_pathObject

Returns the value of attribute modified_path.



66
67
68
# File 'lib/svn/diffs.rb', line 66

def modified_path
  @modified_path
end

#optionsObject

Returns the value of attribute options.



67
68
69
# File 'lib/svn/diffs.rb', line 67

def options
  @options
end

#originalObject

Returns the value of attribute original.



63
64
65
# File 'lib/svn/diffs.rb', line 63

def original
  @original
end

#original_pathObject

Returns the value of attribute original_path.



64
65
66
# File 'lib/svn/diffs.rb', line 64

def original_path
  @original_path
end

#poolObject

Returns the value of attribute pool.



68
69
70
# File 'lib/svn/diffs.rb', line 68

def pool
  @pool
end

#typeObject

Returns the value of attribute type.



62
63
64
# File 'lib/svn/diffs.rb', line 62

def type
  @type
end

Class Method Details

.file_diff(original_path, modified_path, options = {}, pool = RootPool) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/svn/diffs.rb', line 34

def file_diff( original_path, modified_path, options={}, pool=RootPool )
  options = FileOptions.from_hash( options ) if options.is_a? Hash

  out = FFI::MemoryPointer.new( Diff )

  Error.check_and_raise(
      C.file_diff( out, original_path, modified_path, options, pool )
    )

  d = new( out.read_pointer )

  return nil if d.null?

  d.type = :file
  d.original_path = original_path
  d.modified_path = modified_path
  d.options = options
  d.pool = pool

  return d
end

.release(ptr) ⇒ Object



56
57
58
59
# File 'lib/svn/diffs.rb', line 56

def release( ptr )
  # diff objects will probably need to keep track of the pool in which
  # they are allocated so they can be freed in that pool
end

.string_diff(original, modified, options = {}, pool = RootPool) ⇒ Object



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

def string_diff( original, modified, options={}, pool=RootPool )
  options = FileOptions.from_hash( options ) if options.is_a? Hash
  original = CountedString.from_string( original )
  modified = CountedString.from_string( modified )

  out = FFI::MemoryPointer.new( Diff )

  Error.check_and_raise(
      C.string_diff( out, original, modified, options, pool )
    )

  d = new( out.read_pointer )

  return nil if d.null?

  d.type = :string
  d.original = original
  d.modified = modified
  d.options = options
  d.pool = pool

  return d
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/svn/diffs.rb', line 70

def changed?
  ( C.is_changed( self ) == 1 )
end

#conflicts?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/svn/diffs.rb', line 74

def conflicts?
  ( C.has_conflicts( self ) == 1 )
end

#unified(*args) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/svn/diffs.rb', line 78

def unified( *args )
  # keep these in scope
  out_stream = nil
  options = nil
  pool = nil

  case args.size
  when 0
    # use all defaults
  when 1
    if args.first.is_a? Hash
      options = args.first
    elsif args.first.is_a? IO or args.first.is_a? StringIO
      out_stream = args.first
    elsif args.first.is_a? Pool
      pool = args.first
    end
  when 2, 3
    out_stream, options, pool = args
  else
    raise ArgumentError, "wrong number of arguments (#{args.size} for 3)"
  end

  # defaults
  out_stream ||= StringIO.new
  options ||= {}
  pool ||= RootPool

  # get common options
  encoding = options[:encoding] || 'utf-8'
  original_header = options[:original_header]
  modified_header = options[:modified_header]

  case type
  when :string
    with_diff_header = ( options[:with_diff_header] ? 1 : 0 )

    Error.check_and_raise( C.string_output_unified(
        Svn::Stream.wrap_io( out_stream ), self,
        original_header, modified_header, encoding,
        original, modified, pool
      ) )

  when :file
    path_strip = options[:path_strip]
    show_c_function = ( options[:show_c_function] ? 1 : 0 )

    Error.check_and_raise( C.file_output_unified(
        Svn::Stream.wrap_io( out_stream ), self,
        original_path, modified_path,
        original_header, modified_header, encoding, path_strip,
        show_c_function, pool
      ) )
  end

  out_stream.rewind if out_stream.is_a? StringIO

  out_stream
end