git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Non-interactively rewording commit messages
@ 2022-06-30 15:27 Konstantin Ryabitsev
  2022-06-30 17:32 ` Carlo Marcelo Arenas Belón
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Konstantin Ryabitsev @ 2022-06-30 15:27 UTC (permalink / raw)
  To: git

Hello, all:

What's the best approach to non-interactively rewrite specific commit
messages? In this particular case, I am trying to automatically retrieve code
review trailers sent to the mailing list and put them into corresponding
commits.

For example, I have a set of commits:

abcabc: This commit does foo
bcdbcd: This commit does bar
cdecde: This commit does baz

They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
to the second commit. In a usual interactive rebase session this would be:

pick abcabc
reword bcdbcd
pick cdecde

When the edit screen comes up for the bcdbcd commit, the author would manually
stick the new trailer into the commit message. However, I can automate all
that away with b4 -- just need a sane strategy for non-interactively rewriting
entire commit messages at arbitrary points in the recent history.

Any pointers?

-Konstantin

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Non-interactively rewording commit messages
  2022-06-30 15:27 Non-interactively rewording commit messages Konstantin Ryabitsev
@ 2022-06-30 17:32 ` Carlo Marcelo Arenas Belón
  2022-06-30 17:34 ` Christian Couder
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Carlo Marcelo Arenas Belón @ 2022-06-30 17:32 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: git

On Thu, Jun 30, 2022 at 11:27:57AM -0400, Konstantin Ryabitsev wrote:
> just need a sane strategy for non-interactively rewriting
> entire commit messages at arbitrary points in the recent history.

assuming you are still doing it by calling (albeit programmatically):

  rebase --autosquash -i

then you could prepare the new message by also programmatically doing
a `git commit --fixup reword:<commit>` IMHO

Carlo

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Non-interactively rewording commit messages
  2022-06-30 15:27 Non-interactively rewording commit messages Konstantin Ryabitsev
  2022-06-30 17:32 ` Carlo Marcelo Arenas Belón
@ 2022-06-30 17:34 ` Christian Couder
  2022-06-30 17:54   ` Konstantin Ryabitsev
  2022-06-30 21:35   ` Junio C Hamano
  2022-06-30 21:17 ` brian m. carlson
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 11+ messages in thread
From: Christian Couder @ 2022-06-30 17:34 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: git

Hi,

On Thu, Jun 30, 2022 at 5:35 PM Konstantin Ryabitsev
<konstantin@linuxfoundation.org> wrote:
>
> Hello, all:
>
> What's the best approach to non-interactively rewrite specific commit
> messages? In this particular case, I am trying to automatically retrieve code
> review trailers sent to the mailing list and put them into corresponding
> commits.
>
> For example, I have a set of commits:
>
> abcabc: This commit does foo
> bcdbcd: This commit does bar
> cdecde: This commit does baz
>
> They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
> to the second commit. In a usual interactive rebase session this would be:
>
> pick abcabc
> reword bcdbcd
> pick cdecde
>
> When the edit screen comes up for the bcdbcd commit, the author would manually
> stick the new trailer into the commit message. However, I can automate all
> that away with b4 -- just need a sane strategy for non-interactively rewriting
> entire commit messages at arbitrary points in the recent history.
>
> Any pointers?

Have you tried `git interpret-trailers`?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Non-interactively rewording commit messages
  2022-06-30 17:34 ` Christian Couder
@ 2022-06-30 17:54   ` Konstantin Ryabitsev
  2022-06-30 18:10     ` Ævar Arnfjörð Bjarmason
  2022-06-30 21:35   ` Junio C Hamano
  1 sibling, 1 reply; 11+ messages in thread
From: Konstantin Ryabitsev @ 2022-06-30 17:54 UTC (permalink / raw)
  To: Christian Couder; +Cc: git

