public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <tburnus@baylibre.com>
To: Jakub Jelinek <jakub@redhat.com>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [Patch] contrib/gcc-changelog/git_update_version.py: Improve diagnostic
Date: Tue, 21 May 2024 09:36:05 +0200	[thread overview]
Message-ID: <a3315261-60b2-4a45-b7cc-58c70a5cf4b3@baylibre.com> (raw)
In-Reply-To: <Zkr+Ip8FAxmWwyjf@tucnak>


[-- Attachment #1.1: Type: text/plain, Size: 1594 bytes --]

Hi Jakub,

Jakub Jelinek wrote:
> On Mon, May 20, 2024 at 08:31:02AM +0200, Tobias Burnus wrote:
>> Hmm, there were now two daily bumps: [...] I really wonder why.
> Because I've done it by hand.

Okay, that explains it.

I still do not understand why it slipped through at the first place; I 
tried old versions down to r12-709-g772e5e82e3114f and it still FAIL for 
the invalid commit ("ERR: cannot find a ChangeLog location in message").

Thus, I wonder whether the commit hook is active at all?!?

> I have in ~gccadmin a gcc-changelog copy and adjusted update_version_git
> script which doesn't use contrib/gcc-changelog subdirectory from the
> checkout it makes but from the ~gccadmin directory,
[...]
> I'm already using something similar in
> my hack (just was doing it for even successful commits, but I think your
> patch is better).
> And, I think best would be if update_version_git script simply
> accepted a list of ignored commits from the command line too,
> passed it to the git_update_version.py script and that one
> added those to IGNORED_COMMITS.

Updated version:

* Uses my diagnostic

* Adds an -i/--ignore argument for commits. Permits to use '-i hash1  -i 
hash2' but also '-i hash1,hash2' or '-i "hash1 hash2'

* I changed the global variable to lower case as Python's style guide 
states that all uppercase variables is for constants.

* The '=None' matches one of the current usages (no argument passed); 
hence, it is now explicit and 'pylint' is happy.

OK for mainline?

Tobias

PS: I have not updated the hashes. If needed/wanted, I leave that to 
you, Jakub.

[-- Attachment #2: git_update_version-v3.patch --]
[-- Type: text/x-patch, Size: 3559 bytes --]

contrib/gcc-changelog/git_update_version.py: Improve diagnostic

contrib/ChangeLog:

	* gcc-changelog/git_update_version.py: Add '-i'/'--ignore' argument
	to add to-be-ignored commits via the command line.
	(ignored_commits): Rename from IGNORED_COMMITS and change
	type from tuple to set.
	(prepend_to_changelog_files): Show git hash if errors occurred.
	(update_current_branch): Mark argument as optional by defaulting
	to None.

 contrib/gcc-changelog/git_update_version.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/contrib/gcc-changelog/git_update_version.py b/contrib/gcc-changelog/git_update_version.py
index 24f6c43d0b2..c69a3a6897a 100755
--- a/contrib/gcc-changelog/git_update_version.py
+++ b/contrib/gcc-changelog/git_update_version.py
@@ -22,6 +22,7 @@ import argparse
 import datetime
 import logging
 import os
+import re
 
 from git import Repo
 
@@ -30,7 +31,7 @@ from git_repository import parse_git_revisions
 current_timestamp = datetime.datetime.now().strftime('%Y%m%d\n')
 
 # Skip the following commits, they cannot be correctly processed
-IGNORED_COMMITS = (
+ignored_commits = {
         'c2be82058fb40f3ae891c68d185ff53e07f14f45',
         '04a040d907a83af54e0a98bdba5bfabc0ef4f700',
         '2e96b5f14e4025691b57d2301d71aa6092ed44bc',
@@ -41,7 +42,7 @@ IGNORED_COMMITS = (
         '040e5b0edbca861196d9e2ea2af5e805769c8d5d',
         '8057f9aa1f7e70490064de796d7a8d42d446caf8',
         '109f1b28fc94c93096506e3df0c25e331cef19d0',
-        '39f81924d88e3cc197fc3df74204c9b5e01e12f7')
+        '39f81924d88e3cc197fc3df74204c9b5e01e12f7'}
 
 FORMAT = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
 logging.basicConfig(level=logging.INFO, format=FORMAT,
@@ -58,6 +59,7 @@ def read_timestamp(path):
 
 def prepend_to_changelog_files(repo, folder, git_commit, add_to_git):
     if not git_commit.success:
+        logging.info(f"While processing {git_commit.info.hexsha}:")
         for error in git_commit.errors:
             logging.info(error)
         raise AssertionError()
@@ -93,13 +95,15 @@ parser.add_argument('-d', '--dry-mode',
                          ' is expected')
 parser.add_argument('-c', '--current', action='store_true',
                     help='Modify current branch (--push argument is ignored)')
+parser.add_argument('-i', '--ignore', action='append',
+                    help='list of commits to ignore')
 args = parser.parse_args()
 
 repo = Repo(args.git_path)
 origin = repo.remotes['origin']
 
 
-def update_current_branch(ref_name):
+def update_current_branch(ref_name=None):
     commit = repo.head.commit
     commit_count = 1
     while commit:
@@ -123,7 +127,7 @@ def update_current_branch(ref_name):
             head = head.parents[1]
         commits = parse_git_revisions(args.git_path, '%s..%s'
                                       % (commit.hexsha, head.hexsha), ref_name)
-        commits = [c for c in commits if c.info.hexsha not in IGNORED_COMMITS]
+        commits = [c for c in commits if c.info.hexsha not in ignored_commits]
         for git_commit in reversed(commits):
             prepend_to_changelog_files(repo, args.git_path, git_commit,
                                        not args.dry_mode)
@@ -153,6 +157,9 @@ def update_current_branch(ref_name):
     else:
         logging.info('DATESTAMP unchanged')
 
+if args.ignore is not None:
+    for item in args.ignore:
+        ignored_commits.update(set(i for i in re.split(r'\s*,\s*|\s+', item)))
 
 if args.current:
     logging.info('=== Working on the current branch ===')

  reply	other threads:[~2024-05-21  7:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-19  7:00 [Patch] contrib/gcc-changelog/git_update_version.py: Add ignore commit, improve diagnostic Tobias Burnus
2024-05-20  6:31 ` [Patch] contrib/gcc-changelog/git_update_version.py: Improve diagnostic (was: [Patch] contrib/gcc-changelog/git_update_version.py: Add ignore commit, improve diagnostic) Tobias Burnus
2024-05-20  7:39   ` Jakub Jelinek
2024-05-21  7:36     ` Tobias Burnus [this message]
2024-05-21  7:57       ` [Patch] contrib/gcc-changelog/git_update_version.py: Improve diagnostic Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a3315261-60b2-4a45-b7cc-58c70a5cf4b3@baylibre.com \
    --to=tburnus@baylibre.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).