diff options
author | Stan Hu <stanhu@gmail.com> | 2018-08-22 21:11:55 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-08-22 21:11:55 +0300 |
commit | bd91f6447832aaf23277a86b9cbb32536ac0a0c9 (patch) | |
tree | 229373a0caeee77f7785d592457298aa2d07233e /app/services/git_push_service.rb | |
parent | 0e9dc23d4622332c3f8874ba024cac9aa28277a3 (diff) |
Fix wrong commit count in push event payload
This fixes a regression in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20916.
We now only use the full commit count for the initial push to the default branch.
Otherwise, we rely on the number of commits that we calculated occurred in the push.
The original behavior in 11.1.4:
1. When a new branch is pushed, `@push_commits_count` was set to the total
number of refs available for the branch.
2. For other branches, `@push_commits_count` would remain `nil`.
3. `GitPushService#build_push_data` would build the push data with
`@push_commits_count`.
4. If this were `nil`, it would be set to the right value here:
https://gitlab.com/gitlab-org/gitlab-ce/blob/v11.1.4/lib/gitlab/data_builder/push.rb#L60
Broken behavior:
1. `GitPushService#push_commits_count` is always called.
2. The total number of commits is therefore always equal to the total number of refs available.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/49971
Diffstat (limited to 'app/services/git_push_service.rb')
-rw-r--r-- | app/services/git_push_service.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 156b4b3c6ec..26e90e8cf8c 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -158,7 +158,7 @@ class GitPushService < BaseService end def process_default_branch - offset = [push_commits_count - PROCESS_COMMIT_LIMIT, 0].max + offset = [push_commits_count_for_ref - PROCESS_COMMIT_LIMIT, 0].max @push_commits = project.repository.commits(params[:newrev], offset: offset, limit: PROCESS_COMMIT_LIMIT) project.after_create_default_branch @@ -172,7 +172,7 @@ class GitPushService < BaseService params[:newrev], params[:ref], @push_commits, - commits_count: push_commits_count) + commits_count: commits_count) end def push_to_existing_branch? @@ -213,8 +213,14 @@ class GitPushService < BaseService end end - def push_commits_count - strong_memoize(:push_commits_count) do + def commits_count + return push_commits_count_for_ref if default_branch? && push_to_new_branch? + + Array(@push_commits).size + end + + def push_commits_count_for_ref + strong_memoize(:push_commits_count_for_ref) do project.repository.commit_count_for_ref(params[:ref]) end end |