On Thu, Jun 30, 2022 at 07:34:54PM +0200, Christian Couder wrote:
> > Hello, all:
> >
> > What's the best approach to non-interactively rewrite specific commit
> > messages? In this particular case, I am trying to automatically retrieve code
> > review trailers sent to the mailing list and put them into corresponding
> > commits.
> >
> > For example, I have a set of commits:
> >
> > abcabc: This commit does foo
> > bcdbcd: This commit does bar
> > cdecde: This commit does baz
> >
> > They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
> > to the second commit. In a usual interactive rebase session this would be:
> >
> > pick abcabc
> > reword bcdbcd
> > pick cdecde
> >
> > When the edit screen comes up for the bcdbcd commit, the author would manually
> > stick the new trailer into the commit message. However, I can automate all
> > that away with b4 -- just need a sane strategy for non-interactively rewriting
> > entire commit messages at arbitrary points in the recent history.
> >
> > Any pointers?
> 
> Have you tried `git interpret-trailers`?

I'm aware of interpret-trailers, but unless I'm missing something large, it's
just a way of analyzing standalone text files to retrieve or insert trailers.
What I'm looking for is a way to amend arbitrary commit messages within recent
git history.

-K

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Non-interactively rewording commit messages
  2022-06-30 17:54   ` Konstantin Ryabitsev
@ 2022-06-30 18:10     ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 11+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-06-30 18:10 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: Christian Couder, git


On Thu, Jun 30 2022, Konstantin Ryabitsev wrote:

> On Thu, Jun 30, 2022 at 07:34:54PM +0200, Christian Couder wrote:
>> > Hello, all:
>> >
>> > What's the best approach to non-interactively rewrite specific commit
>> > messages? In this particular case, I am trying to automatically retrieve code
>> > review trailers sent to the mailing list and put them into corresponding
>> > commits.
>> >
>> > For example, I have a set of commits:
>> >
>> > abcabc: This commit does foo
>> > bcdbcd: This commit does bar
>> > cdecde: This commit does baz
>> >
>> > They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
>> > to the second commit. In a usual interactive rebase session this would be:
>> >
>> > pick abcabc
>> > reword bcdbcd
>> > pick cdecde
>> >
>> > When the edit screen comes up for the bcdbcd commit, the author would manually
>> > stick the new trailer into the commit message. However, I can automate all
>> > that away with b4 -- just need a sane strategy for non-interactively rewriting
>> > entire commit messages at arbitrary points in the recent history.
>> >
>> > Any pointers?
>> 
>> Have you tried `git interpret-trailers`?
>
> I'm aware of interpret-trailers, but unless I'm missing something large, it's
> just a way of analyzing standalone text files to retrieve or insert trailers.
> What I'm looking for is a way to amend arbitrary commit messages within recent
> git history.

I think what's being suggested is that once you have a program that can
munge a commit message on stdin, you can combine it with rebase, git
commit --amend etc. to change existing commits.q

The t/t7513-interpret-trailers.sh test has some examples of munging
existing content.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Non-interactively rewording commit messages
  2022-06-30 15:27 Non-interactively rewording commit messages Konstantin Ryabitsev
  2022-06-30 17:32 ` Carlo Marcelo Arenas Belón
  2022-06-30 17:34 ` Christian Couder
@ 2022-06-30 21:17 ` brian m. carlson
  2022-07-01  4:01 ` Elijah Newren
  2022-07-01 13:37 ` Johannes Schindelin
  4 siblings, 0 replies; 11+ messages in thread
From: brian m. carlson @ 2022-06-30 21:17 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1280 bytes --]

On 2022-06-30 at 15:27:57, Konstantin Ryabitsev wrote:
> Hello, all:
> 
> What's the best approach to non-interactively rewrite specific commit
> messages? In this particular case, I am trying to automatically retrieve code
> review trailers sent to the mailing list and put them into corresponding
> commits.
> 
> For example, I have a set of commits:
> 
> abcabc: This commit does foo
> bcdbcd: This commit does bar
> cdecde: This commit does baz
> 
> They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
> to the second commit. In a usual interactive rebase session this would be:
> 
> pick abcabc
> reword bcdbcd
> pick cdecde

You can set GIT_SEQUENCE_EDITOR to a command which does this in-place on
the file...

> When the edit screen comes up for the bcdbcd commit, the author would manually
> stick the new trailer into the commit message. However, I can automate all
> that away with b4 -- just need a sane strategy for non-interactively rewriting
> entire commit messages at arbitrary points in the recent history.

