Ensure internal Gitlab::Git references use the namespace

This commit is contained in:
Robert Speicher 2017-01-04 14:54:47 -05:00
parent a00578ce5c
commit 2e20a71d21
7 changed files with 27 additions and 27 deletions

View File

@ -30,7 +30,7 @@ module Gitlab
blob = repository.lookup(blob_entry[:oid]) blob = repository.lookup(blob_entry[:oid])
if blob if blob
Blob.new( new(
id: blob.oid, id: blob.oid,
name: blob_entry[:name], name: blob_entry[:name],
size: blob.size, size: blob.size,
@ -47,7 +47,7 @@ module Gitlab
def raw(repository, sha) def raw(repository, sha)
blob = repository.lookup(sha) blob = repository.lookup(sha)
Blob.new( new(
id: blob.oid, id: blob.oid,
size: blob.size, size: blob.size,
data: blob.content(MAX_DATA_DISPLAY_SIZE), data: blob.content(MAX_DATA_DISPLAY_SIZE),
@ -88,7 +88,7 @@ module Gitlab
end end
def submodule_blob(blob_entry, path, sha) def submodule_blob(blob_entry, path, sha)
Blob.new( new(
id: blob_entry[:oid], id: blob_entry[:oid],
name: blob_entry[:name], name: blob_entry[:name],
data: '', data: '',
@ -140,16 +140,16 @@ module Gitlab
ref = 'refs/heads/' + ref ref = 'refs/heads/' + ref
end end
path_name = PathHelper.normalize_path(file[:path]) path_name = Gitlab::Git::PathHelper.normalize_path(file[:path])
# Abort if any invalid characters remain (e.g. ../foo) # Abort if any invalid characters remain (e.g. ../foo)
raise Repository::InvalidBlobName.new("Invalid path") if path_name.each_filename.to_a.include?('..') raise Gitlab::Git::Repository::InvalidBlobName.new("Invalid path") if path_name.each_filename.to_a.include?('..')
filename = path_name.to_s filename = path_name.to_s
index = repo.index index = repo.index
unless repo.empty? unless repo.empty?
rugged_ref = repo.references[ref] rugged_ref = repo.references[ref]
raise Repository::InvalidRef.new("Invalid branch name") unless rugged_ref raise Gitlab::Git::Repository::InvalidRef.new("Invalid branch name") unless rugged_ref
last_commit = rugged_ref.target last_commit = rugged_ref.target
index.read_tree(last_commit.tree) index.read_tree(last_commit.tree)
parents = [last_commit] parents = [last_commit]
@ -161,14 +161,14 @@ module Gitlab
file_entry = index.get(filename) file_entry = index.get(filename)
if action == :rename if action == :rename
old_path_name = PathHelper.normalize_path(file[:previous_path]) old_path_name = Gitlab::Git::PathHelper.normalize_path(file[:previous_path])
old_filename = old_path_name.to_s old_filename = old_path_name.to_s
file_entry = index.get(old_filename) file_entry = index.get(old_filename)
index.remove(old_filename) unless file_entry.blank? index.remove(old_filename) unless file_entry.blank?
end end
if file_entry if file_entry
raise Repository::InvalidBlobName.new("Filename already exists; update not allowed") unless update raise Gitlab::Git::Repository::InvalidBlobName.new("Filename already exists; update not allowed") unless update
# Preserve the current file mode if one is available # Preserve the current file mode if one is available
mode = file_entry[:mode] if file_entry[:mode] mode = file_entry[:mode] if file_entry[:mode]

View File

@ -58,7 +58,7 @@ module Gitlab
obj = if commit_id.is_a?(String) obj = if commit_id.is_a?(String)
repo.rev_parse_target(commit_id) repo.rev_parse_target(commit_id)
else else
Ref.dereference_object(commit_id) Gitlab::Git::Ref.dereference_object(commit_id)
end end
return nil unless obj.is_a?(Rugged::Commit) return nil unless obj.is_a?(Rugged::Commit)
@ -123,7 +123,7 @@ module Gitlab
def diff_from_parent(rugged_commit, options = {}) def diff_from_parent(rugged_commit, options = {})
options ||= {} options ||= {}
break_rewrites = options[:break_rewrites] break_rewrites = options[:break_rewrites]
actual_options = Diff.filter_diff_options(options) actual_options = Gitlab::Git::Diff.filter_diff_options(options)
diff = if rugged_commit.parents.empty? diff = if rugged_commit.parents.empty?
rugged_commit.diff(actual_options.merge(reverse: true)) rugged_commit.diff(actual_options.merge(reverse: true))
@ -211,7 +211,7 @@ module Gitlab
end end
def diffs(options = {}) def diffs(options = {})
DiffCollection.new(diff_from_parent(options), options) Gitlab::Git::DiffCollection.new(diff_from_parent(options), options)
end end
def parents def parents

View File

@ -33,7 +33,7 @@ module Gitlab
def initialize(repository, name, target) def initialize(repository, name, target)
encode! name encode! name
@name = name.gsub(/\Arefs\/(tags|heads)\//, '') @name = name.gsub(/\Arefs\/(tags|heads)\//, '')
@dereferenced_target = Commit.find(repository, target) @dereferenced_target = Gitlab::Git::Commit.find(repository, target)
@target = if target.respond_to?(:oid) @target = if target.respond_to?(:oid)
target.oid target.oid
elsif target.respond_to?(:name) elsif target.respond_to?(:name)

View File

@ -32,7 +32,7 @@ module Gitlab
def initialize(path) def initialize(path)
@path = path @path = path
@name = path.split("/").last @name = path.split("/").last
@attributes = Attributes.new(path) @attributes = Gitlab::Git::Attributes.new(path)
end end
# Default branch in the repository # Default branch in the repository
@ -61,7 +61,7 @@ module Gitlab
def branches def branches
rugged.branches.map do |rugged_ref| rugged.branches.map do |rugged_ref|
begin begin
Branch.new(self, rugged_ref.name, rugged_ref.target) Gitlab::Git::Branch.new(self, rugged_ref.name, rugged_ref.target)
rescue Rugged::ReferenceError rescue Rugged::ReferenceError
# Omit invalid branch # Omit invalid branch
end end
@ -83,12 +83,12 @@ module Gitlab
reload_rugged if force_reload reload_rugged if force_reload
rugged_ref = rugged.branches[name] rugged_ref = rugged.branches[name]
Branch.new(self, rugged_ref.name, rugged_ref.target) if rugged_ref Gitlab::Git::Branch.new(self, rugged_ref.name, rugged_ref.target) if rugged_ref
end end
def local_branches def local_branches
rugged.branches.each(:local).map do |branch| rugged.branches.each(:local).map do |branch|
Branch.new(self, branch.name, branch.target) Gitlab::Git::Branch.new(self, branch.name, branch.target)
end end
end end
@ -123,7 +123,7 @@ module Gitlab
end end
end end
Tag.new(self, ref.name, ref.target, message) Gitlab::Git::Tag.new(self, ref.name, ref.target, message)
end.sort_by(&:name) end.sort_by(&:name)
end end
@ -260,7 +260,7 @@ module Gitlab
# Discard submodules # Discard submodules
next if submodule?(entry) next if submodule?(entry)
blob = Blob.raw(self, entry[:oid]) blob = Gitlab::Git::Blob.raw(self, entry[:oid])
# Skip binary files # Skip binary files
next if blob.data.encoding == Encoding::ASCII_8BIT next if blob.data.encoding == Encoding::ASCII_8BIT
@ -397,7 +397,7 @@ module Gitlab
# diff options. The +options+ hash can also include :break_rewrites to # diff options. The +options+ hash can also include :break_rewrites to
# split larger rewrites into delete/add pairs. # split larger rewrites into delete/add pairs.
def diff(from, to, options = {}, *paths) def diff(from, to, options = {}, *paths)
DiffCollection.new(diff_patches(from, to, options, *paths), options) Gitlab::Git::DiffCollection.new(diff_patches(from, to, options, *paths), options)
end end
# Returns commits collection # Returns commits collection
@ -755,7 +755,7 @@ module Gitlab
# create_branch("other-feature", "master") # create_branch("other-feature", "master")
def create_branch(ref, start_point = "HEAD") def create_branch(ref, start_point = "HEAD")
rugged_ref = rugged.branches.create(ref, start_point) rugged_ref = rugged.branches.create(ref, start_point)
Branch.new(self, rugged_ref.name, rugged_ref.target) Gitlab::Git::Branch.new(self, rugged_ref.name, rugged_ref.target)
rescue Rugged::ReferenceError => e rescue Rugged::ReferenceError => e
raise InvalidRef.new("Branch #{ref} already exists") if e.to_s =~ /'refs\/heads\/#{ref}'/ raise InvalidRef.new("Branch #{ref} already exists") if e.to_s =~ /'refs\/heads\/#{ref}'/
raise InvalidRef.new("Invalid reference #{start_point}") raise InvalidRef.new("Invalid reference #{start_point}")
@ -870,7 +870,7 @@ module Gitlab
# Check if this directory exists; if it does, then don't bother # Check if this directory exists; if it does, then don't bother
# adding .gitkeep file. # adding .gitkeep file.
ref = options[:commit][:branch] ref = options[:commit][:branch]
path = PathHelper.normalize_path(path).to_s path = Gitlab::Git::PathHelper.normalize_path(path).to_s
rugged_ref = rugged.ref(ref) rugged_ref = rugged.ref(ref)
raise InvalidRef.new("Invalid ref") if rugged_ref.nil? raise InvalidRef.new("Invalid ref") if rugged_ref.nil?
@ -895,7 +895,7 @@ module Gitlab
update: true update: true
} }
Blob.commit(self, options) Gitlab::Git::Blob.commit(self, options)
end end
# Returns result like "git ls-files" , recursive and full file path # Returns result like "git ls-files" , recursive and full file path
@ -1242,7 +1242,7 @@ module Gitlab
def diff_patches(from, to, options = {}, *paths) def diff_patches(from, to, options = {}, *paths)
options ||= {} options ||= {}
break_rewrites = options[:break_rewrites] break_rewrites = options[:break_rewrites]
actual_options = Diff.filter_diff_options(options.merge(paths: paths)) actual_options = Gitlab::Git::Diff.filter_diff_options(options.merge(paths: paths))
diff = rugged.diff(from, to, actual_options) diff = rugged.diff(from, to, actual_options)
diff.find_similar!(break_rewrites: break_rewrites) diff.find_similar!(break_rewrites: break_rewrites)

View File

@ -17,7 +17,7 @@ module Gitlab
root_tree = commit.tree root_tree = commit.tree
tree = if path tree = if path
id = Tree.find_id_by_path(repository, root_tree.oid, path) id = find_id_by_path(repository, root_tree.oid, path)
if id if id
repository.lookup(id) repository.lookup(id)
else else
@ -28,7 +28,7 @@ module Gitlab
end end
tree.map do |entry| tree.map do |entry|
Tree.new( new(
id: entry[:oid], id: entry[:oid],
root_id: root_tree.oid, root_id: root_tree.oid,
name: entry[:name], name: entry[:name],

View File

@ -1,7 +1,7 @@
require "spec_helper" require "spec_helper"
describe Gitlab::Git::EncodingHelper do describe Gitlab::Git::EncodingHelper do
let(:ext_class) { Class.new { extend EncodingHelper } } let(:ext_class) { Class.new { extend Gitlab::Git::EncodingHelper } }
let(:binary_string) { File.join(SEED_REPOSITORY_PATH, 'gitlab_logo.png') } let(:binary_string) { File.join(SEED_REPOSITORY_PATH, 'gitlab_logo.png') }
describe '#encode!' do describe '#encode!' do

View File

@ -1,7 +1,7 @@
require "spec_helper" require "spec_helper"
describe Gitlab::Git::Repository, seed_helper: true do describe Gitlab::Git::Repository, seed_helper: true do
include EncodingHelper include Gitlab::Git::EncodingHelper
let(:repository) { Gitlab::Git::Repository.new(TEST_REPO_PATH) } let(:repository) { Gitlab::Git::Repository.new(TEST_REPO_PATH) }