Commit ebdcb67c authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fj-regressing-blob-text-in-repo-method' into 'master'

Fix regression in ElasticSearch with blob `text?` method

See merge request gitlab-org/gitlab-ee!9418
parents 4a81064e b5046855
---
title: Replacing old blob methods in ElasticSerach module
merge_request: 9418
author:
type: fixed
...@@ -13,7 +13,7 @@ module Elasticsearch ...@@ -13,7 +13,7 @@ module Elasticsearch
@id = raw_blob_hash[:oid] @id = raw_blob_hash[:oid]
@blob = repo.lookup(@id) @blob = repo.lookup(@id)
@mode = raw_blob_hash[:mode].to_s(8) @mode = (raw_blob_hash[:mode] || raw_blob_hash[:filemode]).to_s(8)
@size = @blob.size @size = @blob.size
@path = encode!(raw_blob_hash[:path]) @path = encode!(raw_blob_hash[:path])
@name = @path.split('/').last @name = @path.split('/').last
......
...@@ -74,7 +74,7 @@ module Elasticsearch ...@@ -74,7 +74,7 @@ module Elasticsearch
end end
def delete_blob(blob) def delete_blob(blob)
return unless blob.text? return unless blob.text_in_repo?
{ {
delete: { delete: {
...@@ -246,7 +246,6 @@ module Elasticsearch ...@@ -246,7 +246,6 @@ module Elasticsearch
result = [] result = []
target_sha = repository_for_indexing.head.target.oid target_sha = repository_for_indexing.head.target.oid
if repository_for_indexing.bare? if repository_for_indexing.bare?
tree = repository_for_indexing.lookup(target_sha).tree tree = repository_for_indexing.lookup(target_sha).tree
result.push(recurse_blobs_index_hash(tree)) result.push(recurse_blobs_index_hash(tree))
...@@ -254,7 +253,7 @@ module Elasticsearch ...@@ -254,7 +253,7 @@ module Elasticsearch
repository_for_indexing.index.each do |blob| repository_for_indexing.index.each do |blob|
b = LiteBlob.new(repository_for_indexing, blob) b = LiteBlob.new(repository_for_indexing, blob)
if b.text? if b.text_in_repo?
result.push( result.push(
{ {
id: "#{target_sha}_#{b.path}", id: "#{target_sha}_#{b.path}",
...@@ -277,7 +276,7 @@ module Elasticsearch ...@@ -277,7 +276,7 @@ module Elasticsearch
blob[:path] = path + blob[:name] blob[:path] = path + blob[:name]
b = LiteBlob.new(repository_for_indexing, blob) b = LiteBlob.new(repository_for_indexing, blob)
if b.text? if b.text_in_repo?
result.push( result.push(
{ {
id: "#{repository_for_indexing.head.target.oid}_#{path}#{blob[:name]}", id: "#{repository_for_indexing.head.target.oid}_#{path}#{blob[:name]}",
......
...@@ -32,6 +32,21 @@ describe Repository, :elastic do ...@@ -32,6 +32,21 @@ describe Repository, :elastic do
expect(project.repository.search('def | popen extension:md')[:blobs][:total_count]).to eq(1) expect(project.repository.search('def | popen extension:md')[:blobs][:total_count]).to eq(1)
end end
it 'can delete blobs' do
project = create :project, :repository
blob = project.repository.blob_at('b83d6e391c22777fca1ed3012fce84f633d7fed0', 'files/ruby/popen.rb')
expect(project.repository.delete_blob(blob)[:delete]).not_to be_empty
end
it 'can return the index as a json' do
project = create :project, :repository
index = project.repository.as_indexed_json
expect(index[:blobs]).not_to be_empty
expect(index[:commits]).not_to be_empty
end
def search_and_check!(on, query, type:, per: 1000) def search_and_check!(on, query, type:, per: 1000)
results = on.search(query, type: type, per: per)["#{type}s".to_sym][:results] results = on.search(query, type: type, per: per)["#{type}s".to_sym][:results]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment