Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-05-18 17:22:41 +0300
committerDouwe Maan <douwe@gitlab.com>2017-05-18 17:22:41 +0300
commit6319ca271cd8de4595af136542b79367f28d211f (patch)
treec2cc11ee3a0014628b1eac9b8ad4d2dbeb7b5777 /lib/gitlab/git
parent4d2d2b11796fbf6f115b5e427794ec1c8126b2a0 (diff)
parent925945f01b1dcaf7b288afd7be53175a04eaecad (diff)
Merge branch 'gitaly-local-branches' into 'master'
Incorporate Gitaly's local_branches operation into repo code Closes #27379 See merge request !10059
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r--lib/gitlab/git/branch.rb34
-rw-r--r--lib/gitlab/git/commit.rb9
-rw-r--r--lib/gitlab/git/repository.rb37
3 files changed, 67 insertions, 13 deletions
diff --git a/lib/gitlab/git/branch.rb b/lib/gitlab/git/branch.rb
index 586380da94a..124526e4b59 100644
--- a/lib/gitlab/git/branch.rb
+++ b/lib/gitlab/git/branch.rb
@@ -1,6 +1,40 @@
module Gitlab
module Git
class Branch < Ref
+ def initialize(repository, name, target)
+ if target.is_a?(Gitaly::FindLocalBranchResponse)
+ target = target_from_gitaly_local_branches_response(target)
+ end
+
+ super(repository, name, target)
+ end
+
+ def target_from_gitaly_local_branches_response(response)
+ # Git messages have no encoding enforcements. However, in the UI we only
+ # handle UTF-8, so basically we cross our fingers that the message force
+ # encoded to UTF-8 is readable.
+ message = response.commit_subject.dup.force_encoding('UTF-8')
+
+ # NOTE: For ease of parsing in Gitaly, we have only the subject of
+ # the commit and not the full message. This is ok, since all the
+ # code that uses `local_branches` only cares at most about the
+ # commit message.
+ # TODO: Once gitaly "takes over" Rugged consider separating the
+ # subject from the message to make it clearer when there's one
+ # available but not the other.
+ hash = {
+ id: response.commit_id,
+ message: message,
+ authored_date: Time.at(response.commit_author.date.seconds),
+ author_name: response.commit_author.name,
+ author_email: response.commit_author.email,
+ committed_date: Time.at(response.commit_committer.date.seconds),
+ committer_name: response.commit_committer.name,
+ committer_email: response.commit_committer.email
+ }
+
+ Gitlab::Git::Commit.decorate(hash)
+ end
end
end
end
diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb
index f9a9b767ef4..297531db4cc 100644
--- a/lib/gitlab/git/commit.rb
+++ b/lib/gitlab/git/commit.rb
@@ -19,13 +19,7 @@ module Gitlab
def ==(other)
return false unless other.is_a?(Gitlab::Git::Commit)
- methods = [:message, :parent_ids, :authored_date, :author_name,
- :author_email, :committed_date, :committer_name,
- :committer_email]
-
- methods.all? do |method|
- send(method) == other.send(method)
- end
+ id && id == other.id
end
class << self
@@ -55,6 +49,7 @@ module Gitlab
# Commit.find(repo, 'master')
#
def find(repo, commit_id = "HEAD")
+ return commit_id if commit_id.is_a?(Gitlab::Git::Commit)
return decorate(commit_id) if commit_id.is_a?(Rugged::Commit)
obj = if commit_id.is_a?(String)
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index a2c01ec4432..b9f1ac144b6 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -80,14 +80,16 @@ module Gitlab
end
# Returns an Array of Branches
- def branches
- rugged.branches.map do |rugged_ref|
+ def branches(filter: nil, sort_by: nil)
+ branches = rugged.branches.each(filter).map do |rugged_ref|
begin
Gitlab::Git::Branch.new(self, rugged_ref.name, rugged_ref.target)
rescue Rugged::ReferenceError
# Omit invalid branch
end
- end.compact.sort_by(&:name)
+ end.compact
+
+ sort_branches(branches, sort_by)
end
def reload_rugged
@@ -108,9 +110,15 @@ module Gitlab
Gitlab::Git::Branch.new(self, rugged_ref.name, rugged_ref.target) if rugged_ref
end
- def local_branches
- rugged.branches.each(:local).map do |branch|
- Gitlab::Git::Branch.new(self, branch.name, branch.target)
+ def local_branches(sort_by: nil)
+ gitaly_migrate(:local_branches) do |is_enabled|
+ if is_enabled
+ gitaly_ref_client.local_branches(sort_by: sort_by).map do |gitaly_branch|
+ Gitlab::Git::Branch.new(self, gitaly_branch.name, gitaly_branch)
+ end
+ else
+ branches(filter: :local, sort_by: sort_by)
+ end
end
end
@@ -1202,6 +1210,23 @@ module Gitlab
diff.each_patch
end
+ def sort_branches(branches, sort_by)
+ case sort_by
+ when 'name'
+ branches.sort_by(&:name)
+ when 'updated_desc'
+ branches.sort do |a, b|
+ b.dereferenced_target.committed_date <=> a.dereferenced_target.committed_date
+ end
+ when 'updated_asc'
+ branches.sort do |a, b|
+ a.dereferenced_target.committed_date <=> b.dereferenced_target.committed_date
+ end
+ else
+ branches
+ end
+ end
+
def gitaly_ref_client
@gitaly_ref_client ||= Gitlab::GitalyClient::Ref.new(self)
end