Skip to content

Generalize CrossRepoComparer and rename it to CrossRepo

Igor Drozdov requested to merge id-generalize-cross-repo-service into master

What does this MR do and why?

This MR converts Gitlab::Git::CrossRepoComparer into a general Gitlab::Git::CrossRepo.

It's a prerequisite to implementing this feature How far is your fork behind/ahead of the upstre... (#14491 - closed)

We want to count commits (for example, using count_commits_between method). But currently, we have the following behavior:

  • Fork a repo
  • Create a commit in the source repo
  • Call count_commits_between expecting that the fork is behind 1 commit
  • The method returns 0 because the source repo doesn't contain a commit from the target repo

It works correctly for Compare between repo and a fork and merge requests from forks because they fetch the source branch:

It would be cool to reuse the CrossRepoComparer functionality.


This MR shouldn't/doesn't change any behavior, it just makes it possible to do something like:

CrossRepo.new(source_repository, target_repository).execute(target_branch_name) do |target_commit_id|
  source_repository.count_commits_between(source_commit_id, target_commit_id)
end

Merge request reports

Loading