Skip to content

Commit 7af5a5f

Browse files
committed
git-review-rebase: interleave added commits based on their position in the rebased branch.
Added commits were showing as the first commits in the rebase table as they were added last to the commit_matches dictionnary. It is fine when said commits are added on top of the branch, like when we're working on the linux kernel and add commits neutralizing kABI changes, but when using git-review-rebase on branches imported from XenServer SRPMs, XenServer folks often add some patchsets in the middle of their patch-queue - it is nice in those cases to see the extra added commits interleaved with the other matched right commits. Signed-off-by: Quentin Casasnovas <quentin.casasnovas@vates.tech>
1 parent 34270f0 commit 7af5a5f

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

scripts/git-review-rebase/src/git_review_rebase/commit_matching.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,33 @@ def init_matches(self) -> None:
7272
if right_commit is not None and right_commit.id in right_commit_keys:
7373
del right_commit_keys[right_commit.id]
7474

75-
# Remainders commits on the right side
75+
right_position = {oid: idx for idx, oid in enumerate(self.right_range._rebased_commits)}
76+
77+
added_commits: list[tuple[pygit2.Oid, RebasedCommitMatch]] = []
7678
for right_commit_id in right_commit_keys:
7779
right_commit = self.repo.get(right_commit_id)
7880
assert isinstance(right_commit, pygit2.Commit)
79-
self.commit_matches[right_commit_id] = RebasedCommitMatch(
80-
None, right_commit, CommitMatchInfoFlag.Added
81+
added_commits.append(
82+
(right_commit_id, RebasedCommitMatch(None, right_commit, CommitMatchInfoFlag.Added))
8183
)
82-
self.commit_matches.update(left_commit_matches)
84+
85+
# Interleave Added commits with left commits based on right-branch position.
86+
# For each matched left commit, flush Added commits whose right-branch position
87+
# comes before it. Dropped/PresentInRebaseOnto left commits (no position in
88+
# right_position) are passed through immediately without flushing.
89+
added_idx = 0
90+
for left_commit_oid, left_match in left_commit_matches.items():
91+
if left_match.right_commit is not None and left_match.right_commit.id in right_position:
92+
current_right_pos = right_position[left_match.right_commit.id]
93+
while (
94+
added_idx < len(added_commits)
95+
and right_position[added_commits[added_idx][0]] < current_right_pos
96+
):
97+
added_commit_id, added_commit_match_info = added_commits[added_idx]
98+
self.commit_matches[added_commit_id] = added_commit_match_info
99+
added_idx += 1
100+
self.commit_matches[left_commit_oid] = left_match
101+
102+
# Append remaining Added commits (those after all matched right commits)
103+
for added_commit_id, added_commit_match_info in added_commits[added_idx:]:
104+
self.commit_matches[added_commit_id] = added_commit_match_info

0 commit comments

Comments
 (0)