https://gcc.gnu.org/g:cc7f48e65b9aadb885461dea201d6028cc008ea1

commit cc7f48e65b9aadb885461dea201d6028cc008ea1
Author: Tobias Burnus <tbur...@baylibre.com>
Date:   Thu May 22 17:06:38 2025 +0200

    git_repository.py: Fix handling of --last-commit with merges
    
    contrib/ChangeLog:
    
            * gcc-changelog/git_update_version.py (update_current_branch): Fix
            handling of merges.
            * gcc-changelog/git_repository.py (parse_git_revisions): Skip over
            merge commits for merges from exclude branch.

Diff:
---
 contrib/gcc-changelog/git_repository.py     |  9 +++++++--
 contrib/gcc-changelog/git_update_version.py | 28 ++++++++++++++--------------
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/contrib/gcc-changelog/git_repository.py 
b/contrib/gcc-changelog/git_repository.py
index dc658af83b9b..c70307d2c30e 100755
--- a/contrib/gcc-changelog/git_repository.py
+++ b/contrib/gcc-changelog/git_repository.py
@@ -77,8 +77,13 @@ def parse_git_revisions(repo_path, revisions, ref_name=None,
         commits = [repo.commit(revisions)]
 
     for commit in commits:
-        if exclude_branch is not None and repo.is_ancestor(commit, 
exclude_branch):
-            continue
+        if exclude_branch is not None:
+            if repo.is_ancestor(commit, exclude_branch):
+                continue
+            # Exlude merge commit
+            if (len(commit.parents) == 2
+                and repo.is_ancestor(commit.parents[1], exclude_branch)):
+                continue
         git_commit = GitCommit(commit_to_info(commit.hexsha),
                                commit_to_info_hook=commit_to_info,
                                ref_name=ref_name)
diff --git a/contrib/gcc-changelog/git_update_version.py 
b/contrib/gcc-changelog/git_update_version.py
index ec5951ca2686..ae2630ea5756 100755
--- a/contrib/gcc-changelog/git_update_version.py
+++ b/contrib/gcc-changelog/git_update_version.py
@@ -124,21 +124,19 @@ def update_current_branch(ref_name=None, suffix="", 
last_commit_ref=None,
                           exclude_branch=None):
     commit = repo.head.commit
     commit_count = 1
-    last_commit = (repo.commit(last_commit_ref)
-                   if last_commit_ref is not None else None)
-    while commit:
-        if last_commit is not None:
-            if last_commit == commit:
+    if last_commit_ref is not None:
+        commit = repo.commit(last_commit_ref)
+    else:
+        while commit:
+            if (commit.author.email == 'gccad...@gcc.gnu.org'
+                  and commit.message.strip() == 'Daily bump.'):
                 break
-        elif (commit.author.email == 'gccad...@gcc.gnu.org'
-              and commit.message.strip() == 'Daily bump.'):
-            break
-        # We support merge commits but only with 2 parensts
-        assert len(commit.parents) <= 2
-        commit = commit.parents[-1]
-        commit_count += 1
-
-    logging.info('%d revisions since last Daily bump' % commit_count)
+            # We support merge commits but only with 2 parensts
+            assert len(commit.parents) <= 2
+            commit = commit.parents[-1]
+            commit_count += 1
+        logging.info('%d revisions since last Daily bump' % commit_count)
+
     datestamp_path = os.path.join(args.git_path, 'gcc/DATESTAMP')
     if suffix != "":
         if not os.path.exists(datestamp_path + suffix):
@@ -158,6 +156,8 @@ def update_current_branch(ref_name=None, suffix="", 
last_commit_ref=None,
                                       % (commit.hexsha, head.hexsha), ref_name,
                                       exclude_branch)
         commits = [c for c in commits if c.info.hexsha not in ignored_commits]
+        if last_commit_ref is not None:
+            logging.info('%d revisions since last Daily bump' % len(commits))
         for git_commit in reversed(commits):
             prepend_to_changelog_files(repo, args.git_path, git_commit,
                                        not args.dry_mode, args.suffix)

Reply via email to