On 16/06/20 19:58, John Snow wrote: > 1. Correlating a mailing list patch from e.g. patchew to a commit in my > history, even if it's changed a little bit?
Use "git am --message-id"? > (git-backport-diff uses patch names, that might be sufficient... Could > use that as a starting point, at least.) > > 2. Obtaining the commit message of that patch? > `git show -s --format=%B $SHA` ought to do it... > > 3. Editing that commit message? This I'm not sure about. I'd need to > understand the tags on the upstream and downstream versions, merge them, > and then re-write the message. Some magic with `git rebase -i` ? "patchew apply" actually uses "git filter-branch --msg-filter" to add the tags after a successful "git am", so you can do something similar yourself. (Actually I have pending patches to patchew that switch it to server-side application of tags using the "mbox" URL that Philippe mentioned earlier, but they've been pending for quite some time now). To get the upstream tags you can use the Patchew REST API: $ [email protected] $ curl -L https://patchew.org/api/v1/projects/by-name/QEMU/messages/$MSGID/ | jq -r '.tags[]' Reported-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Richard Henderson <[email protected]> So you'd have to take a commit, look for a Message-Id header, fetch the tags from above mentioned Patchew API URL and add the tags to the commit message. The commit message can be either emitted to stdout (and the script used with "git filter-branch)" or, for the faint of heart, the script could do a "git commit --amend" and you can use "git rebase -i --exec" to execute the script on all commits in a range. This script is for the latter option: #! /bin/bash BODY=$(git show -s --format=%B) MSGID=$(git interpret-trailers --parse <<< $BODY | sed -n 's/^Message-Id: <\(.*\)>/\1/ip') USER="$(git config user.name) <$(git config user.email)>" BODY=$(curl -L https://patchew.org/api/v1/projects/by-name/QEMU/messages/$MSGID/ | \ jq -r '.tags[]' | ( \ args=() while read x; do args+=(--trailer "$x") done git interpret-trailers \ --if-exists doNothing "${args[@]}" \ --if-exists replace --if-missing doNothing --trailer "Signed-off-by: $USER" <<< $BODY )) git commit --amend -m"$BODY" The script will also move your Signed-off-by line at the end of the commit message, this might be a problem if there is more than one such line and you want to keep them all. Paolo
