diff --git a/pagure/internal/__init__.py b/pagure/internal/__init__.py index 0a3bca2..d76b7b8 100644 --- a/pagure/internal/__init__.py +++ b/pagure/internal/__init__.py @@ -296,7 +296,7 @@ def get_pull_request_ready_branch(): if compare_branch: try: com = main_walker.next() - main_commits.add(com.hex) + main_commits.add(com.oid.hex) except StopIteration: com = None try: @@ -309,22 +309,17 @@ def get_pull_request_ready_branch(): break if branch_commit: - tmp = set(branch_commits + [branch_commit.hex]) - else: - tmp = set(branch_commits) - if main_commits.intersection(tmp): - break - - if branch_commit: branch_commits.append(branch_commit.hex) + if main_commits.intersection(set(branch_commits)): + break # If master is ahead of branch, we need to remove the commits - # that are already in master - branch_commits = [ - com - for com in branch_commits - if com not in main_commits - ] + # that are after the first one found in master + i = 0 + for i in range(len(branch_commits)): + if branch_commits[i] in main_commits: + break + branch_commits = branch_commits[:i] if branch_commits: branches[branchname] = branch_commits diff --git a/pagure/lib/git.py b/pagure/lib/git.py index e177772..8a9b118 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -1377,7 +1377,7 @@ def diff_pull_request( while 1: try: com = main_walker.next() - main_commits.add(com.hex) + main_commits.add(com.oid.hex) except StopIteration: com = None @@ -1392,19 +1392,17 @@ def diff_pull_request( if branch_commit: branch_commits.add(branch_commit.oid.hex) + diff_commits.append(branch_commit) if main_commits.intersection(branch_commits): break - if branch_commit: - diff_commits.append(branch_commit) - # If master is ahead of branch, we need to remove the commits - # that are already in master - diff_commits = [ - com - for com in diff_commits - if com.oid.hex not in main_commits - ] + # that are after the first one found in master + i = 0 + for i in range(len(diff_commits)): + if diff_commits[i].oid.hex in main_commits: + break + diff_commits = diff_commits[:i] if request.status and diff_commits: first_commit = repo_obj[diff_commits[-1].oid.hex] diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index 8338e93..75d4818 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -96,7 +96,7 @@ def _get_pr_info(repo_obj, orig_repo, branch_from, branch_to): while 1: try: com = main_walker.next() - main_commits.add(com.hex) + main_commits.add(com.oid.hex) except StopIteration: com = None @@ -111,19 +111,17 @@ def _get_pr_info(repo_obj, orig_repo, branch_from, branch_to): if branch_commit: branch_commits.add(branch_commit.oid.hex) + diff_commits.append(branch_commit) if main_commits.intersection(branch_commits): break - if branch_commit: - diff_commits.append(branch_commit) - # If master is ahead of branch, we need to remove the commits - # that are already in master - diff_commits = [ - com - for com in diff_commits - if com.oid.hex not in main_commits - ] + # that are after the first one found in master + i = 0 + for i in range(len(diff_commits)): + if diff_commits[i].oid.hex in main_commits: + break + diff_commits = diff_commits[:i] if diff_commits: first_commit = repo_obj[diff_commits[-1].oid.hex]