Skip to content

Commit

Permalink
Replace regex methods by string ones since faster
Browse files Browse the repository at this point in the history
and more readable.
  • Loading branch information
cirosantilli committed Nov 2, 2014
1 parent 1b14038 commit 640edf3
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 25 deletions.
8 changes: 4 additions & 4 deletions app/models/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ def title

return no_commit_message if title.blank?

title_end = title.index(/\n/)
title_end = title.index("\n")
if (!title_end && title.length > 100) || (title_end && title_end > 100)
title[0..79] << "&hellip;".html_safe
else
title.split(/\n/, 2).first
title.split("\n", 2).first
end
end

# Returns the commits description
#
# cut off, ellipses (`&hellp;`) are prepended to the commit message.
def description
title_end = safe_message.index(/\n/)
title_end = safe_message.index("\n")
@description ||= if (!title_end && safe_message.length > 100) || (title_end && title_end > 100)
"&hellip;".html_safe << safe_message[80..-1]
else
safe_message.split(/\n/, 2)[1].try(:chomp)
safe_message.split("\n", 2)[1].try(:chomp)
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ def branch?
end

def new_branch?
commit_from =~ /^00000/
commit_from.start_with?('00000')
end

def new_ref?
commit_from =~ /^00000/
commit_from.start_with?('00000')
end

def rm_ref?
commit_to =~ /^00000/
commit_to.start_with?('00000')
end

def md_ref?
Expand Down
2 changes: 1 addition & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def execute_services(data)
end

def update_merge_requests(oldrev, newrev, ref, user)
return true unless ref =~ /heads/
return true unless ref.include?('heads')
branch_name = ref.gsub("refs/heads/", "")
commits = self.repository.commits_between(oldrev, newrev)
c_ids = commits.map(&:id)
Expand Down
4 changes: 2 additions & 2 deletions app/models/project_services/campfire_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def build_message(push)
message << "[#{project.name_with_namespace}] "
message << "#{push[:user_name]} "

if before =~ /000000/
if before.include?('000000')
message << "pushed new branch #{ref} \n"
elsif after =~ /000000/
elsif after.include?('000000')
message << "removed branch #{ref} \n"
else
message << "pushed #{push[:total_commits_count]} commits to #{ref}. "
Expand Down
4 changes: 2 additions & 2 deletions app/models/project_services/hipchat_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def create_message(push)

message = ""
message << "#{push[:user_name]} "
if before =~ /000000/
if before.include?('000000')
message << "pushed new branch <a href=\""\
"#{project.web_url}/commits/#{URI.escape(ref)}\">#{ref}</a>"\
" to <a href=\"#{project.web_url}\">"\
"#{project.name_with_namespace.gsub!(/\s/, "")}</a>\n"
elsif after =~ /000000/
elsif after.include?('000000')
message << "removed branch #{ref} from <a href=\"#{project.web_url}\">#{project.name_with_namespace.gsub!(/\s/,'')}</a> \n"
else
message << "pushed to branch <a href=\""\
Expand Down
4 changes: 2 additions & 2 deletions app/models/project_services/pushover_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def execute(push_data)
before = push_data[:before]
after = push_data[:after]

if before =~ /000000/
if before.include?('000000')
message = "#{push_data[:user_name]} pushed new branch \"#{ref}\"."
elsif after =~ /000000/
elsif after.include?('000000')
message = "#{push_data[:user_name]} deleted branch \"#{ref}\"."
else
message = "#{push_data[:user_name]} push to branch \"#{ref}\"."
Expand Down
4 changes: 2 additions & 2 deletions app/models/project_services/slack_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def compose_commit_message(commit)
end

def new_branch?
before =~ /000000/
before.include?('000000')
end

def removed_branch?
after =~ /000000/
after.include?('000000')
end

def branch_url
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def all_ssh_keys
end

def temp_oauth_email?
email =~ /\Atemp-email-for-oauth/
email.start_with?('temp-email-for-oauth')
end

def public_profile?
Expand Down
11 changes: 7 additions & 4 deletions app/services/git_push_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,26 @@ def push_to_existing_branch?(ref, oldrev)
ref_parts = ref.split('/')

# Return if this is not a push to a branch (e.g. new commits)
ref_parts[1] =~ /heads/ && oldrev != "0000000000000000000000000000000000000000"
ref_parts[1].include('heads') &&
oldrev != '0000000000000000000000000000000000000000'
end

def push_to_new_branch?(ref, oldrev)
ref_parts = ref.split('/')

ref_parts[1] =~ /heads/ && oldrev == "0000000000000000000000000000000000000000"
ref_parts[1].include('heads') &&
oldrev == '0000000000000000000000000000000000000000'
end

def push_remove_branch?(ref, newrev)
ref_parts = ref.split('/')

ref_parts[1] =~ /heads/ && newrev == "0000000000000000000000000000000000000000"
ref_parts[1].include('heads') &&
newrev == '0000000000000000000000000000000000000000'
end

def push_to_branch?(ref)
ref =~ /refs\/heads/
ref.include?('refs/heads')
end

def is_default_branch?(ref)
Expand Down
2 changes: 1 addition & 1 deletion app/services/notification_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def new_note(note)
return true unless note.noteable_type.present?

# ignore gitlab service messages
return true if note.note =~ /\A_Status changed to closed_/
return true if note.note.start_with?('_Status changed to closed_')
return true if note.cross_reference? && note.system == true

opts = { noteable_type: note.noteable_type, project_id: note.project_id }
Expand Down
4 changes: 2 additions & 2 deletions lib/api/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Internal < Grape::API
# project. This applies the correct project permissions to
# the wiki repository as well.
access =
if project_path =~ /\.wiki\Z/
project_path.sub!(/\.wiki\Z/, '')
if project_path.end_with?('.wiki')
project_path.chomp!('.wiki')
Gitlab::GitAccessWiki.new
else
Gitlab::GitAccess.new
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/gitlab/import.rake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace :gitlab do

puts "Processing #{repo_path}".yellow

if path =~ /\.wiki\Z/
if path.end_with?('.wiki')
puts " * Skipping wiki repo"
next
end
Expand Down

0 comments on commit 640edf3

Please sign in to comment.