commit_stats.rb 824 Bytes
Newer Older
Robert Speicher's avatar
Robert Speicher committed
1 2 3 4 5
# Gitlab::Git::CommitStats counts the additions, deletions, and total changes
# in a commit.
module Gitlab
  module Git
    class CommitStats
6 7
      include Gitlab::Git::WrapsGitalyErrors

Robert Speicher's avatar
Robert Speicher committed
8 9 10
      attr_reader :id, :additions, :deletions, :total

      # Instantiate a CommitStats object
11 12
      #
      # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/323
13
      def initialize(repo, commit)
Robert Speicher's avatar
Robert Speicher committed
14 15 16 17 18
        @id = commit.id
        @additions = 0
        @deletions = 0
        @total = 0

19
        wrapped_gitaly_errors do
Jacob Vosmaer's avatar
Jacob Vosmaer committed
20
          gitaly_stats(repo, commit)
21 22 23 24 25 26 27 28 29
        end
      end

      def gitaly_stats(repo, commit)
        stats = repo.gitaly_commit_client.commit_stats(@id)
        @additions = stats.additions
        @deletions = stats.deletions
        @total = @additions + @deletions
      end
Robert Speicher's avatar
Robert Speicher committed
30 31 32
    end
  end
end