Skip to content
This repository was archived by the owner on May 12, 2018. It is now read-only.

Commit 71ceb0f

Browse files
committed
Merge pull request #48 from mr-vinn/faster-branches-contains
Improve Repository#branches_contains performance
2 parents edc95bc + abe0f31 commit 71ceb0f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/gitlab_git/repository.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,15 @@ def branch_names_contains(commit)
361361
# repo.branch_names_contains('master')
362362
#
363363
def branches_contains(commit)
364-
sha = rugged.rev_parse_oid(commit)
364+
commit_obj = rugged.rev_parse(commit)
365+
parent = commit_obj.parents.first unless commit_obj.parents.empty?
365366

366367
walker = Rugged::Walker.new(rugged)
367368

368369
rugged.branches.select do |branch|
369370
walker.push(branch.target_id)
370-
result = walker.any? { |c| c.oid == sha }
371+
walker.hide(parent) if parent
372+
result = walker.any? { |c| c.oid == commit_obj.oid }
371373
walker.reset
372374

373375
result

0 commit comments

Comments
 (0)