Class: Rugged::Diff::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/rugged/diff/line.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



42
43
44
45
46
47
# File 'lib/pronto/rugged/diff/line.rb', line 42

def ==(other)
  content == other.content &&
    line_origin == other.line_origin &&
    old_lineno == other.old_lineno &&
    new_lineno == other.new_lineno
end

#commitObject



15
16
17
18
19
# File 'lib/pronto/rugged/diff/line.rb', line 15

def commit
  @commit ||= begin
    repo.lookup(commit_sha) if commit_sha
  end
end

#commit_lineObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pronto/rugged/diff/line.rb', line 27

def commit_line
  @commit_line ||= begin
    diff = commit.show
    patches = diff ? diff.patches : []
    commit_patch = patches.find do |p|
      patch.new_file_full_path == p.new_file_full_path
    end

    lines = commit_patch ? commit_patch.lines : []
    result = lines.find { |l| blameline.lineno == l.new_lineno }

    result || self # no commit_line means that it was just added
  end
end

#commit_shaObject



21
22
23
24
25
# File 'lib/pronto/rugged/diff/line.rb', line 21

def commit_sha
  @commit_sha ||= begin
    blameline.commit.id if blameline
  end
end

#patchObject



4
5
6
# File 'lib/pronto/rugged/diff/line.rb', line 4

def patch
  hunk.owner
end

#positionObject



8
9
10
11
12
13
# File 'lib/pronto/rugged/diff/line.rb', line 8

def position
  hunk_index = patch.hunks.find_index { |h| h.header == hunk.header }
  line_index = patch.lines.find_index(self)

  line_index + hunk_index + 1
end