Sha256: a31a05439ca8f1f41750bdec058048092a51d4566c9ab0f102ef88e60f5a81f4

Contents?: true

Size: 1.34 KB

Versions: 51

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/simple_cache'
require 'eac_ruby_utils/require_sub'
::EacRubyUtils.require_sub(__FILE__)

module Avm
  module Git
    class Commit
      include ::EacRubyUtils::SimpleCache

      FIELDS = {
        author_name: '%an', author_email: '%ae', author_date: '%ai',
        subject: '%s',
        author_all: '%an <%ae>, %ai',
        commiter_name: '%cn', commiter_email: '%ce', commiter_date: '%ci',
        commiter_all: '%cn <%ce>, %ci'
      }.freeze

      attr_reader :git, :sha1

      def initialize(git, sha1)
        @git = git
        @sha1 = sha1
      end

      def format(format)
        git.execute!('--no-pager', 'log', '-1', "--pretty=format:#{format}", sha1).strip
      end

      FIELDS.each do |field, format|
        define_method field do
          format(format)
        end
      end

      def files_uncached
        diff_tree_execute.each_line.map { |line| ::Avm::Git::Commit::File.new(git, line) }
      end

      def files_size_uncached
        files.inject(0) { |a, e| a + e.dst_size }
      end

      def root_child?
        format('%P').blank?
      end

      private

      def diff_tree_execute
        args = []
        args << '--root' if root_child?
        args << sha1
        git.execute!(*::Avm::Git::Commit::DiffTreeLine::GIT_COMMAND_ARGS, *args)
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
avm-tools-0.19.0 lib/avm/git/commit.rb
avm-tools-0.18.0 lib/avm/git/commit.rb
avm-tools-0.17.0 lib/avm/git/commit.rb
avm-tools-0.16.0 lib/avm/git/commit.rb
avm-tools-0.15.1 lib/avm/git/commit.rb
avm-tools-0.15.0 lib/avm/git/commit.rb
avm-tools-0.14.0 lib/avm/git/commit.rb
avm-tools-0.13.0 lib/avm/git/commit.rb
avm-tools-0.12.0 lib/avm/git/commit.rb
avm-tools-0.11.1 lib/avm/git/commit.rb
avm-tools-0.11.0 lib/avm/git/commit.rb