...and you can set GIT_EDITOR to modify the commit message in-place in
whatever way you want, and then use git rebase -i to rebase.
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Non-interactively rewording commit messages
  2022-06-30 17:34 ` Christian Couder
  2022-06-30 17:54   ` Konstantin Ryabitsev
@ 2022-06-30 21:35   ` Junio C Hamano
  2022-07-01 11:10     ` Christian Couder
  1 sibling, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2022-06-30 21:35 UTC (permalink / raw)
  To: Christian Couder; +Cc: Konstantin Ryabitsev, git

Christian Couder <christian.couder@gmail.com> writes:

>> For example, I have a set of commits:
>>
>> abcabc: This commit does foo
>> bcdbcd: This commit does bar
>> cdecde: This commit does baz
>>
>> They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
>> to the second commit. In a usual interactive rebase session this would be:
> ...
>
> Have you tried `git interpret-trailers`?

Do you mean a

	git fast-export |
	git interpret-trailers |
	git fast-import

pipeline?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Non-interactively rewording commit messages
  2022-06-30 15:27 Non-interactively rewording commit messages Konstantin Ryabitsev
                   ` (2 preceding siblings ...)
  2022-06-30 21:17 ` brian m. carlson
@ 2022-07-01  4:01 ` Elijah Newren
  2022-07-01 18:18   ` Konstantin Ryabitsev
  2022-07-01 13:37 ` Johannes Schindelin
  4 siblings, 1 reply; 11+ messages in thread
From: Elijah Newren @ 2022-07-01  4:01 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: Git Mailing List

On Thu, Jun 30, 2022 at 8:35 AM Konstantin Ryabitsev
<konstantin@linuxfoundation.org> wrote:
>
> Hello, all:
>
> What's the best approach to non-interactively rewrite specific commit
> messages? In this particular case, I am trying to automatically retrieve code
> review trailers sent to the mailing list and put them into corresponding
> commits.
>
> For example, I have a set of commits:
>
> abcabc: This commit does foo
> bcdbcd: This commit does bar
> cdecde: This commit does baz
>
> They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
> to the second commit. In a usual interactive rebase session this would be:
>
> pick abcabc
> reword bcdbcd
> pick cdecde
>
> When the edit screen comes up for the bcdbcd commit, the author would manually
> stick the new trailer into the commit message. However, I can automate all
> that away with b4 -- just need a sane strategy for non-interactively rewriting
> entire commit messages at arbitrary points in the recent history.
>
> Any pointers?

One possibility would be to tweak
https://github.com/newren/git-filter-repo/blob/main/contrib/filter-repo-demos/signed-off-by,
modifying the line setting the 'trailer' variable to make it be a
Reviewed-by rather than a Signed-off-by.  You could tweak the script
to also make other automated commit message changes unrelated to any
trailers, if you wanted.

(There's also the slightly less careful way of adding trailers shown
over at https://github.com/newren/git-filter-repo/blob/main/Documentation/converting-from-filter-branch.md#rewriting-commit-messages----adding-text,
but the literal appending instead of determining whether to also first
add one or more newlines before the trailer might not be exactly what
you want.)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Non-interactively rewording commit messages
  2022-06-30 21:35   ` Junio C Hamano
@ 2022-07-01 11:10     ` Christian Couder
  0 siblings, 0 replies; 11+ messages in thread
From: Christian Couder @ 2022-07-01 11:10 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Konstantin Ryabitsev, git

On Thu, Jun 30, 2022 at 11:35 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Christian Couder <christian.couder@gmail.com> writes:

> > Have you tried `git interpret-trailers`?
>
> Do you mean a
>
>         git fast-export |
>         git interpret-trailers |
>         git fast-import
>
> pipeline?

I was thinking about using ways that are described a bit in the `git
interpret-trailers` doc. And I was thinking about using  ̀git rebase
-i` and either adding "exec ..." lines to the todo list (possibly with
`--exec ...` ) or maybe using "reword ..."

About ways that are described in the `git interpret-trailers` doc, there is:

