From patchwork Fri Jul 7 07:07:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 117003 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp3076163vqx; Fri, 7 Jul 2023 00:08:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlFgM7phQejCCz5khKf/GGf7BBn943XcbEm068xgSPUYr+3i180yR+AElwjMindiJ1JwE0/8 X-Received: by 2002:a17:906:e17:b0:992:a838:a564 with SMTP id l23-20020a1709060e1700b00992a838a564mr2605555eji.28.1688713711708; Fri, 07 Jul 2023 00:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688713711; cv=none; d=google.com; s=arc-20160816; b=tyZn7zm4T6CjVK9f0QMxEXLa8sTXv1/3XUm+1976GttL5SDmjUu7SdzJ7DNgU9pYhc SEG69wbFrqN7zokAdTqUHto8Lrygxp1uT6uGL54vQIKDZNvFo/+ALjqeBt3Kwc7eMKzY 8//UgNShuXrFuoQcDGR1yga2mYQ/RgYW9Fkeg4d4oJM/BA7OsirR830YqFxu8REe0ruH vuvQ/9cJvU5fX7U0+OzD2Zeqpud4s8HuEMvYe2VhMzl7LdLOUoEh+n/zcUr1N8X3khIR GDZ58HYJYBLWVBO2vivdH5Lf3iUIxX53D64mBLF3wtJuuW56/bdnRt4QTzY1INPAQsyn BDOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=QS4LypVJoRvDnBFlQAosbRt+m5C4R5d4GCzbK/jJDiY=; fh=BJGtbeGb1fXIdly1jBl/UMGiVqkge20hnXmbid4f7vU=; b=J6u/oJPIXtJ+G9TPQeYjHU10t429VEc+m34JnsAOPz9FyK5/59sNt6xU+U63TpLAGc EOrWkZt+Zbs7r5CQHScKMRmRFo+I6e7lZEfGbt9KskZCxkRq0/ZUlME5w9bNZiSJNkrK 6zExSD3dND/ENgeftzzRrNdLUeAiuh9BL8B/meGCE9XwddQJBo9tDl7mwglDhohhejMV oBQoa3eNLYEgYWMHssjmipFRNZ6gSstTCuW/HcOSbB2izl5jrb5SvO6cdAB0d01OtgU8 s5tZuOf40a7+1pWzXDhl1U91rQO4msjrBMgXfQOz3N8mLJKyyIgP6917EaEQA4uxfVoo XWHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Df98u+4u; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qc17-20020a170906d8b100b00992b6f546b1si1802542ejb.77.2023.07.07.00.08.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 00:08:31 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Df98u+4u; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92740385696B for ; Fri, 7 Jul 2023 07:08:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92740385696B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688713710; bh=QS4LypVJoRvDnBFlQAosbRt+m5C4R5d4GCzbK/jJDiY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Df98u+4ue+zMh6oiPLG1+qAVCbfylCHdZ7VYB9m4wSR1ltXiLK+R36Dl9wNtE21jv iOu0ijAX0Jx9YLGpjNV9F/wVYmZwIxqRLyy/g2fmQ8cossPZHu9/TtQvQhSqfmOrFq SdRur2oGWDqi47ElfAt38HjGlQ/nOWy+DgTZTFYk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gandi.kataplop.net (gandi.kataplop.net [46.226.111.114]) by sourceware.org (Postfix) with ESMTPS id 517223858C60 for ; Fri, 7 Jul 2023 07:07:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 517223858C60 Received: from [176.191.105.132] (helo=arrakis.kataplop.net) by gandi.kataplop.net with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHfZ6-000169-Qp; Fri, 07 Jul 2023 09:07:41 +0200 To: gcc-patches@gcc.gnu.org Cc: =?utf-8?q?Marc_Poulhi=C3=A8s?= Subject: [PATCH] mklog: handle Signed-Off-By, minor cleanup Date: Fri, 7 Jul 2023 09:07:27 +0200 Message-Id: <20230707070727.658031-1-dkm@kataplop.net> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam_score: -1.0 X-Spam_bar: - X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770744668910995423?= X-GMAIL-MSGID: =?utf-8?q?1770744668910995423?= Consider Signed-off-by lines as part of the ending of the initial commit to avoid having these in the middle of the log when the changelog part is injected after. This is particularly usefull with: $ git gcc-commit-mklog --amend -s that can be used to create the changelog and add the Signed-Off-By line. Also applies most of the shellcheck suggestions on the prepare-commit-msg hook. Signed-off-by: Marc Poulhiès --- This command is used in particular during the dev of the frontend for the Rust language (see r13-7099-g4b25fc15b925f8 as an example). Ok for master? contrib/mklog.py | 34 +++++++++++++++++++++++++++++----- contrib/prepare-commit-msg | 20 ++++++++++---------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/contrib/mklog.py b/contrib/mklog.py index 777212c98d7..e5cc69e0d0a 100755 --- a/contrib/mklog.py +++ b/contrib/mklog.py @@ -41,7 +41,34 @@ from unidiff import PatchSet LINE_LIMIT = 100 TAB_WIDTH = 8 -CO_AUTHORED_BY_PREFIX = 'co-authored-by: ' + +# Initial commit: +# +--------------------------------------------------+ +# | gccrs: Some title | +# | | This is the "start" +# | This is some text explaining the commit. | +# | There can be several lines. | +# | |<-------------------> +# | Signed-off-by: My Name | This is the "end" +# +--------------------------------------------------+ +# +# Results in: +# +--------------------------------------------------+ +# | gccrs: Some title | +# | | +# | This is some text explaining the commit. | This is the "start" +# | There can be several lines. | +# | |<-------------------> +# | gcc/rust/ChangeLog: | +# | | This is the generated +# | * some_file (bla): | ChangeLog part +# | (foo): | +# | |<-------------------> +# | Signed-off-by: My Name | This is the "end" +# +--------------------------------------------------+ + +# this regex matches the first line of the "end" in the initial commit message +FIRST_LINE_OF_END_RE = re.compile('(?i)^(signed-off-by|co-authored-by|#): ') pr_regex = re.compile(r'(\/(\/|\*)|[Cc*!])\s+(?PPR [a-z+-]+\/[0-9]+)') prnum_regex = re.compile(r'PR (?P[a-z+-]+)/(?P[0-9]+)') @@ -330,10 +357,7 @@ def update_copyright(data): def skip_line_in_changelog(line): - if line.lower().startswith(CO_AUTHORED_BY_PREFIX) or line.startswith('#'): - return False - return True - + return FIRST_LINE_OF_END_RE.match(line) == None if __name__ == '__main__': extra_args = os.getenv('GCC_MKLOG_ARGS') diff --git a/contrib/prepare-commit-msg b/contrib/prepare-commit-msg index 48c9dad3c6f..1e94706ba40 100755 --- a/contrib/prepare-commit-msg +++ b/contrib/prepare-commit-msg @@ -32,11 +32,11 @@ if ! [ -f "$COMMIT_MSG_FILE" ]; then exit 0; fi # Don't do anything unless requested to. if [ -z "$GCC_FORCE_MKLOG" ]; then exit 0; fi -if [ -z "$COMMIT_SOURCE" ] || [ $COMMIT_SOURCE = template ]; then +if [ -z "$COMMIT_SOURCE" ] || [ "$COMMIT_SOURCE" = template ]; then # No source or "template" means new commit. cmd="diff --cached" -elif [ $COMMIT_SOURCE = message ]; then +elif [ "$COMMIT_SOURCE" = message ]; then # "message" means -m; assume a new commit if there are any changes staged. if ! git diff --cached --quiet; then cmd="diff --cached" @@ -44,23 +44,23 @@ elif [ $COMMIT_SOURCE = message ]; then cmd="diff --cached HEAD^" fi -elif [ $COMMIT_SOURCE = commit ]; then +elif [ "$COMMIT_SOURCE" = commit ]; then # The message of an existing commit. If it's HEAD, assume --amend; # otherwise, assume a new commit with -C. - if [ $SHA1 = HEAD ]; then + if [ "$SHA1" = HEAD ]; then cmd="diff --cached HEAD^" if [ "$(git config gcc-config.mklog-hook-type)" = "smart-amend" ]; then # Check if the existing message still describes the staged changes. f=$(mktemp /tmp/git-commit.XXXXXX) || exit 1 - git log -1 --pretty=email HEAD > $f - printf '\n---\n\n' >> $f - git $cmd >> $f + git log -1 --pretty=email HEAD > "$f" + printf '\n---\n\n' >> "$f" + git $cmd >> "$f" if contrib/gcc-changelog/git_email.py "$f" >/dev/null 2>&1; then # Existing commit message is still OK for amended commit. - rm $f + rm "$f" exit 0 fi - rm $f + rm "$f" fi else cmd="diff --cached" @@ -72,7 +72,7 @@ fi # Save diff to a file if requested. DIFF_FILE=$(git config gcc-config.diff-file) -if ! [ -z "$DIFF_FILE" ]; then +if [ -n "$DIFF_FILE" ]; then tee="tee $DIFF_FILE" else tee="cat"