Sha256: 4ebc019f225fa29ceea0c0435434458edcf6d27551478dbfa0add6b53e7455d8

Contents?: true

Size: 1.29 KB

Versions: 26

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacGit
  class Local
    class Commit
      require_sub __FILE__, include_modules: true
      enable_simple_cache

      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

      common_constructor :repo, :hash

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

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

      def changed_files_uncached
        diff_tree_execute.each_line.map do |line|
          ::EacGit::Local::Commit::ChangedFile.new(self, line)
        end
      end

      def changed_files_size_uncached
        changed_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 << hash
        repo.command(*::EacGit::Local::Commit::DiffTreeLine::GIT_COMMAND_ARGS, *args).execute!
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
avm-tools-0.106.0 vendor/eac_git/lib/eac_git/local/commit.rb
avm-tools-0.105.0 vendor/eac_git/lib/eac_git/local/commit.rb
eac_git-0.7.3 lib/eac_git/local/commit.rb
eac_git-0.7.2 lib/eac_git/local/commit.rb
eac_git-0.7.1 lib/eac_git/local/commit.rb
eac_git-0.7.0 lib/eac_git/local/commit.rb
avm-tools-0.104.0 vendor/eac_git/lib/eac_git/local/commit.rb
avm-tools-0.103.1 vendor/eac_git/lib/eac_git/local/commit.rb
avm-tools-0.103.0 vendor/eac_git/lib/eac_git/local/commit.rb
avm-tools-0.102.2 vendor/eac_git/lib/eac_git/local/commit.rb
eac_git-0.6.0 lib/eac_git/local/commit.rb
avm-tools-0.102.1 vendor/eac_git/lib/eac_git/local/commit.rb
avm-tools-0.102.0 vendor/eac_git/lib/eac_git/local/commit.rb
eac_git-0.5.0 lib/eac_git/local/commit.rb
avm-tools-0.101.0 vendor/eac_git/lib/eac_git/local/commit.rb
avm-tools-0.100.0 vendor/eac_git/lib/eac_git/local/commit.rb
avm-tools-0.99.1 vendor/eac_git/lib/eac_git/local/commit.rb
avm-tools-0.99.0 vendor/eac_git/lib/eac_git/local/commit.rb
avm-tools-0.98.0 vendor/eac_git/lib/eac_git/local/commit.rb
avm-tools-0.97.0 vendor/eac_git/lib/eac_git/local/commit.rb