* the following example with `git format-patch`:

      •   Extract the last commit as a patch, and add a Cc and a
Reviewed-by trailer to it:

              $ git format-patch -1
              0001-foo.patch
              $ git interpret-trailers --trailer 'Cc: Alice
<alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>'
0001-foo.patch >0001-bar.patch

* the example with a commit-msg hook that uses git interpret-trailers

BTW using interpret-trailers' --in-place option might be better than
handling files the way it's done in both these examples.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Non-interactively rewording commit messages
  2022-06-30 15:27 Non-interactively rewording commit messages Konstantin Ryabitsev
                   ` (3 preceding siblings ...)
  2022-07-01  4:01 ` Elijah Newren
@ 2022-07-01 13:37 ` Johannes Schindelin
  4 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2022-07-01 13:37 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: git

Hi Konstantin,

On Thu, 30 Jun 2022, Konstantin Ryabitsev wrote:

> What's the best approach to non-interactively rewrite specific commit
> messages? In this particular case, I am trying to automatically retrieve code
> review trailers sent to the mailing list and put them into corresponding
> commits.
>
> For example, I have a set of commits:
>
> abcabc: This commit does foo
> bcdbcd: This commit does bar
> cdecde: This commit does baz
>
> They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
> to the second commit. In a usual interactive rebase session this would be:
>
> pick abcabc
> reword bcdbcd
> pick cdecde
>
> When the edit screen comes up for the bcdbcd commit, the author would manually
> stick the new trailer into the commit message. However, I can automate all
> that away with b4 -- just need a sane strategy for non-interactively rewriting
> entire commit messages at arbitrary points in the recent history.
>
> Any pointers?

The quickest (in terms of script size) might be to craft an `amend!`
commit, something like this:

	git commit --allow-empty -m "$(printf 'amend! bcdbcd\n\n' &&
		git cat-file commit bcdbcd |
		sed -e '1,/^$/d' \
		 -e '{:1;${s/^/Reviewed-by: M A Intainer <maintainer@example.org>\n/;b};N;/\n$/b;b1}')"

and then running an "interactive" rebase with `:` as the editor:

	GIT_SEQUENCE_EDITOR=: GIT_EDITOR=: git rebase -i --autosquash HEAD~3

(The `sed` call is admittedly a bit horrible, it prepends the
`Reviewed-by:` footer to the last paragraph, if it needs to be _appended_,
it can be greatly simplified.)

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Non-interactively rewording commit messages
  2022-07-01  4:01 ` Elijah Newren
@ 2022-07-01 18:18   ` Konstantin Ryabitsev
  0 siblings, 0 replies; 11+ messages in thread
From: Konstantin Ryabitsev @ 2022-07-01 18:18 UTC (permalink / raw)
  To: Elijah Newren; +Cc: Git Mailing List

On Thu, Jun 30, 2022 at 09:01:33PM -0700, Elijah Newren wrote:
> One possibility would be to tweak
> https://github.com/newren/git-filter-repo/blob/main/contrib/filter-repo-demos/signed-off-by,
> modifying the line setting the 'trailer' variable to make it be a
> Reviewed-by rather than a Signed-off-by.  You could tweak the script
> to also make other automated commit message changes unrelated to any
> trailers, if you wanted.

Oh, this is neat, I was unaware of git-filter-repo. It looks like exactly what
I need for my purposes -- maybe I can just use it as a subproject. Thanks for
the suggestion!

-K

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-07-01 18:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 15:27 Non-interactively rewording commit messages Konstantin Ryabitsev
2022-06-30 17:32 ` Carlo Marcelo Arenas Belón
2022-06-30 17:34 ` Christian Couder
2022-06-30 17:54   ` Konstantin Ryabitsev
2022-06-30 18:10     ` Ævar Arnfjörð Bjarmason
2022-06-30 21:35   ` Junio C Hamano
2022-07-01 11:10     ` Christian Couder
2022-06-30 21:17 ` brian m. carlson
2022-07-01  4:01 ` Elijah Newren
2022-07-01 18:18   ` Konstantin Ryabitsev
2022-07-01 13:37 ` Johannes Schindelin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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).