Skip to content

Commit d657602

Browse files
committed
git-review-rebase: also flag changes in commit descriptions.
This just adds yet another marker, this time to show when there are changes to the commit description, which would otherwise not show if the patch-id are strictly equivalent. Signed-off-by: Quentin Casasnovas <quentin.casasnovas@vates.tech>
1 parent 4984934 commit d657602

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎scripts/git-review-rebase/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ An interactive TUI (Terminal User Interface) tool for reviewing rebased git bran
2020
| ---- | ----------------------------------------- |
2121
| `=` | Same commit (identical SHA1 |
2222
| `~` | Loose match (same title, patchid changed) |
23+
| `✎` | Commit message changed |
2324
| `⤶` | Already present in new upstream |
2425
| `✗` | Dropped during rebase |
2526
| `✚` | Added in rebase |
2627

28+
> A commit message comparison ignores trailing whitespace and surrounding blank lines, so `✎`
29+
> only shows up when the message content itself differs. It is never set on `=` matches, since
30+
> those commits are identical by definition.
31+
2732
> **Patchid** is a checksum of a commit's diff (`git patch-id`). Two commits with different
2833
> SHA1 (e.g. after rebase) that introduce the same code changes will have the same patchid.
2934
> This allows the tool to match commits across a rebase even when their SHA-1s change.

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from .branch_range import BranchRange
88
from .constants import CommitMatchInfoFlag
9-
from .git_utils import abbrev, commit_title
9+
from .git_utils import abbrev, commit_title, message_changed
1010

1111

1212
class RebasedCommitMatch:
@@ -67,6 +67,13 @@ def init_matches(self) -> None:
6767
if right_commit is not None:
6868
match_info = CommitMatchInfoFlag.LooseMatch
6969

70+
if (
71+
right_commit is not None
72+
and right_commit.id != left_commit.id
73+
and message_changed(left_commit, right_commit)
74+
):
75+
match_info |= CommitMatchInfoFlag.MessageChanged
76+
7077
if (
7178
right_commit is not None
7279
and right_commit.id not in self.right_range._rebased_commits

‎scripts/git-review-rebase/src/git_review_rebase/constants.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class SolarizedColors(StrEnum):
2828
class CommitMatchInfoFlag(Flag):
2929
SameCommit = auto()
3030
LooseMatch = auto()
31+
MessageChanged = auto()
3132
PresentInRebaseOnto = auto()
3233
Dropped = auto()
3334
Added = auto()
@@ -49,6 +50,11 @@ def __init__(self, flag, character, definition):
4950
Text("~", SolarizedColors.Yellow),
5051
"Commit patchid has changed",
5152
),
53+
CommitMatchInfoFlag.MessageChanged: CommitMatchInfo(
54+
CommitMatchInfoFlag.MessageChanged,
55+
Text("✎", SolarizedColors.Orange),
56+
"Commit message has changed",
57+
),
5258
CommitMatchInfoFlag.PresentInRebaseOnto: CommitMatchInfo(
5359
CommitMatchInfoFlag.PresentInRebaseOnto,
5460
Text("⤶", SolarizedColors.Blue),

‎scripts/git-review-rebase/src/git_review_rebase/git_utils.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ def commit_title(commit: pygit2.Commit) -> str:
4040
return (commit.message.splitlines() or [""])[0]
4141

4242

43+
def normalized_message(commit: pygit2.Commit) -> str:
44+
"""Commit message without trailing whitespace nor surrounding blank lines."""
45+
return "\n".join(line.rstrip() for line in commit.message.strip().splitlines())
46+
47+
48+
def message_changed(left_commit: pygit2.Commit, right_commit: pygit2.Commit) -> bool:
49+
"""Return True if both commits do not share the same message."""
50+
return normalized_message(left_commit) != normalized_message(right_commit)
51+
52+
4353
def cached_patchid_ref(revision: str) -> str:
4454
"""Poor man's cache in git refs directly using merkle trees."""
4555
return f"refs/patchids/from_revision/" f"{revision[:2]}/{revision[2:4]}/{revision[4:]}"

0 commit comments

Comments
 (0)