Sha256: ef68306adc54a4aff5859c77ed69b4480949d8bb6b91572f9e35890f915185ec

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 KB

Contents

module GitObjectBrowser

  module Models

    class IndexTreeExtension < Bindata

      attr_reader :signature, :total_length, :entries

      def initialize(input)
        super(input)
      end

      def parse
        @signature = raw(4) # TREE
        @total_length = int
        @entries = []

        length = 0
        while (length < @total_length)
          entry = {}
          entry[:path_component] = find_char "\0"
          entry[:entry_count]    = find_char " "
          entry[:subtree_count]  = find_char "\n"

          length += entry[:path_component].bytesize + 1
          length += entry[:entry_count].bytesize + 1
          length += entry[:subtree_count].bytesize + 1

          entry[:entry_count]    = entry[:entry_count].to_i
          entry[:subtree_count]  = entry[:subtree_count].to_i

          if 0 <= entry[:entry_count]
            entry[:sha1] = hex(20)
            length += 20
          end
          @entries << entry
        end

        self
      end

      def to_hash
        return {
          :signature     => @signature,
          :total_length  => @total_length,
          :entries       => @entries
        }
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
git-object-browser-0.1.3 lib/git-object-browser/models/index_tree_extension.rb
git-object-browser-0.1.2 lib/git-object-browser/models/index_tree_extension.rb
git-object-browser-0.1.1 lib/git-object-browser/models/index_tree_extension.rb
git-object-browser-0.1.0 lib/git-object-browser/models/index_tree_extension.rb
git-object-browser-0.0.9 lib/git-object-browser/models/index_tree_extension.rb
git-object-browser-0.0.8 lib/git-object-browser/models/index_tree_extension.rb
git-object-browser-0.0.7 lib/git-object-browser/models/index_tree_extension.rb
git-object-browser-0.0.6 lib/git-object-browser/models/index_tree_extension.rb
git-object-browser-0.0.4 lib/git-object-browser/models/index_tree_extension.rb
git-object-browser-0.0.3 lib/git-object-browser/models/index_tree_extension.rb