From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gandi.kataplop.net (gandi.kataplop.net [46.226.111.114]) by sourceware.org (Postfix) with ESMTPS id F03823853D26 for ; Fri, 21 Jul 2023 11:08:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F03823853D26 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=kataplop.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kataplop.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kataplop.net; s=rsa1; h=Content-Transfer-Encoding:Content-Type:MIME-Version :Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=sE5MPZBO+IMSyFc3zZ4C8GypRMxx6C8xFcFFrFavPdo=; b=joXPVZNxrX0kQ692Rz5uMs/rwi +hcDvAC45v3A5H1/zO5bN/olpCZqqhnM9sYqngnDN8EPbiD4dX0bJPpVPwAVtkINN0mliee7x8Zqa lz0HAG9Fq6T7zN8FXi/nYpwRDXYqhXMljIO8Oothj9rSlWXMJhJgLzytBiXF9CogrXf4=; 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 1qMnzj-0004g2-9P; Fri, 21 Jul 2023 13:08:23 +0200 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Subject: [PATCH v2] mklog: handle Signed-Off-By, minor cleanup Date: Fri, 21 Jul 2023 13:08:13 +0200 Message-Id: <20230721110813.3136547-1-dkm@kataplop.net> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam_score: -1.0 X-Spam_bar: - X-Spam-Status: No, score=-9.1 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 List-Id: 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. contrib/ChangeLog: * mklog.py: Leave SOB lines after changelog. * prepare-commit-msg: Apply most shellcheck suggestions. Signed-off-by: Marc Poulhiès --- Previous version was missing the ChangeLog. This command is used in particular during the dev of the frontend for the Rust language (see r13-7099-g4b25fc15b925f8 as an example of a SoB ending in the middle of the commit message). 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" -- 2.40.1