Class: Gitlab::Git::Blame

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_git/blame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, sha, path) ⇒ Blame

Returns a new instance of Blame.



6
7
8
9
10
11
# File 'lib/gitlab_git/blame.rb', line 6

def initialize(repository, sha, path)
  @repo = repository.rugged
  @blame = Rugged::Blame.new(@repo, path, { newest_commit: sha })
  @blob = Blob.find(repository, sha, path)
  @lines = @blob.data.split("\n")
end

Instance Attribute Details

#blobObject

Returns the value of attribute blob.



4
5
6
# File 'lib/gitlab_git/blame.rb', line 4

def blob
  @blob
end

Instance Method Details

#eachObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/gitlab_git/blame.rb', line 13

def each
  @blame.each do |blame|
    from = blame[:final_start_line_number] - 1
    commit = @repo.lookup(blame[:final_commit_id])

    yield(Gitlab::Git::Commit.new(commit),
        @lines[from, blame[:lines_in_hunk]] || [],
        blame[:final_start_line_number])
  end
end