Hello,
On Mon, Nov 06 2023, Florian Weimer via Gcc wrote:
> Emacs has a very useful facility. You press “C-x 4 a” in a place where
> you make changes, and the editor automatically opens the right ChangeLog
> file and adds a draft entry to it, like this:
>
> 2023-11-06 Florian Weimer <[email protected]>
>
> * c-opts.cc (c_common_post_options): █
>
> Is there something like this that works with commit messages and
> produces output compatible with GCC's expectations?
>
I use exactly this. But I modify it to write the ChangeLog to file
ChangeLog.mine instead:
(setq change-log-default-name "ChangeLog.mine")
Then in a git prepare-commit-msg hook I gather these:
----------------------------------------------------------------------
#!/bin/bash
#
# Hook script to prepare the commit log message from the first
# entry in each modified ChangeLog being committed.
set -e
# echo $1 $2 $3
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
# "merge" means the commit is a merge or a .git/MERGE_MSG file exists.
# "message" means a -m or -F option was given.
# "squash" means a .git/SQUASH_MSG file exists.
# "commit" means a -c, -C or --amend option was given (and $3 is commit SHA1).
case "$2," in
merge,|squash,) exit ;;
message,) exit ;;
esac
# If there is already a ChangeLog entry, assume --amend and exit
grep -q "ChangeLog" "$COMMIT_MSG_FILE" && exit 0
TMPF=$(mktemp)
echo > $TMPF
for I in `find . -name ChangeLog.mine -type f -size +0c | xargs`; do
echo >> $TMPF
CNF=`echo ${I%.mine} | cut -c3-` >> $TMPF
echo "${CNF}:" >> $TMPF
echo >> $TMPF
awk -v n=2 '/^2/{p++} p<n' $I >> $TMPF
done
echo >> $TMPF
cat $COMMIT_MSG_FILE >> $TMPF
mv $TMPF $COMMIT_MSG_FILE
----------------------------------------------------------------------
The only downside is that you need to truncate the ChangeLog.mine files
at the appropriate time. The big upside is that you can generate
ChangeLog as you stage hunks in emacs magit.
Martin