Sha256: ab7436fb3072234ea9c68ac77f4ab4e1cc8d4100746ff5942ca750f5348295fa

Contents?: true

Size: 899 Bytes

Versions: 23

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

module Avm
  module Git
    class Commit
      class DiffTreeLine
        DIFF_TREE_PATTERN = /\A:(\d{6}) (\d{6}) (\S+) (\S+) (\S+)\t(\S.*)\z/.freeze
        FIELDS = %w[src_mode dst_mode src_sha1 dst_sha1 status path].freeze
        GIT_COMMAND_ARGS = %w[-c core.quotepath=off diff-tree --no-commit-id -r --full-index].freeze

        attr_reader(*FIELDS)

        # line: a line of command "git [GIT_COMMAND_ARGS]"'s output.
        # Reference: https://git-scm.com/docs/git-diff-tree
        def initialize(line)
          m = DIFF_TREE_PATTERN.match(line.strip)
          raise "\"#{line}\" did not match pattern" unless m

          FIELDS.count.times { |i| send("#{FIELDS[i]}=", m[i + 1]) }
        end

        def fields
          FIELDS.index_with { |field| send(field) }
        end

        private

        attr_writer(*FIELDS)
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
avm-git-0.18.0 lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.94.0 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
avm-git-0.17.0 lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.86.5 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
avm-git-0.16.0 lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.86.4 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.86.3 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
avm-git-0.15.0 lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.86.2 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.84.0 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.83.0 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.82.0 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
avm-git-0.14.0 lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.81.0 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.80.0 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.79.0 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.78.0 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.77.1 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.77.0 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb
eac_tools-0.76.1 sub/avm-git/lib/avm/git/commit/diff_tree_line.rb