Commit 9b216686 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'gitaly-renames-annotations' into 'master'

Gitaly deletions and annotations

See merge request !13280
parents 3a087a00 5d775ea3
...@@ -941,7 +941,7 @@ class Project < ActiveRecord::Base ...@@ -941,7 +941,7 @@ class Project < ActiveRecord::Base
end end
def repo def repo
repository.raw repository.rugged
end end
def url_to_repo def url_to_repo
......
...@@ -102,7 +102,7 @@ module Gitlab ...@@ -102,7 +102,7 @@ module Gitlab
if is_enabled if is_enabled
repo.gitaly_commit_client.between(base, head) repo.gitaly_commit_client.between(base, head)
else else
repo.commits_between(base, head).map { |c| decorate(c) } repo.rugged_commits_between(base, head).map { |c| decorate(c) }
end end
end end
rescue Rugged::ReferenceError rescue Rugged::ReferenceError
......
...@@ -58,11 +58,6 @@ module Gitlab ...@@ -58,11 +58,6 @@ module Gitlab
end end
end end
# Alias to old method for compatibility
def raw
rugged
end
def rugged def rugged
@rugged ||= Rugged::Repository.new(path, alternates: alternate_object_directories) @rugged ||= Rugged::Repository.new(path, alternates: alternate_object_directories)
rescue Rugged::RepositoryError, Rugged::OSError rescue Rugged::RepositoryError, Rugged::OSError
...@@ -296,6 +291,7 @@ module Gitlab ...@@ -296,6 +291,7 @@ module Gitlab
# after: Time.new(2016, 4, 21, 14, 32, 10) # after: Time.new(2016, 4, 21, 14, 32, 10)
# ) # )
# #
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/446
def log(options) def log(options)
raw_log(options).map { |c| Commit.decorate(c) } raw_log(options).map { |c| Commit.decorate(c) }
end end
...@@ -324,7 +320,9 @@ module Gitlab ...@@ -324,7 +320,9 @@ module Gitlab
# Return a collection of Rugged::Commits between the two revspec arguments. # Return a collection of Rugged::Commits between the two revspec arguments.
# See http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for # See http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for
# a detailed list of valid arguments. # a detailed list of valid arguments.
def commits_between(from, to) #
# Gitaly note: JV: to be deprecated in favor of Commit.between
def rugged_commits_between(from, to)
walker = Rugged::Walker.new(rugged) walker = Rugged::Walker.new(rugged)
walker.sorting(Rugged::SORT_NONE | Rugged::SORT_REVERSE) walker.sorting(Rugged::SORT_NONE | Rugged::SORT_REVERSE)
...@@ -857,46 +855,6 @@ module Gitlab ...@@ -857,46 +855,6 @@ module Gitlab
submodule_data.select { |path, data| data['id'] } submodule_data.select { |path, data| data['id'] }
end end
# Returns true if +commit+ introduced changes to +path+, using commit
# trees to make that determination. Uses the history simplification
# rules that `git log` uses by default, where a commit is omitted if it
# is TREESAME to any parent.
#
# If the +follow+ option is true and the file specified by +path+ was
# renamed, then the path value is set to the old path.
def commit_touches_path?(commit, path, follow, walker)
entry = tree_entry(commit, path)
if commit.parents.empty?
# This is the root commit, return true if it has +path+ in its tree
return !entry.nil?
end
num_treesame = 0
commit.parents.each do |parent|
parent_entry = tree_entry(parent, path)
# Only follow the first TREESAME parent for merge commits
if num_treesame > 0
walker.hide(parent)
next
end
if entry.nil? && parent_entry.nil?
num_treesame += 1
elsif entry && parent_entry && entry[:oid] == parent_entry[:oid]
num_treesame += 1
end
end
case num_treesame
when 0
detect_rename(commit, commit.parents.first, path) if follow
true
else false
end
end
# Find the entry for +path+ in the tree for +commit+ # Find the entry for +path+ in the tree for +commit+
def tree_entry(commit, path) def tree_entry(commit, path)
pathname = Pathname.new(path) pathname = Pathname.new(path)
...@@ -924,43 +882,6 @@ module Gitlab ...@@ -924,43 +882,6 @@ module Gitlab
tmp_entry tmp_entry
end end
# Compare +commit+ and +parent+ for +path+. If +path+ is a file and was
# renamed in +commit+, then set +path+ to the old filename.
def detect_rename(commit, parent, path)
diff = parent.diff(commit, paths: [path], disable_pathspec_match: true)
# If +path+ is a filename, not a directory, then we should only have
# one delta. We don't need to follow renames for directories.
return nil if diff.each_delta.count > 1
delta = diff.each_delta.first
if delta.added?
full_diff = parent.diff(commit)
full_diff.find_similar!
full_diff.each_delta do |full_delta|
if full_delta.renamed? && path == full_delta.new_file[:path]
# Look for the old path in ancestors
path.replace(full_delta.old_file[:path])
end
end
end
end
# Returns true if the index entry has the special file mode that denotes
# a submodule.
def submodule?(index_entry)
index_entry[:mode] == 57344
end
# Return a Rugged::Index that has read from the tree at +ref_name+
def populated_index(ref_name)
commit = rev_parse_target(ref_name)
index = rugged.index
index.read_tree(commit.tree)
index
end
# Return the Rugged patches for the diff between +from+ and +to+. # Return the Rugged patches for the diff between +from+ and +to+.
def diff_patches(from, to, options = {}, *paths) def diff_patches(from, to, options = {}, *paths)
options ||= {} options ||= {}
......
...@@ -114,7 +114,7 @@ describe Gitlab::Git::Commit, seed_helper: true do ...@@ -114,7 +114,7 @@ describe Gitlab::Git::Commit, seed_helper: true do
describe '.find' do describe '.find' do
it "should return first head commit if without params" do it "should return first head commit if without params" do
expect(Gitlab::Git::Commit.last(repository).id).to eq( expect(Gitlab::Git::Commit.last(repository).id).to eq(
repository.raw.head.target.oid repository.rugged.head.target.oid
) )
end end
......
...@@ -22,7 +22,6 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -22,7 +22,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
describe "Respond to" do describe "Respond to" do
subject { repository } subject { repository }
it { is_expected.to respond_to(:raw) }
it { is_expected.to respond_to(:rugged) } it { is_expected.to respond_to(:rugged) }
it { is_expected.to respond_to(:root_ref) } it { is_expected.to respond_to(:root_ref) }
it { is_expected.to respond_to(:tags) } it { is_expected.to respond_to(:tags) }
...@@ -757,13 +756,13 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -757,13 +756,13 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
end end
describe "#commits_between" do describe "#rugged_commits_between" do
context 'two SHAs' do context 'two SHAs' do
let(:first_sha) { 'b0e52af38d7ea43cf41d8a6f2471351ac036d6c9' } let(:first_sha) { 'b0e52af38d7ea43cf41d8a6f2471351ac036d6c9' }
let(:second_sha) { '0e50ec4d3c7ce42ab74dda1d422cb2cbffe1e326' } let(:second_sha) { '0e50ec4d3c7ce42ab74dda1d422cb2cbffe1e326' }
it 'returns the number of commits between' do it 'returns the number of commits between' do
expect(repository.commits_between(first_sha, second_sha).count).to eq(3) expect(repository.rugged_commits_between(first_sha, second_sha).count).to eq(3)
end end
end end
...@@ -772,11 +771,11 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -772,11 +771,11 @@ describe Gitlab::Git::Repository, seed_helper: true do
let(:branch) { 'master' } let(:branch) { 'master' }
it 'returns the number of commits between a sha and a branch' do it 'returns the number of commits between a sha and a branch' do
expect(repository.commits_between(sha, branch).count).to eq(5) expect(repository.rugged_commits_between(sha, branch).count).to eq(5)
end end
it 'returns the number of commits between a branch and a sha' do it 'returns the number of commits between a branch and a sha' do
expect(repository.commits_between(branch, sha).count).to eq(0) # sha is before branch expect(repository.rugged_commits_between(branch, sha).count).to eq(0) # sha is before branch
end end
end end
...@@ -785,7 +784,7 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -785,7 +784,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
let(:second_branch) { 'master' } let(:second_branch) { 'master' }
it 'returns the number of commits between' do it 'returns the number of commits between' do
expect(repository.commits_between(first_branch, second_branch).count).to eq(17) expect(repository.rugged_commits_between(first_branch, second_branch).count).to eq(17)
end end
end end
end end
......
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