Commit b1c81f84 authored by Timothy Andrew's avatar Timothy Andrew
Browse files

Have `Project#open_branches` return branches that are matched by a wildcard protected branch.

1. The `open_branches` method is used to provide a list of branches
   while creating a protected branch.

2. It makes sense to include branches which are matched by one or more
   wildcard protected branches, since the user might want to make exact
   protected branches from these as well.

3. This also provides a large performance improvement. On my machine, in
   a project with 5000 branches and 2000 protected branches, the
   `ProtectedBranches#index` page went from a 40 seconds load time to 4
   seconds (10x speedup).
parent 035281ab2de1
......@@ -802,8 +802,12 @@ def repo_exists?
@repo_exists = false
# Branches that are not _exactly_ matched by a protected branch.
def open_branches
repository.branches.reject { |branch| self.protected_branch?( }
exact_protected_branch_names = protected_branches.reject(&:wildcard?).map(&:name)
branch_names =
non_open_branch_names =
repository.branches.reject { |branch| non_open_branch_names.include? }
def root_ref?(branch)
......@@ -34,7 +34,7 @@ def matches?(branch_name)
# Checks if this protected branch contains a wildcard
def wildcard?'*') &&'*')
......@@ -438,12 +438,12 @@
it { expect( include('feature') }
it { expect( include('master') }
it "does not include branches matching a protected branch wildcard" do
it "includes branches matching a protected branch wildcard" do
expect( include('feature')
create(:protected_branch, name: 'feat*', project: project)
expect(Project.find( include('feature')
expect(Project.find( include('feature')
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