git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] sequencer: beautify subject of reverts of reverts

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
May 17, 2023, 09:05 UTC
Message-ID
<3f5e4116-54e6-9753-f925-ed4a9f6e3518@gmail.com>
In-Reply-To
<20230428083528.1699221-1-oswald.buddenhagen@gmx.de>
Hi Oswald
On 28/04/2023 09:35, Oswald Buddenhagen wrote:
Show 61 quoted lines
> Instead of generating a silly-looking `Revert "Revert "foo""`, make it
> a more humane `Reapply "foo"`.
> 
> The alternative `Revert^2 "foo"`, etc. was considered, but it was deemed
> over-engineered and "too nerdy". Instead, people should get creative
> with the subjects when they recurse reverts that deeply. The proposed
> change encourages that by example and explicit recommendation.
> 
> Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
> Cc: Junio C Hamano <gitster@pobox.com>
> Cc: Kristoffer Haugsbakk <code@khaugsbakk.name>
> ---
> v2:
> - add discussion to commit message
> - add paragraph to docu
> - add test
> - use skip_prefix() instead of starts_with()
> - catch pre-existing double reverts
> ---
>   Documentation/git-revert.txt |  6 ++++++
>   sequencer.c                  | 14 ++++++++++++++
>   t/t3515-revert-subjects.sh   | 32 ++++++++++++++++++++++++++++++++
>   3 files changed, 52 insertions(+)
>   create mode 100755 t/t3515-revert-subjects.sh
> 
> diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt
> index d2e10d3dce..e8fa513607 100644
> --- a/Documentation/git-revert.txt
> +++ b/Documentation/git-revert.txt
> @@ -31,6 +31,12 @@ both will discard uncommitted changes in your working directory.
>   See "Reset, restore and revert" in linkgit:git[1] for the differences
>   between the three commands.
>   
> +The command generates the subject 'Revert "<title>"' for the resulting
> +commit, assuming the original commit's subject is '<title>'.  Reverting
> +such a reversion commit in turn yields the subject 'Reapply "<title>"'.
> +These can of course be modified in the editor when the reason for
> +reverting is described.
> +
>   OPTIONS
>   -------
>   <commit>...::
> diff --git a/sequencer.c b/sequencer.c
> index 3be23d7ca2..61e466470e 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -2227,13 +2227,27 @@ static int do_pick_commit(struct repository *r,
>   	 */
>   
>   	if (command == TODO_REVERT) {
> +		const char *orig_subject;
> +
>   		base = commit;
>   		base_label = msg.label;
>   		next = parent;
>   		next_label = msg.parent_label;
>   		if (opts->commit_use_reference) {
>   			strbuf_addstr(&msgbuf,
>   				"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
> +		} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject)) {
> +			if (skip_prefix(orig_subject, "Revert \"", &orig_subject)) {
I think it is probably worth adding
	if (starts_with(orig_subject, "Revert \""))
		strbuf_addstr(&msgbuf, "Revert \"");
	else

here to make sure that we don't end up with a subject starting "Revert \"Reapply \"Revert ...".

Best Wishes
Phillip
Show 51 quoted lines
> +				/*
> +				 * This prevents the generation of somewhat unintuitive (even if
> +				 * not incorrect) 'Reapply "Revert "' titles from legacy double
> +				 * reverts. Fixing up deeper recursions is left to the user.
> +				 */
> +				strbuf_addstr(&msgbuf, "Revert \"Reapply \"");
> +			} else {
> +				strbuf_addstr(&msgbuf, "Reapply \"");
> +			}
> +			strbuf_addstr(&msgbuf, orig_subject);
>   		} else {
>   			strbuf_addstr(&msgbuf, "Revert \"");
>   			strbuf_addstr(&msgbuf, msg.subject);
> diff --git a/t/t3515-revert-subjects.sh b/t/t3515-revert-subjects.sh
> new file mode 100755
> index 0000000000..ea4319fd15
> --- /dev/null
> +++ b/t/t3515-revert-subjects.sh
> @@ -0,0 +1,32 @@
> +#!/bin/sh
> +
> +test_description='git revert produces the expected subject'
> +
> +. ./test-lib.sh
> +
> +test_expect_success 'fresh reverts' '
> +    test_commit --no-tag A file1 &&
> +    test_commit --no-tag B file1 &&
> +    git revert --no-edit HEAD &&
> +    echo "Revert \"B\"" > expect &&
> +    git log -1 --pretty=%s > actual &&
> +    test_cmp expect actual &&
> +    git revert --no-edit HEAD &&
> +    echo "Reapply \"B\"" > expect &&
> +    git log -1 --pretty=%s > actual &&
> +    test_cmp expect actual &&
> +    git revert --no-edit HEAD &&
> +    echo "Revert \"Reapply \"B\"\"" > expect &&
> +    git log -1 --pretty=%s > actual &&
> +    test_cmp expect actual
> +'
> +
> +test_expect_success 'legacy double revert' '
> +    test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
> +    git revert --no-edit HEAD &&
> +    echo "Revert \"Reapply \"B\"\"" > expect &&
> +    git log -1 --pretty=%s > actual &&
> +    test_cmp expect actual
> +'
> +
> +test_done
Previous: Junio C HamanoNext: Oswald Buddenhagen
Message 8 of 53 in “sequencer: beautify subject of reverts of reverts”
  1. sequencer: beautify subject of reverts of revertsOswald Buddenhagen, Apr 28, 2023
  2. Junio C HamanoApr 28, 2023
  3. Oswald BuddenhagenApr 28, 2023
  4. Junio C HamanoMay 1, 2023
  5. Oswald BuddenhagenMay 1, 2023
  6. Junio C HamanoMay 1, 2023
  7. Junio C HamanoMay 5, 2023
  8. Phillip WoodMay 17, 2023
  9. Oswald BuddenhagenMay 17, 2023
  10. Phillip WoodMay 17, 2023
  11. Oswald BuddenhagenMay 17, 2023
  12. Phillip WoodMay 18, 2023
  13. Junio C HamanoMay 18, 2023
  14. Linus ArverJul 28, 2023
  15. Oswald BuddenhagenJul 28, 2023
  16. Junio C HamanoJul 28, 2023
  17. Oswald BuddenhagenJul 28, 2023
  18. Junio C HamanoJul 28, 2023
  19. Oswald BuddenhagenJul 28, 2023
  20. Linus ArverJul 28, 2023
  21. 1/2 sequencer: beautify subject of reverts of revertsOswald Buddenhagen, Aug 9, 2023
  22. 2/2 doc: revert: add discussionOswald Buddenhagen, Aug 9, 2023
  23. Linus ArverAug 10, 2023
  24. Linus ArverAug 10, 2023
  25. Oswald BuddenhagenAug 11, 2023
  26. Linus ArverAug 11, 2023
  27. Oswald BuddenhagenAug 12, 2023
  28. Linus ArverSep 7, 2023
  29. Phillip WoodAug 11, 2023
  30. Oswald BuddenhagenAug 12, 2023
  31. Junio C HamanoAug 13, 2023
  32. Oswald BuddenhagenAug 14, 2023
  33. Phillip WoodAug 11, 2023
  34. Junio C HamanoAug 11, 2023
  35. Junio C HamanoAug 11, 2023
  36. Re* [PATCH v3 2/2] doc: revert: add discussionJunio C Hamano, Aug 11, 2023
  37. Junio C HamanoAug 11, 2023
  38. rsbecker@nexbridge.comAug 11, 2023
  39. Eric SunshineAug 11, 2023
  40. Oswald BuddenhagenAug 11, 2023
  41. Junio C HamanoAug 11, 2023
  42. Phillip WoodAug 11, 2023
  43. Junio C HamanoAug 11, 2023
  44. Oswald BuddenhagenAug 11, 2023
  45. 1/2 sequencer: beautify subject of reverts of revertsOswald Buddenhagen, Aug 21, 2023
  46. 2/2 git-revert.txt: add discussionOswald Buddenhagen, Aug 21, 2023
  47. Junio C HamanoAug 21, 2023
  48. Taylor BlauAug 23, 2023
  49. Junio C HamanoAug 23, 2023
  50. Oswald BuddenhagenAug 24, 2023
  51. sequencer: beautify subject of reverts of revertsOswald Buddenhagen, Sep 2, 2023
  52. Junio C HamanoSep 2, 2023
  53. Kristoffer HaugsbakkSep 11, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.