Sha256: 02fb69a05cd520a9976db6afd47a5f3b119cd219680a096a0a983f0f2ef3de06

Contents?: true

Size: 1.03 KB

Versions: 8

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'active_support/core_ext/module/delegation'
require 'eac_ruby_utils/simple_cache'
require 'avm/git/commit/diff_tree_line'

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

        attr_reader :git, :diff_tree

        # git: [Avm::Launcher::Git::Base]
        # diff_tree_tree: a line of command "git diff-tree --no-commit-id -r --full-index"'s output
        def initialize(git, diff_tree_line)
          @git = git
          @diff_tree = ::Avm::Git::Commit::DiffTreeLine.new(diff_tree_line)
        end

        delegate(*::Avm::Git::Commit::DiffTreeLine::FIELDS, to: :diff_tree)

        def to_s
          "#{path}|#{status}"
        end

        def src_size_uncached
          size(src_sha1)
        end

        def dst_size_uncached
          size(dst_sha1)
        end

        private

        def size(sha1)
          return 0 if /\A0+\z/.match(sha1)

          git.execute!('cat-file', '-s', sha1).strip.to_i
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
avm-tools-0.103.1 lib/avm/git/commit/file.rb
avm-tools-0.103.0 lib/avm/git/commit/file.rb
avm-tools-0.102.2 lib/avm/git/commit/file.rb
avm-tools-0.102.1 lib/avm/git/commit/file.rb
avm-tools-0.102.0 lib/avm/git/commit/file.rb
avm-tools-0.101.0 lib/avm/git/commit/file.rb
avm-tools-0.100.0 lib/avm/git/commit/file.rb
avm-tools-0.99.1 lib/avm/git/commit/file.rb