Class: Mercurial::Diff

Inherits:
Object
  • Object
show all
Defined in:
lib/mercurial-ruby/diff.rb

Overview

The class represents Mercurial diff. Obtained by running an hg diff command.

The class represents Diff object itself, DiffFactory is responsible for assembling instances of Diff. For the list of all possible diff-related operations check DiffFactory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Diff

Returns a new instance of Diff.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mercurial-ruby/diff.rb', line 27

def initialize(opts={})
  @hash_a = opts[:hash_a]
  @hash_b = opts[:hash_b]
  @file_a = opts[:file_a]
  @file_b = opts[:file_b]
  @body   = opts[:body]
  @binary = opts[:binary]

  if RUBY_VERSION >= '1.9.1'
    @file_a.force_encoding('utf-8') if @file_a
    @file_b.force_encoding('utf-8') if @file_b
  end
end

Instance Attribute Details

#bodyObject (readonly)

Diff body.



25
26
27
# File 'lib/mercurial-ruby/diff.rb', line 25

def body
  @body
end

#file_aObject (readonly)

Version a of the file name.



19
20
21
# File 'lib/mercurial-ruby/diff.rb', line 19

def file_a
  @file_a
end

#file_bObject (readonly)

Version b of the file name.



22
23
24
# File 'lib/mercurial-ruby/diff.rb', line 22

def file_b
  @file_b
end

#hash_aObject (readonly)

SHA1 hash of version a of the file.



13
14
15
# File 'lib/mercurial-ruby/diff.rb', line 13

def hash_a
  @hash_a
end

#hash_bObject (readonly)

SHA1 hash of version b of the file.



16
17
18
# File 'lib/mercurial-ruby/diff.rb', line 16

def hash_b
  @hash_b
end

Instance Method Details

#binary?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/mercurial-ruby/diff.rb', line 45

def binary?
  !! @binary
end

#file_nameObject



41
42
43
# File 'lib/mercurial-ruby/diff.rb', line 41

def file_name
  file_b || file_a
end