unpack_object

in lib/grit/git-ruby/internal/pack.rb [262:291]


        def unpack_object(packfile, offset, options = {})
          obj_offset = offset
          packfile.seek(offset)

          c = packfile.read(1).getord(0)
          size = c & 0xf
          type = (c >> 4) & 7
          shift = 4
          offset += 1
          while c & 0x80 != 0
            c = packfile.read(1).getord(0)
            size |= ((c & 0x7f) << shift)
            shift += 7
            offset += 1
          end

          return [false, false] if !(type == OBJ_COMMIT || type == OBJ_TREE) && options[:caching]

          case type
          when OBJ_OFS_DELTA, OBJ_REF_DELTA
            data, type = unpack_deltified(packfile, type, offset, obj_offset, size, options)
            
          when OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, OBJ_TAG
            data = unpack_compressed(offset, size)
          else
            raise PackFormatError, "invalid type #{type}"
          end
          [data, type]
        end