Skip to contentSkip to conversation

sequencer: beautify subject of reverts of reverts

PATCH Superseded Oswald Buddenhagen 8 participants 53 messages Apr 28, 2023 – Sep 11, 2023 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sequencer: beautify subject of reverts of reverts

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.

Cc Junio C Hamano <[email protected]>
Cc Kristoffer Haugsbakk <[email protected]>

---
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
Documentation/git-revert.txt +6 -0
index d2e10d3dce..e8fa513607 100644
@@ -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>...::
sequencer.c +14 -0
index 3be23d7ca2..61e466470e 100644
@@ -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)) {
+				/*
+				 * 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);
t/t3515-revert-subjects.sh new file +32 -0
new file mode 100755
index 0000000000..ea4319fd15
@@ -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
Signature · 1 line
2.40.0.152.g15d061e6df
#1 lore raw
Quoted 16 lines · Oswald Buddenhagen

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.

---

Documentation/git-revert.txt +0 -0
index d2e10d3dce..e8fa513607 100644

Documentation/git-revert.txt both will discard uncommitted changes in your working directory. · line 36

Quoted 6 lines
Documentation/git-revert.txt +3 -0
@@ -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>"'.

Clearly written.

Documentation/git-revert.txt both will discard uncommitted changes in your working directory. · line 38

Quoted 2 lines
Documentation/git-revert.txt +2 -0
+These can of course be modified in the editor when the reason for
+reverting is described.

Not just the title but the entire message can be edited and that is by design. Having to modify what this new mechanism does when existing users do not like the new behaviour will annoy them, and this sentence will not be a good enough excuse to ask them forgiveness for breaking their established practice, either.

So, I am not sure if there is a point to have this sentence here.

Quoted 14 lines
sequencer.c +2 -0
index 3be23d7ca2..61e466470e 100644
@@ -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;

sequencer.c static int do_pick_commit(struct repository *r, · line 2245

Quoted 10 lines
sequencer.c +7 -0
 		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)) {
+				/*
+				 * 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.
+				 */

Good comment but in an overwide paragraph.

t/t3515-revert-subjects.sh

Quoted 15 lines
sequencer.c +5 -0
+				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);
t/t3515-revert-subjects.sh new file +0 -0
new file mode 100755
index 0000000000..ea4319fd15

It is a bit unexpectd that we need an entire new file to test this. It is doubly bad that the title of the file is only about the subject of revert commits and does not allow other things to be added later. Are we planning to have a lot more creativity in how automatically generated subject of revert commits would read?

If there isn't a good enough test coverage for the "git revert" command already, then having a new file to test "git revert" would be an excellent idea, adding one here is a very welcome addition, and it is perfectly fine to start such a new test with only these new tests that protects the new "Revert Revert to Reapply" feature.

But if there is a test file already for "git revert" that covers other behaviour of the command, "create two new commits, i.e. revert and revert of revert, and then try reverting them and see what their subject says" ought to be a simple addition or two to such an existing test file. Doesn't t3501 seem a better home for them? The last handful of tests there are about how the auto-generated log is phrased, and would form a good group with this new feature, wouldn't it?

t/t3515-revert-subjects.sh line 11

Quoted 12 lines
t/t3515-revert-subjects.sh new file +11 -0
@@ -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 &&

Style. See Documentation/CodingGuidelines and look for "For shell scripts specifically".

Quoted 11 lines
t/t3515-revert-subjects.sh new file +11 -0
+    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
+'

t/t3515-revert-subjects.sh line 32

Quoted 10 lines
t/t3515-revert-subjects.sh new file +10 -0
+
+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

Thanks.

#2 lore raw
Quoted 16 lines · Junio C Hamano

Documentation/git-revert.txt both will discard uncommitted changes in your working directory. · line 36

Quoted 3 lines · Oswald Buddenhagen
Documentation/git-revert.txt +3 -0
+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>"'.

Clearly written.

Documentation/git-revert.txt both will discard uncommitted changes in your working directory. · line 38

Quoted 2 lines
Documentation/git-revert.txt +2 -0
+These can of course be modified in the editor when the reason for
+reverting is described.

Not just the title but the entire message can be edited and that is by design. Having to modify what this new mechanism does when existing users do not like the new behaviour will annoy them, and this sentence will not be a good enough excuse to ask them forgiveness for breaking their established practice, either.

Quoted 2 lines

So, I am not sure if there is a point to have this sentence here.

well, it's the one sentence i copied verbatim from your proposal. :-D

but i don't get the argument anyway. i think the docu is pretty pointless except to emphasize that the generated subject is a default that should be edited when circumstances recommend it. in fact, i wouldn't mind writing just that, with a notice that the default attempts to be somewhat natural for repeated reverts.

Quoted 12 lines

sequencer.c static int do_pick_commit(struct repository *r, · line 2245

Quoted 9 lines
sequencer.c +7 -0
 			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)) {
+				/*
+				 * 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.
+				 */

Good comment but in an overwide paragraph.

there are several lines in the lower 90-ies in that file, one of them seen in the patch context. would 88 be fine? (too narrow flowed text looks silly, imo.)

Quoted 2 lines

Doesn't t3501 seem a better home for them?

looking closer at it, i guess it kind of does. the file's contents have clearly grown to fulfill the filename's broad promise, but nobody bothered to adjust the test description and make the setup title more specific. any takers?

-- ossi

#3 lore raw
Quoted 5 lines · Oswald Buddenhagen

but i don't get the argument anyway. i think the docu is pretty pointless except to emphasize that the generated subject is a default that should be edited when circumstances recommend it. in fact, i wouldn't mind writing just that, with a notice that the default attempts to be somewhat natural for repeated reverts.

I think it is very well known that the user gets the default message to be edited in the editor. I would understand if the instruction is "do not edit this line, because ...", but otherwise it is pretty up to the user to do whatever they like to the log message, no?

#4 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Oswald Buddenhagen

but i don't get the argument anyway. i think the docu is pretty pointless except to emphasize that the generated subject is a default that should be edited when circumstances recommend it. in fact, i wouldn't mind writing just that, with a notice that the default attempts to be somewhat natural for repeated reverts.

Quoted 5 lines

I think it is very well known that the user gets the default message to be edited in the editor. I would understand if the instruction is "do not edit this line, because ...", but otherwise it is pretty up to the user to do whatever they like to the log message, no?

well, yeah. but not everybody seems to get that editing the title specifically is actually an acceptable thing to do - see my earlier messages in the other sub-thread. so i'd go with something like:

Git attempts to make the subject of reverts of reverts somewhat natural, but will inevitably fail at greater depths. Editing these subjects is recommended.

also, this should be probably a note near the bottom, rather than being so close to the top. in fact, it's probably a good idea to add a DISCUSSION section with some basic guidelines, like git-commit has.

-- ossi

#5 lore raw
Quoted 2 lines · Oswald Buddenhagen

being so close to the top. in fact, it's probably a good idea to add a DISCUSSION section with some basic guidelines, like git-commit has.

;-) Sounds quite sensible.

Thanks.

#6 lore raw
In reply to Oswald Buddenhagen
Quoted 6 lines · Oswald Buddenhagen
Quoted 2 lines

Doesn't t3501 seem a better home for them?

looking closer at it, i guess it kind of does. the file's contents have clearly grown to fulfill the filename's broad promise, but nobody bothered to adjust the test description and make the setup title more specific. any takers?

Just dropping "with renames" from the test description would be fine, no? Existing tests in the early part of the script cover not just renames but unknown command line option, operating on a dirty working tree, etc. that are not specific to any renames.

One more thing I forgot was that your test scripts were indented by 4 spaces; please use tabs for indent to match existing ones when you add tests to an existing script.

Thanks.

#7 lore raw
In reply to Oswald Buddenhagen

Hi Oswald

Quoted 51 lines · Oswald Buddenhagen

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.

Cc Junio C Hamano <[email protected]>
Cc Kristoffer Haugsbakk <[email protected]>

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

Documentation/git-revert.txt +6 -0
index d2e10d3dce..e8fa513607 100644
@@ -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>...::
sequencer.c +1 -0
index 3be23d7ca2..61e466470e 100644
@@ -2227,13 +2227,27 @@ static int do_pick_commit(struct repository *r,
  	 */
 
  	if (command == TODO_REVERT) {
+		const char *orig_subject;

sequencer.c static int do_pick_commit(struct repository *r, · line 2240

Quoted 10 lines
sequencer.c +3 -0
+
  		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

Quoted 51 lines
sequencer.c +10 -0
+				/*
+				 * 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);
t/t3515-revert-subjects.sh new file +32 -0
new file mode 100755
index 0000000000..ea4319fd15
@@ -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
#8 lore raw
Quoted 6 lines · Phillip Wood

sequencer.c static int do_pick_commit(struct repository *r, · line 2240

Quoted 2 lines · Oswald Buddenhagen
sequencer.c +2 -0
+		} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject)) {
+			if (skip_prefix(orig_subject, "Revert \"", &orig_subject)) {

I think it is probably worth adding

Quoted 6 lines
	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 ...".

i can't follow you.

how is the concern not covered by the subsequent comment?

Quoted 5 lines

sequencer.c static int do_pick_commit(struct repository *r, · line 2245

Quoted 5 lines
sequencer.c +5 -0
+				/*
+				 * 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.
+				 */

regards,
ossi

#9 lore raw
Quoted 13 lines · Oswald Buddenhagen
Quoted 12 lines · Phillip Wood
Quoted 4 lines · Oswald Buddenhagen

+        } 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

Quoted 5 lines
Quoted 2 lines

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

i can't follow you.

how is the concern not covered by the subsequent comment?

That comment says that reverting a commit with a subject line

Revert "Revert some subject"

will result in the new commit having a subject

Revert "Reapply some subject"

I'm saying that reverting a commit with a subject line

Revert "Revert "Revert some subject""

should result in the new commit having the subject

Revert "Revert "Revert "Revert some subject"""

(i.e. at that point we stop trying to be clever) rather than

Revert "Reapply "Revert some subject""

which I think is what this patch produces.

Best Wishes

Phillip

Quoted 11 lines
Quoted 8 lines
Quoted 8 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.
+                 */

regards,
ossi

#10 lore raw
Quoted 4 lines · Phillip Wood

I'm saying that reverting a commit with a subject line

Revert "Revert "Revert some subject""

Quoted 8 lines

should result in the new commit having the subject

Revert "Revert "Revert "Revert some subject"""

(i.e. at that point we stop trying to be clever) rather than

Revert "Reapply "Revert some subject""

right.
how about filing that under GIGO and extending the comment?
i mean, when you actually run into this situation, you should be re-thinking your life choices rather than stressing about git producing a somewhat suboptimal commit message template ...

regards,
ossi

#11 lore raw
Quoted 9 lines · Oswald Buddenhagen
Quoted 8 lines · Phillip Wood

I'm saying that reverting a commit with a subject line

    Revert "Revert "Revert some subject""

should result in the new commit having the subject

    Revert "Revert "Revert "Revert some subject"""

Quoted 7 lines
Quoted 4 lines

(i.e. at that point we stop trying to be clever) rather than

    Revert "Reapply "Revert some subject""

right.
how about filing that under GIGO and extending the comment?
i mean, when you actually run into this situation, you should be re-thinking your life choices rather than stressing about git producing a somewhat suboptimal commit message template ...

Given that it is simple to handle this case and Junio is expecting a re-roll of this topic[1] then I think it would be worth just adding those three lines.

Best Wishes

Phillip

[1] https://lore.kernel.org/git/[email protected]/

Quoted 2 lines

regards,
ossi

#12 lore raw
Quoted 6 lines · Phillip Wood
Quoted 6 lines
Quoted 4 lines

(i.e. at that point we stop trying to be clever) rather than

    Revert "Reapply "Revert some subject""

right.

Quoted 8 lines
Quoted 4 lines

how about filing that under GIGO and extending the comment? i mean, when you actually run into this situation, you should be re-thinking your life choices rather than stressing about git producing a somewhat suboptimal commit message template ...

Given that it is simple to handle this case and Junio is expecting a re-roll of this topic[1] then I think it would be worth just adding those three lines.

Phillip, your first message with these three lines were a bit dense to understand (in other words, to me, it did not immediately "click" how these lines contribute to avoiding the revert-reapply-revert sequence that is awkward).

But after reading the exchange bewteen you two [*], your suggestion makes quite a lot of sense to me. It is better for a code to behave in a dumb but explainable way, than to attempting and failing to act too clever for its own worth.

Oswald, I do not think GIGO is really an excuse in this case, when the only value of the topic is to make the behaviour less awkward by creating something better than a repeated revert-revert sequence, revert-reapply-revert is worse, as it is markedly harder to guess what it really means for a reversion of revert-revert-revert than "revert" repeated four times. If anything, it is the cleverness of "lets call revert of revert a reapply" code without Phillip's suggestion that creates a garbage output, no?

Thanks.

[Footnote]

* Oswald, please refrain from using Mail-Followup-To; I wanted to deliver the contents of this message specifically to you and Phillip, but Phillip's MUA followed your Mail-Followup-To and lost your address, which made me look it up and add it myself.

Please refer to these first before saying "I use it because..." if you are going to respond:

https://lore.kernel.org/git/[email protected]/
https://lore.kernel.org/git/[email protected]/

#13 lore raw
Quoted 3 lines · Junio C Hamano

It is better for a code to behave
in a dumb but explainable way, than to attempting and failing to act too clever for its own worth.

I completely agree.

Quoted 6 lines

Oswald, I do not think GIGO is really an excuse in this case, when the only value of the topic is to make the behaviour less awkward by creating something better than a repeated revert-revert sequence, revert-reapply-revert is worse, as it is markedly harder to guess what it really means for a reversion of revert-revert-revert than "revert" repeated four times.

How about introducing a suffix (+ or -) after the word "Revert" to indicate the application/inclusion (+) or removal (-) of a commit? Example:

- "foo: bar baz quux"
- Revert "foo: bar baz quux"
- Revert(+) Revert(-) "foo: bar baz quux"
- Revert(-) Revert(+) Revert(-) "foo: bar baz quux"
- Revert(+) Revert(-) Revert(+) Revert(-) "foo: bar baz quux"

I think the above increases readability. I chose to keep the same style as the status quo for the first revert, because the "(-)" suffix alone without a neighboring "(+)", as in

Revert(-) "foo: bar baz quux"

might confuse users. This style would also do away with the multiple quoting levels that make the current multi-revert subject lines look messy at the end. Example:

Revert "Revert "Revert "Revert some subject"""
^
This part is starting to become noisy.

(Sorry for jumping into this thread so late, but the mention of this topic on the recent "What's cooking" message [1] (that this topic would be discarded) got me interested.)

[1] https://lore.kernel.org/git/[email protected]/T/#mf4edccc7bbc6365a03eaf106121694a27559d275

#14 lore raw
Quoted 3 lines · Linus Arver

How about introducing a suffix (+ or -) after the word "Revert" to indicate the application/inclusion (+) or removal (-) of a commit?

i think that falls squarely into the "too nerdy" category, like the Revert^n proposal does.

Quoted 4 lines

(Sorry for jumping into this thread so late, but the mention of this topic on the recent "What's cooking" message [1] (that this topic would be discarded) got me interested.)

i actually have finally updated my patches, but then found a problem in my script i'm using for submitting them, and want to fix that first for dogfooding purposes. shouldn't be long.

regards

#15 lore raw
Quoted 6 lines · Oswald Buddenhagen
Quoted 3 lines · Linus Arver

How about introducing a suffix (+ or -) after the word "Revert" to indicate the application/inclusion (+) or removal (-) of a commit?

i think that falls squarely into the "too nerdy" category, like the Revert^n proposal does.

True, but instead of dismissing it (or ^n) as "too nerdy", let's compare it with what we are trying to achieve and see why we feel it is not desirable. I think we are trying to find a good balance between aesthetics and usefulness. The former should take lower precedence, as it would be more subjective between the two.

The usefulness of the message comes from its information content. What do we want to read out of these messages? I think we want a title that immediately lets us know three things:

(1) What the original patch was about.
(2) What the final state is.
(3) How involved was the road to get to the final state has been.

As to (1), we are not proposing to lose what comes "Revert", so this information is not lost under any proposal we have seen so far in the discussion.

As to (2), with the current "Revert" -> "Revert Revert" -> "Revert Revert Revert" -> ..., you have to count, which is cumbersome and does not give you an immediate access to that information. With "Revert^n", you'd see if n is even or odd to determine, which is much better than the status quo, but it takes practice to interpret. With "Revert" -> "Reapply" -> "Revert Reapply" -> "Reapply Reapply" -> ..., the first word would give you the final state immediately.

We want to know (3), because between a change whose revert was reverted and a change that hasn't been involved in any revert, there may be no difference in the end result, the former is likely to be trickier and merits more careful inspection than the latter. With "Revert^n", we read how large the number n is to find the information. With the current "the Revert repeated number of times" or your "a pair of frontmost Reverts become one Reapply", the length of the Revert/Reapply prefix conveys this information, but this is associated with the cost of pushing the original title further to the right and hard to read/find. Note that, while the number of times revert-reapply sequence took place is a useful piece of information, the exact number may not be all that important.

And from the above discussion, I wonder if the following would be a good place to stop:

 - The first revert is as before:         Revert "original title"
 - A revert of a revert becomes:          Reapply "original title"
 - A revert of a reapply becomes:         Revert Reapply "original title"
 - A revert of "Revert Reapply" becomes:  Reapply Reapply "original title"

- A revert of "Reapply Reapply" becomes: Revert Reapply "original title"

In other words, we accept the fact that wedo not need exact number of times reversions were done, and use that to simplify the output to make sure we will not spend more than two words in the front of the title. That would help to keep the original title visible, while still allowing us to distinguish the ones that was reverted up to four times (and "Revert Reapply" and "Reapply Reapply" only tell us "final state is to (discard|accept) the original but it took us _many_ times", without saying exactly how many).

#16 lore raw
Quoted 9 lines · Junio C Hamano

And from the above discussion, I wonder if the following would be a good place to stop:

- The first revert is as before:         Revert "original title"
- A revert of a revert becomes:          Reapply "original title"
- A revert of a reapply becomes:         Revert Reapply "original title"
- A revert of "Revert Reapply" becomes:  Reapply Reapply "original title"

- A revert of "Reapply Reapply" becomes: Revert Reapply "original title"

Quoted 9 lines

In other words, we accept the fact that we do not need exact number of times reversions were done, and use that to simplify the output to make sure we will not spend more than two words in the front of the title. That would help to keep the original title visible, while still allowing us to distinguish the ones that was reverted up to four times (and "Revert Reapply" and "Reapply Reapply" only tell us "final state is to (discard|accept) the original but it took us _many_ times", without saying exactly how many).

i would not bother automating it, because it falls into the "you should get creative when that happens" category (which is codified in the manual by my reworked patches).

also, the "no more than two words" is sort of arbitrary - one can make a pretty convincing argument for just one word as well.

finally, just dropping that info would typically result in multiple (non-trivial) commits with the same summary, which i don't really like. leaving the uglier long variant (and the user hopefully amending it) avoids it.

i think i'll steal some of the text i didn't quote for the commit message, though. ^^

regards

#17 lore raw
Quoted 2 lines · Oswald Buddenhagen

also, the "no more than two words" is sort of arbitrary - one can make a pretty convincing argument for just one word as well.

I doubt it. If you squash "revert revert revert" into "revert", it means "revert" no longer means "singly reverted", so you destroy the goal (3) completely. Using two at least lets you differentiate "ended up rejecting after reverted multiple times" and "reverted just once".

Quoted 4 lines

finally, just dropping that info would typically result in multiple (non-trivial) commits with the same summary, which i don't really like. leaving the uglier long variant (and the user hopefully amending it) avoids it.

Actually, I am fine with your

Quoted 3 lines

... it falls into the "you
should get creative when that happens" category (which is codified in the manual by my reworked patches).

and leave this whole discussion behind it.

If we were doing something, we should make sure what we are doing is reasonable, and moving away from evaluation criteria like "beautify" and "too nerdy" and steping back to see what we are trying to achieve was an attempt to refocus the discussion. From that point of view, allowing arbitrary number of "Reapply" repeated, optionally prefixed by a single "Revert", does not sound like it is much better compared to the current one---is it worth this much time to discuss, only to halve the length of long runs of "Revert"?

#18 lore raw
Quoted 6 lines · Junio C Hamano

From that point
of view, allowing arbitrary number of "Reapply" repeated, optionally prefixed by a single "Revert", does not sound like it is much better compared to the current one---is it worth this much time to discuss, only to halve the length of long runs of "Revert"?

yes, for two reasons:
- the single "reapply" case is actually common; it's usually done after a previously missed pre-requisite was applied.
- the fact that it's "beautified" _at all_ sends a signal (see previous mails). it doesn't have to be particularly sophisticated for that.

regards

#19 lore raw
In reply to Junio C Hamano
Quoted 11 lines · Junio C Hamano

The usefulness of the message comes from its information content. What do we want to read out of these messages? I think we want a title that immediately lets us know three things:

(1) What the original patch was about.
(2) What the final state is.
(3) How involved was the road to get to the final state has been.

As to (1), we are not proposing to lose what comes "Revert", so this information is not lost under any proposal we have seen so far in the discussion.

Agreed.

Quoted 5 lines

As to (2), with the current "Revert" -> "Revert Revert" -> "Revert Revert Revert" -> ..., you have to count, which is cumbersome and does not give you an immediate access to that information. With "Revert^n", you'd see if n is even or odd to determine, which is much better than the status quo

I actually think "Revert^n" is much worse than what we have, mainly because the "^n" syntax is already used in other subcommands (e.g., rebase). It may well be that we already have overloaded syntax elsewhere, but we should avoid overloading where possible.

Quoted 3 lines

, but it takes practice to interpret.
With "Revert" -> "Reapply" -> "Revert Reapply" -> "Reapply Reapply" -> ..., the first word would give you the final state immediately.

I agree. But to take the idea further, maybe "Reapply Reapply" should be shortened to just

Reapply* "original title"

and likewise any ultimate _removal_ of the commit (no matter the exact pairwise count of the word "Revert") should be shortened to

Revert* "original title"

? The trailing asterisk in each case would indicate that this reapplication was not the first reapplication. We could then put in the commit message body text something like

--8<---------------cut here--------------------------------->8---
*NOTE: This is not the first time we've reverted XXX.
--8<---------------cut here----------------^---------^------>8---

                                           |         |
                                           |         Commit SHA.
                                           |

Could be "reapplied" if "Reapply*" is the title prefix.

to help stress point (3) that you described in your list above.

Quoted 4 lines

We want to know (3), because between a change whose revert was reverted and a change that hasn't been involved in any revert, there may be no difference in the end result, the former is likely to be trickier and merits more careful inspection than the latter.

Agreed.

Quoted 7 lines

With
"Revert^n", we read how large the number n is to find the information. With the current "the Revert repeated number of times" or your "a pair of frontmost Reverts become one Reapply", the length of the Revert/Reapply prefix conveys this information, but this is associated with the cost of pushing the original title further to the right and hard to read/find.

I agree that trying to keep the title short is very important. I didn't think too deeply about this point previously, but I think it is equally important as the other points you've enumerated above.

Quoted 3 lines

Note that, while the number of
times revert-reapply sequence took place is a useful piece of information, the exact number may not be all that important.

Agreed. For this reason I would prefer just using a single asterisk (as in my example) after the first occurrence of the revert/reapplication.

Quoted 9 lines

And from the above discussion, I wonder if the following would be a good place to stop:

 - The first revert is as before:         Revert "original title"
 - A revert of a revert becomes:          Reapply "original title"
 - A revert of a reapply becomes:         Revert Reapply "original title"
 - A revert of "Revert Reapply" becomes:  Reapply Reapply "original title"

- A revert of "Reapply Reapply" becomes: Revert Reapply "original title"

Quoted 8 lines

In other words, we accept the fact that wedo not need exact number of times reversions were done, and use that to simplify the output to make sure we will not spend more than two words in the front of the title. That would help to keep the original title visible, while still allowing us to distinguish the ones that was reverted up to four times (and "Revert Reapply" and "Reapply Reapply" only tell us "final state is to (discard|accept) the original but it took us _many_ times", without saying exactly how many).

I very much like your idea of just "stopping the recursion" early on. The only difference is that I would prefer to drop the second "Reapply" word in your examples and replace them with an asterisk (this makes them the same as in my example).

I think having this second word "Reapply" would make the title potentially hurt readability, especially because the first word is really the only one users should be looking at anyway to figure out the final state. Another reason for dropping it is because a well-written commit message title should have a single verb near the beginning, but your style would break this convention.

If you don't like the "asterisk" idea, another form might be

  - A revert of a reapply becomes:         Revert reapplication of "original title"
  - A revert of the above becomes:         Reapply revert of "original title"
  - A revert of the above becomes:         Revert reapplication of "original title"
  - A revert of the above becomes:         Reapply revert of "original title"

and so forth.

#20 lore raw

PATCH v3 1/2 sequencer: beautify subject of reverts of reverts

In reply to Oswald Buddenhagen

Instead of generating a silly-looking Revert "Revert "foo"", make it a more humane Reapply "foo".

This is done for two reasons:
- To cover the actually common case of just a double revert.
- To encourage people to rewrite summaries of recursive reverts by setting an example (a subsequent commit will also do this explicitly in the documentation).

To achieve these goals, the mechanism does not need to be particularly sophisticated. Therefore, more complicated alternatives which would "compress more efficiently" have not been implemented.

---
v3:
- capitulate at first sight of a pre-existing recursive reversion, as handling the edge cases is a bottomless pit
- reworked commit message again
- moved test into existing file
- generalized docu change and factored it out

v2:
- add discussion to commit message
- add paragraph to docu
- add test
- use skip_prefix() instead of starts_with()
- catch pre-existing double reverts

Cc Junio C Hamano <[email protected]>
Cc Kristoffer Haugsbakk <[email protected]>
Cc Phillip Wood <[email protected]>
---
 sequencer.c                   | 11 +++++++++++
 t/t3501-revert-cherry-pick.sh | 25 +++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
sequencer.c +11 -0
index cc9821ece2..12ec158922 100644
@@ -2249,13 +2249,24 @@ 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) &&
+			   /*
+			    * We don't touch pre-existing repeated reverts, because
+			    * theoretically these can be nested arbitrarily deeply,
+			    * thus requiring excessive complexity to deal with.
+			    */
+			   !starts_with(orig_subject, "Revert \"")) {
+			strbuf_addstr(&msgbuf, "Reapply \"");
+			strbuf_addstr(&msgbuf, orig_subject);
 		} else {
 			strbuf_addstr(&msgbuf, "Revert \"");
 			strbuf_addstr(&msgbuf, msg.subject);
t/t3501-revert-cherry-pick.sh +25 -0
index e2ef619323..7011e3a421 100755
@@ -176,6 +176,31 @@ test_expect_success 'advice from failed revert' '
 	test_cmp expected actual
 '
 
+test_expect_success 'title of 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 'title of legacy double revert' '
+	test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
+	git revert --no-edit HEAD &&
+	echo "Revert \"Revert \"Revert \"B\"\"\"" >expect &&
+	git log -1 --pretty=%s >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'identification of reverted commit (default)' '
 	test_commit to-ident &&
 	test_when_finished "git reset --hard to-ident" &&
Signature · 1 line
2.40.0.152.g15d061e6df
#21 lore raw

PATCH v3 2/2 doc: revert: add discussion

The section is inspired by git-commit.txt.

---

Cc Junio C Hamano <[email protected]>

---

while thinking about what to write, i came up with an idea for another
improvement: with (implicit) --edit, the template message would end up being:

This reverts commit <sha1>,
because <PUT REASON HERE>.

---
 Documentation/git-revert.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/git-revert.txt +10 -0
index d2e10d3dce..2b52dc89a8 100644
@@ -142,6 +142,16 @@ EXAMPLES
 	changes. The revert only modifies the working tree and the
 	index.
 
+DISCUSSION
+----------
+
+While git creates a basic commit message automatically, you really
+should not leave it at that. In particular, it is _strongly_
+recommended to explain why the original commit is being reverted.
+Repeatedly reverting reversions yields increasingly unwieldy
+commit subjects; latest when you arrive at 'Reapply "Reapply
+"<original subject>""' you should get creative.
+
 CONFIGURATION
 -------------
 
Signature · 1 line
2.40.0.152.g15d061e6df
#22 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

Quoted 6 lines · Oswald Buddenhagen

while thinking about what to write, i came up with an idea for another
improvement: with (implicit) --edit, the template message would end up being:

This reverts commit <sha1>,
because <PUT REASON HERE>.

This sounds great to me.

Nit: the "doc: revert: add discussion" subject line should probably be more like "revert doc: suggest adding the 'why' behind reverts".

Quoted 11 lines
---
 Documentation/git-revert.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/git-revert.txt +0 -0
index d2e10d3dce..2b52dc89a8 100644
@@ -142,6 +142,16 @@ EXAMPLES
 	changes. The revert only modifies the working tree and the
 	index.

Documentation/git-revert.txt EXAMPLES · line 153

Quoted 10 lines
Documentation/git-revert.txt +9 -0
 
+DISCUSSION
+----------
+
+While git creates a basic commit message automatically, you really
+should not leave it at that. In particular, it is _strongly_
+recommended to explain why the original commit is being reverted.
+Repeatedly reverting reversions yields increasingly unwieldy
+commit subjects; latest when you arrive at 'Reapply "Reapply
+"<original subject>""' you should get creative.

The word "latest" here sounds odd. Ditto for "get creative". How about the following rewording?

While git creates a basic commit message automatically, it is _strongly_ recommended to explain why the original commit is being reverted. In addition, repeatedly reverting the same commit will result in increasingly unwieldy subject lines, for example 'Reapply "Reapply "<original subject>""'. Please consider rewording such subject lines to reflect the reason why the original commit is being reapplied again.

#23 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

Quoted 6 lines · Linus Arver

How about
the following rewording?

While git creates a basic commit message automatically, it is _strongly_ recommended to explain why the original commit is being reverted. In addition, repeatedly reverting the same commit will

Hmph, "repeatedly reverting the same commit" sounds wrong because strictly speaking there is only 1 "same commit" (the original commit). Perhaps

In addition, repeatedly reverting the same progression of reverts will

or even

In addition, repeatedly reverting the same revert chain will

is better here?

#24 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

Quoted 3 lines · Linus Arver

Nit: the "doc: revert: add discussion" subject line should probably be more like "revert doc: suggest adding the 'why' behind reverts".

this is counter to the prevalent "big endian" prefix style, and is in this case really easy to misread.
i also intentionally kept the subject generic, because the content covers two matters (the reasoning and the subjects, which is also the reason why this is a separate patch to start with).

Quoted 13 lines

Documentation/git-revert.txt EXAMPLES · line 153

Quoted 9 lines · Oswald Buddenhagen
Documentation/git-revert.txt +9 -0
+DISCUSSION
+----------
+
+While git creates a basic commit message automatically, you really
+should not leave it at that. In particular, it is _strongly_
+recommended to explain why the original commit is being reverted.
+Repeatedly reverting reversions yields increasingly unwieldy
+commit subjects; latest when you arrive at 'Reapply "Reapply
+"<original subject>""' you should get creative.

The word "latest" here sounds odd. Ditto for "get creative".

yeah, i suppose. i wasn't sure how formal i should make it - things aren't consistent to start with.

Quoted 9 lines

How about the following rewording?

While git creates a basic commit message automatically, it is _strongly_ recommended to explain why the original commit is being reverted. In addition, repeatedly reverting the same commit will result in increasingly unwieldy subject lines,

for example 'Reapply "Reapply "<original subject>""'.

you turned it from a suggested threshold into an example. at this point it appears superfluous to me.

Quoted 4 lines

Please consider rewording such
subject lines to reflect the reason why the original commit is being reapplied again.

the reasoning most likely wouldn't fit into the subject.
also, the original request to explain the reasoning applies transitively, so i don't think it's really necessary to point it out explicitly.

Quoted 4 lines · Linus Arver

Hmph, "repeatedly reverting the same commit" sounds wrong because strictly speaking there is only 1 "same commit" (the original commit). Perhaps

Quoted 8 lines

In addition, repeatedly reverting the same progression of reverts will

or even

In addition, repeatedly reverting the same revert chain will

is better here?

we used "recursive reverts" elsewhere. but i'm not sure whether that's sufficiently intuitive and formally correct.

anyway, what's wrong with my original proposal?

so in summary, how about:

While git creates a basic commit message automatically, it is _strongly_ recommended to explain why the original commit is being reverted. In addition, repeatedly reverting reversions will result in increasingly unwieldy subject lines. Please consider rewording these into something shorter and more unique.

regards

#25 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

Quoted 9 lines · Oswald Buddenhagen
Quoted 3 lines · Linus Arver

Nit: the "doc: revert: add discussion" subject line should probably be more like "revert doc: suggest adding the 'why' behind reverts".

this is counter to the prevalent "big endian" prefix style, and is in this case really easy to misread.
i also intentionally kept the subject generic, because the content covers two matters (the reasoning and the subjects, which is also the reason why this is a separate patch to start with).

I think the phrase "add discussion" in "doc: revert: add discussion" doesn't add much value, because your patch's diff is very easy to read (in that it adds a new DISCUSSION section). I just wanted to replace it with something more useful that gives more information than just repeat (somewhat redundantly) what is obvious by looking at the patch.

I also learned recently that there should just be one colon ":" in the subject, which is why I suggested "revert doc" as the prefix instead of "doc: revert: ...".

Quoted 13 lines
Quoted 13 lines

Documentation/git-revert.txt EXAMPLES · line 153

Quoted 9 lines · Oswald Buddenhagen
Documentation/git-revert.txt +9 -0
+DISCUSSION
+----------
+
+While git creates a basic commit message automatically, you really
+should not leave it at that. In particular, it is _strongly_
+recommended to explain why the original commit is being reverted.
+Repeatedly reverting reversions yields increasingly unwieldy
+commit subjects; latest when you arrive at 'Reapply "Reapply
+"<original subject>""' you should get creative.

The word "latest" here sounds odd. Ditto for "get creative".

Quoted 2 lines

yeah, i suppose. i wasn't sure how formal i should make it - things aren't consistent to start with.

For our discussion I will define "formal" style as the writing style used in traditional reference texts, for example dictionaries and encyclopedias.

For manpages, I think we should stick to formal style as much as possible. The main concern I have is for readers of our manpages where English may not be their first language. Although I understood what you meant by the phrase "get creative", others may not understand so readily. If there are places in our manpages where we do not use formal style, I think we should fix them.

For other types of documentation like tutorials, I think the style doesn't have to be as formal, (in fact it should be as informal as possible) because a tutorial should be enjoyable to read from beginning to end. This is unlike a manpage where most of the time the user reads specific (sub)sections to get the exact, precise information they need (just like looking up a word in a dictionary).

Quoted 9 lines
Quoted 9 lines

How about the following rewording?

While git creates a basic commit message automatically, it is _strongly_ recommended to explain why the original commit is being reverted. In addition, repeatedly reverting the same commit will result in increasingly unwieldy subject lines,

for example 'Reapply "Reapply "<original subject>""'.

Quoted 8 lines

you turned it from a suggested threshold into an example. at this point it appears superfluous to me.

Quoted 4 lines

Please consider rewording such
subject lines to reflect the reason why the original commit is being reapplied again.

the reasoning most likely wouldn't fit into the subject.

Hence the language "to _reflect_ the reason", because the "reason" should belong in the commit message body text.

Quoted 3 lines

also, the original request to explain the reasoning applies transitively, so i don't think it's really necessary to point it out explicitly.

It may be that a user will think only giving the revert reason in the body text is enough, while leaving the subject line as is. I wanted to break this line of thinking by providing additional instructions.

Quoted 7 lines · Linus Arver
Quoted 6 lines

Hmph, "repeatedly reverting the same commit" sounds wrong because strictly speaking there is only 1 "same commit" (the original commit). Perhaps

In addition, repeatedly reverting the same progression of reverts will

Quoted 8 lines
Quoted 6 lines

or even

In addition, repeatedly reverting the same revert chain will

is better here?

we used "recursive reverts" elsewhere. but i'm not sure whether that's sufficiently intuitive and formally correct.

Agreed. We might have to just define the correct phrasing ourselves in "man gitglossary". Surprisingly I see that the term "revert" (which can be both a verb _and_ a noun) is not defined there.

Quoted 9 lines

[...]

so in summary, how about:

While git creates a basic commit message automatically, it is _strongly_ recommended to explain why the original commit is being reverted. In addition, repeatedly reverting reversions will result in increasingly unwieldy subject lines. Please consider rewording these into something shorter and more unique.

This is definitely better. But others in this thread have already commented that my version looks good (after seeing your version also, presumably).

#26 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

Quoted 12 lines · Linus Arver
Quoted 5 lines · Oswald Buddenhagen
Quoted 3 lines · Linus Arver

Nit: the "doc: revert: add discussion" subject line should probably be more like "revert doc: suggest adding the 'why' behind reverts".

this is counter to the prevalent "big endian" prefix style, and is in this case really easy to misread.

I also learned recently that there should just be one colon ":" in the subject, which is why I suggested "revert doc" as the prefix instead of "doc: revert: ...".

in what context was this preference expressed?
because here, it's rather counter-productive: most commands are verbs for obvious reasons, so using that style sets the reader up for misparsing the subject on first try. this could be avoided by quoting the command, but that looks noisy in the subject. so rather, i'd follow another precedent, 'git-revert.txt: ', which is unambiguous.

Quoted 10 lines
Quoted 1 line

i also intentionally kept the subject generic, because the content covers two matters (the reasoning and the subjects, which is also the reason why this is a separate patch to start with).

I think the phrase "add discussion" in "doc: revert: add discussion" doesn't add much value, because your patch's diff is very easy to read (in that it adds a new DISCUSSION section). I just wanted to replace it with something more useful that gives more information than

just repeat
(somewhat redundantly) what is obvious by looking at the patch.

but ... that's exactly what a subject is supposed to do!

Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

Please consider rewording such
subject lines to reflect the reason why the original commit is being reapplied again.

the reasoning most likely wouldn't fit into the subject.

Hence the language "to _reflect_ the reason", because the "reason" should belong in the commit message body text.

i don't think that's how most people would actually read this. and i still don't see how that instruction could be meaningfully followed.

Quoted 6 lines
Quoted 1 line

also, the original request to explain the reasoning applies transitively, so i don't think it's really necessary to point it out explicitly.

It may be that a user will think only giving the revert reason in the body text is enough, while leaving the subject line as is. I wanted to break this line of thinking by providing additional instructions.

yes, that's the whole intention of this patch. but i don't see how making it more convoluted than my proposal helps in any way.

Quoted 4 lines

This is definitely better. But others in this thread have already commented that my version looks good (after seeing your version also, presumably).

well, i'm also an "others" when it comes to your proposal, and i find it confusing.

regards

#27 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

First, I apologize for the long delay in my response. I only work on Git 20% of the time, and that 20% can become 0% due to factors outside my control.

Quoted 7 lines · Oswald Buddenhagen
Quoted 6 lines · Linus Arver
Quoted 4 lines · Oswald Buddenhagen
Quoted 3 lines · Linus Arver

Nit: the "doc: revert: add discussion" subject line should probably be more like "revert doc: suggest adding the 'why' behind reverts".

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

this is counter to the prevalent "big endian" prefix style, and is in this case really easy to misread.

I also learned recently that there should just be one colon ":" in the subject, which is why I suggested "revert doc" as the prefix instead of "doc: revert: ...".

in what context was this preference expressed?

IIRC, it was from a conversation off-list with the folks at Google's Git-core team.

Quoted 3 lines

because here, it's rather counter-productive: most commands are verbs for obvious reasons, so using that style sets the reader up for misparsing the subject on first try.

I think the convention for commit titles is

    <prefix>: <action>

so the phrase "revert doc: add discussion", where the <prefix> is "revert doc" does not parse any worse than "doc: revert: add discussion". That is, the <prefix> is never confused with the <action> (they are separated by the colon).

Quoted 4 lines

this could be avoided by quoting
the command, but that looks noisy in the subject.
so rather, i'd follow another precedent, 'git-revert.txt: ', which is unambiguous.

SGTM.

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

i also intentionally kept the subject generic, because the content covers two matters (the reasoning and the subjects, which is also the reason why this is a separate patch to start with).

I think the phrase "add discussion" in "doc: revert: add discussion" doesn't add much value, because your patch's diff is very easy to read (in that it adds a new DISCUSSION section). I just wanted to replace it with something more useful that gives more information than

Quoted 4 lines
Quoted 3 lines

just repeat
(somewhat redundantly) what is obvious by looking at the patch.

but ... that's exactly what a subject is supposed to do!

I think the rule of thumb is to explain the goodness of what a commit brings, rather than focus on what is literally happening. This is because the former is more valuable. So instead of

"git-revert.txt: add discussion"

you could say

"git-revert.txt: advise against default commit message"

and now you don't have to look at the patch to see (roughly) what kind of discussion was added.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Please consider rewording such
subject lines to reflect the reason why the original commit is being reapplied again.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

the reasoning most likely wouldn't fit into the subject.

Hence the language "to _reflect_ the reason", because the "reason" should belong in the commit message body text.

i don't think that's how most people would actually read this. and i still don't see how that instruction could be meaningfully followed.

OK, you may be right.

Quoted 10 lines
Quoted 8 lines
Quoted 3 lines

also, the original request to explain the reasoning applies transitively, so i don't think it's really necessary to point it out explicitly.

It may be that a user will think only giving the revert reason in the body text is enough, while leaving the subject line as is. I wanted to break this line of thinking by providing additional instructions.

yes, that's the whole intention of this patch. but i don't see how making it more convoluted than my proposal helps in any way.

Well, even if a review makes something more convoluted, it may generate discussion and drive consensus on the better way(s) of doing something. I see value in that course of events.

Of course you are free to reject review comments that you truly believe are inferior to the approach you've already taken.

But overall, when I see a reviewer's comment on this mailing list, I assume they are trying to make my patch better. Similarly when I reviewed your patch my intent was to provide actionable feedback to try to make it better. I'm sorry if I did not come across that way.

Quoted 6 lines
Quoted 4 lines

This is definitely better. But others in this thread have already commented that my version looks good (after seeing your version also, presumably).

well, i'm also an "others" when it comes to your proposal, and i find it confusing.

I think you did the right thing by responding to my comments, and pointing to things you found confusing.

#28 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

In reply to Linus Arver
Quoted 11 lines · Linus Arver
Quoted 6 lines · Linus Arver

How about
the following rewording?

While git creates a basic commit message automatically, it is _strongly_ recommended to explain why the original commit is being reverted. In addition, repeatedly reverting the same commit will

Hmph, "repeatedly reverting the same commit" sounds wrong because strictly speaking there is only 1 "same commit" (the original commit).

While it isn't strictly accurate I think that wording is easy enough to understand. I think it is hard to find a more accurate wording that isn't too verbose or cumbersome.

Best Wishes

Phillip

Quoted 9 lines

Perhaps

In addition, repeatedly reverting the same progression of reverts will

or even

In addition, repeatedly reverting the same revert chain will

is better here?

#29 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

Quoted 6 lines · Phillip Wood
Quoted 5 lines · Linus Arver
Quoted 3 lines · Linus Arver

How about
the following rewording?

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

While git creates a basic commit message automatically, it is _strongly_ recommended to explain why the original commit is being reverted. In addition, repeatedly reverting the same commit will

Hmph, "repeatedly reverting the same commit" sounds wrong because strictly speaking there is only 1 "same commit" (the original commit).

While it isn't strictly accurate I think that wording is easy enough to understand.

yes, but why would that be _better_ than saying "repeatedly reverting reversions" like i did?

regards

#30 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

Quoted 10 lines · Oswald Buddenhagen
Quoted 7 lines · Phillip Wood
Quoted 2 lines · Linus Arver

Hmph, "repeatedly reverting the same commit" sounds wrong because strictly speaking there is only 1 "same commit" (the original commit).

While it isn't strictly accurate I think that wording is easy enough to understand.

yes, but why would that be _better_ than saying "repeatedly reverting reversions" like i did?

To me at least, "repeatedly reverting reversions" sounds more like a riddle, compared to "repeatedly reverting the same commit", whose intent sounds fairly obvious. An explicit mention of "commit", which is a more familiar noun to folks than "reversion", does contribute to it, I suspect.

That would be how I explain why one is _better_ over the other, but of course these things are subjective, so I'd rather see us not asking such questions too often: which is more familiar, "commit" vs "reversion", especially to new folks who are starting to use "git" and reading the manual page for "git revert"?

#31 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Oswald Buddenhagen
Quoted 7 lines · Phillip Wood
Quoted 2 lines · Linus Arver

Hmph, "repeatedly reverting the same commit" sounds wrong because strictly speaking there is only 1 "same commit" (the original commit).

While it isn't strictly accurate I think that wording is easy enough to understand.

Quoted 7 lines
Quoted 2 lines

yes, but why would that be _better_ than saying "repeatedly reverting reversions" like i did?

To me at least, "repeatedly reverting reversions" sounds more like a riddle, compared to "repeatedly reverting the same commit", whose intent sounds fairly obvious.

a more natural way for git users to say it would be "reverting reverts", which i think everyone in the target audience would understand, but it seems linguistically questionable to me. native speakers may want to opine ...

Quoted 4 lines

An explicit mention of "commit", which
is a more familiar noun to folks than "reversion", does contribute to it, I suspect.

yes, but "commit" may be misunderstood, as linus pointed out in his reply to himself. phillip dismissed the concern, but i don't think ambiguity is a good idea in the authoritative documentation.

unfortunately, linus' proposed alternatives seem even more like "riddles" to me than what i am proposing.

regards

#32 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

In reply to Linus Arver
Quoted 14 lines · Linus Arver

Documentation/git-revert.txt EXAMPLES · line 153

Quoted 9 lines · Oswald Buddenhagen
Documentation/git-revert.txt +9 -0
+DISCUSSION
+----------
+
+While git creates a basic commit message automatically, you really
+should not leave it at that. In particular, it is _strongly_
+recommended to explain why the original commit is being reverted.
+Repeatedly reverting reversions yields increasingly unwieldy
+commit subjects; latest when you arrive at 'Reapply "Reapply
+"<original subject>""' you should get creative.

The word "latest" here sounds odd. Ditto for "get creative". How about the following rewording?

Quoted 7 lines

While git creates a basic commit message automatically, it is _strongly_ recommended to explain why the original commit is being reverted. In addition, repeatedly reverting the same commit will result in increasingly unwieldy subject lines, for example 'Reapply "Reapply "<original subject>""'. Please consider rewording such subject lines to reflect the reason why the original commit is being reapplied again.

That's a good suggestion, I think having the example will help readers understand the issue being described.

Best Wishes

Phillip

#33 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

Quoted 22 lines · Phillip Wood
Quoted 12 lines · Linus Arver

Documentation/git-revert.txt EXAMPLES · line 153

Quoted 9 lines · Oswald Buddenhagen
Documentation/git-revert.txt +9 -0
+DISCUSSION
+----------
+
+While git creates a basic commit message automatically, you really
+should not leave it at that. In particular, it is _strongly_
+recommended to explain why the original commit is being reverted.
+Repeatedly reverting reversions yields increasingly unwieldy
+commit subjects; latest when you arrive at 'Reapply "Reapply
+"<original subject>""' you should get creative.

The word "latest" here sounds odd. Ditto for "get creative". How about

Quoted 8 lines

the following rewording?
While git creates a basic commit message automatically, it is _strongly_ recommended to explain why the original commit is being reverted. In addition, repeatedly reverting the same commit will result in increasingly unwieldy subject lines, for example 'Reapply "Reapply "<original subject>""'. Please consider rewording such subject lines to reflect the reason why the original commit is being reapplied again.

Quoted 2 lines

That's a good suggestion, I think having the example will help readers understand the issue being described.

Sounds very good.

#34 lore raw

Re: [PATCH v3 2/2] doc: revert: add discussion

In reply to Linus Arver
Quoted 10 lines · Linus Arver
Quoted 6 lines · Oswald Buddenhagen

while thinking about what to write, i came up with an idea for another
improvement: with (implicit) --edit, the template message would end up being:

This reverts commit <sha1>,
because <PUT REASON HERE>.

This sounds great to me.

Oh, absolutely. I rarely do a revert myself (other than reverting a premature merge out of 'next'), but giving a better instruction in the commit log editor buffer as template is a very good idea.

Quoted 2 lines

Nit: the "doc: revert: add discussion" subject line should probably be more like "revert doc: suggest adding the 'why' behind reverts".

Good suggestion.

Quoted 10 lines

The word "latest" here sounds odd. Ditto for "get creative". How about the following rewording?

While git creates a basic commit message automatically, it is _strongly_ recommended to explain why the original commit is being reverted. In addition, repeatedly reverting the same commit will result in increasingly unwieldy subject lines, for example 'Reapply "Reapply "<original subject>""'. Please consider rewording such subject lines to reflect the reason why the original commit is being reapplied again.

Sounds better, but let me read the remaining discussion first ;-)

Thanks.

#35 lore raw

Re* [PATCH v3 2/2] doc: revert: add discussion

Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Linus Arver
Quoted 4 lines · Oswald Buddenhagen

while thinking about what to write, i came up with an idea for another
improvement: with (implicit) --edit, the template message would end up being:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

This reverts commit <sha1>,
because <PUT REASON HERE>.

This sounds great to me.

Oh, absolutely. I rarely do a revert myself (other than reverting a premature merge out of 'next'), but giving a better instruction in the commit log editor buffer as template is a very good idea.

It might be just the matter of doing something like the attached patch on top of Oswald's, reusing the existing code to instruct the user to describe the reversion.

------- >8 ------------- >8 ------------- >8 ------------- >8 -------
Subject: [PATCH 3/2] revert: force explaining overly complex revert chain

Once we revert reverts of revert and reach "Reapply "Reapply "..."", it becomes too unweirdly to read a reversion of such a comit.

We instruct the user to explain why the reversion is done in their own words when using the revert.reference mode, and the instruction applies equally for such an overly complex revert chain. The rationale for such a sequence of events should be recorded to help future developers.

Building on top of the recent Oswald's work to turn "revert revert" into "reapply", let's turn the reference mode automatically on in such a case.

---

* I left the reference to the second parent to honor the command line option and configuration variable even when this new mechanism kicks in and this is very much deliberate. As a commit that is a revert (or reapply) should be single parent (because a revert of a merge is a single parent commit), the choice does not make any difference in practice.

 sequencer.c                   | 16 +++++++++++-----
 t/t3501-revert-cherry-pick.sh | 11 ++++++++++-
 2 files changed, 21 insertions(+), 6 deletions(-)
sequencer.c +11 -5
index 7dc13fdcca..43bb558518 100644
@@ -2130,10 +2130,10 @@ static int should_edit(struct replay_opts *opts) {
 	return opts->edit;
 }
 
-static void refer_to_commit(struct replay_opts *opts,
+static void refer_to_commit(int use_reference,
 			    struct strbuf *msgbuf, struct commit *commit)
 {
-	if (opts->commit_use_reference) {
+	if (use_reference) {
 		struct pretty_print_context ctx = {
 			.abbrev = DEFAULT_ABBREV,
 			.date_mode.type = DATE_SHORT,
@@ -2250,12 +2250,18 @@ static int do_pick_commit(struct repository *r,
 
 	if (command == TODO_REVERT) {
 		const char *orig_subject;
+		int use_reference = opts->commit_use_reference;
 
 		base = commit;
 		base_label = msg.label;
 		next = parent;
 		next_label = msg.parent_label;
-		if (opts->commit_use_reference) {
+
+		if (starts_with(msg.subject, "Reapply \"Reapply \""))
+			/* fifth time is too many - force reference format*/
+			use_reference = 1;
+
+		if (use_reference) {
 			strbuf_addstr(&msgbuf,
 				"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
 		} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
@@ -2273,11 +2279,11 @@ static int do_pick_commit(struct repository *r,
 			strbuf_addstr(&msgbuf, "\"");
 		}
 		strbuf_addstr(&msgbuf, "\n\nThis reverts commit ");
-		refer_to_commit(opts, &msgbuf, commit);
+		refer_to_commit(use_reference, &msgbuf, commit);
 
 		if (commit->parents && commit->parents->next) {
 			strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
-			refer_to_commit(opts, &msgbuf, parent);
+			refer_to_commit(opts->commit_use_reference, &msgbuf, parent);
 		}
 		strbuf_addstr(&msgbuf, ".\n");
 	} else {
t/t3501-revert-cherry-pick.sh +10 -1
index 7011e3a421..7a8715d3f4 100755
@@ -190,7 +190,16 @@ test_expect_success 'title of fresh reverts' '
 	git revert --no-edit HEAD &&
 	echo "Revert \"Reapply \"B\"\"" >expect &&
 	git log -1 --pretty=%s >actual &&
-	test_cmp expect actual
+	test_cmp expect actual &&
+	git revert --no-edit HEAD &&
+	echo "Reapply \"Reapply \"B\"\"" >expect &&
+	git log -1 --pretty=%s >actual &&
+	test_cmp expect actual &&
+
+	# Give the stronger instruction for unusually complex case
+	git revert --no-edit HEAD &&
+	git log -1 --pretty=%s >actual &&
+	grep -F -e "# *** SAY WHY WE ARE REVERTING" actual
 '
 
 test_expect_success 'title of legacy double revert' '
#36 lore raw

Re: Re* [PATCH v3 2/2] doc: revert: add discussion

sequencer.c static int do_pick_commit(struct repository *r, · line 2262

Quoted 4 lines · Junio C Hamano
sequencer.c +4 -0
+
+		if (starts_with(msg.subject, "Reapply \"Reapply \""))
+			/* fifth time is too many - force reference format*/
+			use_reference = 1;

Come to think of it, as the documentation patch in the series cited double reapply as too unwieldy, we probably should stop before producing such commit. We can update "Reapply \"Reapply" above to "Revert \"Reapply" and then "fifth" -> "fourth". The test update below must also be adjusted, if we want to take that route.

#37 lore raw

RE: Re* [PATCH v3 2/2] doc: revert: add discussion

Quoted 8 lines · Junio C Hamano

sequencer.c static int do_pick_commit(struct repository *r, · line 2262

Quoted 4 lines · Junio C Hamano
sequencer.c +4 -0
+
+		if (starts_with(msg.subject, "Reapply \"Reapply \""))
+			/* fifth time is too many - force reference format*/
+			use_reference = 1;

Come to think of it, as the documentation patch in the series cited double

reapply as

Quoted 2 lines

too unwieldy, we probably should stop before producing such commit. We can update "Reapply \"Reapply" above to "Revert \"Reapply" and then "fifth" ->

"fourth".

Quoted 1 line

The test update below must also be adjusted, if we want to take that route.

May I suggest a potential quick solution. Perhaps we could leave this up to users by putting in an --amend or --reword option to cause a prompt for a comment for the reverted commit instead of trying to come up with a one-size-fits-all solution.

#38 lore raw

Re: Re* [PATCH v3 2/2] doc: revert: add discussion

In reply to Junio C Hamano
Quoted 4 lines · Junio C Hamano

Subject: [PATCH 3/2] revert: force explaining overly complex revert chain

Once we revert reverts of revert and reach "Reapply "Reapply "..."", it becomes too unweirdly to read a reversion of such a comit.

s/unweirdly/unwieldy/
s/comit/commit/

Quoted 11 lines

We instruct the user to explain why the reversion is done in their own words when using the revert.reference mode, and the instruction applies equally for such an overly complex revert chain. The rationale for such a sequence of events should be recorded to help future developers.

Building on top of the recent Oswald's work to turn "revert revert" into "reapply", let's turn the reference mode automatically on in such a case.

#39 lore raw

Re: Re* [PATCH v3 2/2] doc: revert: add discussion

In reply to Junio C Hamano
Quoted 15 lines · Junio C Hamano
Quoted 13 lines · Junio C Hamano
Quoted 10 lines · Linus Arver
Quoted 6 lines · Oswald Buddenhagen

while thinking about what to write, i came up with an idea for another
improvement: with (implicit) --edit, the template message would end up being:

This reverts commit <sha1>,
because <PUT REASON HERE>.

This sounds great to me.

Quoted 8 lines
Quoted 3 lines

Oh, absolutely. I rarely do a revert myself (other than reverting a premature merge out of 'next'), but giving a better instruction in the commit log editor buffer as template is a very good idea.

It might be just the matter of doing something like the attached patch on top of Oswald's, reusing the existing code to instruct the user to describe the reversion.

hmm, this seems to be going down a too narrow road - my idea was to make this fully orthogonal to reverting reverts in particular (note that i attached it to the generic "discussion" patch rather than the "reverts of reverts" one). i didn't think about the integration with existing options yet.

regards

#40 lore raw

Re: Re* [PATCH v3 2/2] doc: revert: add discussion

Quoted 3 lines · Oswald Buddenhagen

make this fully orthogonal to reverting reverts in particular (note that i attached it to the generic "discussion" patch rather than the "reverts of reverts" one).

I viewed that as a patch to add "discussion on how to explain revert" (not necessarily "revert of revert", but how "revert" in general should be explained).

Quoted 1 line

i didn't think about the integration with existing options yet.

Now I did ;-).

The discussion of what the right way to present and justify a revert was done before, and I think revert.reference and the "--reference" option came out of it. It aims the same "do not just describe the fact what was reverted, but you should explain why" spirit. While what I showed in my illustration patch was not meant as "integration with existing options", it is inevitable that reuse of existing code that was written earlier for improving the workflow in the same spirit may get involved.

Perhaps we should also tweak the commit log template to give a gentle knudge to the user to use revert.reference and then enhance the help text we give.

Instead of

Revert "doc: revert: add discussion"

This reverts commit 7139d1298993b0148ad429cd7cb4824223b7f420.

you may see something along the lines of ...

# Consider retitling to reflect WHY you are reverting. # You may also want to set revert.reference configuration to # help encuraging a better title for revert commits. Revert "doc: revert: add discussion"

This reverts commit 7139d1298993b0148ad429cd7cb4824223b7f420 because <REASON OF REVERSION HERE>

I ran out of time budget for today to think about a topic that is not releant to the current release, so I'd stop here.

THanks.

#41 lore raw
In reply to Oswald Buddenhagen

Hi Oswald

Quoted 9 lines · Oswald Buddenhagen

Instead of generating a silly-looking Revert "Revert "foo"", make it a more humane Reapply "foo".

This is done for two reasons:
- To cover the actually common case of just a double revert.
- To encourage people to rewrite summaries of recursive reverts by setting an example (a subsequent commit will also do this explicitly in the documentation).

Quoted 3 lines

To achieve these goals, the mechanism does not need to be particularly sophisticated. Therefore, more complicated alternatives which would "compress more efficiently" have not been implemented.

This all looks good to me, it seems quite sensible just to bail out if we see an existing recursive reversion. I'm not suggesting you change these tests but for future reference we now have a test_commit_message() function which was merged a few days ago to simplify tests like these.

Thanks for working on it

Phillip

Quoted 90 lines

---
v3:
- capitulate at first sight of a pre-existing recursive reversion, as handling the edge cases is a bottomless pit
- reworked commit message again
- moved test into existing file
- generalized docu change and factored it out

v2:
- add discussion to commit message
- add paragraph to docu
- add test
- use skip_prefix() instead of starts_with()
- catch pre-existing double reverts

Cc Junio C Hamano <[email protected]>
Cc Kristoffer Haugsbakk <[email protected]>
Cc Phillip Wood <[email protected]>
---
  sequencer.c                   | 11 +++++++++++
  t/t3501-revert-cherry-pick.sh | 25 +++++++++++++++++++++++++
  2 files changed, 36 insertions(+)
sequencer.c +11 -0
index cc9821ece2..12ec158922 100644
@@ -2249,13 +2249,24 @@ 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) &&
+			   /*
+			    * We don't touch pre-existing repeated reverts, because
+			    * theoretically these can be nested arbitrarily deeply,
+			    * thus requiring excessive complexity to deal with.
+			    */
+			   !starts_with(orig_subject, "Revert \"")) {
+			strbuf_addstr(&msgbuf, "Reapply \"");
+			strbuf_addstr(&msgbuf, orig_subject);
  		} else {
  			strbuf_addstr(&msgbuf, "Revert \"");
  			strbuf_addstr(&msgbuf, msg.subject);
t/t3501-revert-cherry-pick.sh +25 -0
index e2ef619323..7011e3a421 100755
@@ -176,6 +176,31 @@ test_expect_success 'advice from failed revert' '
  	test_cmp expected actual
  '
 
+test_expect_success 'title of 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 'title of legacy double revert' '
+	test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
+	git revert --no-edit HEAD &&
+	echo "Revert \"Revert \"Revert \"B\"\"\"" >expect &&
+	git log -1 --pretty=%s >actual &&
+	test_cmp expect actual
+'
+
  test_expect_success 'identification of reverted commit (default)' '
  	test_commit to-ident &&
  	test_when_finished "git reset --hard to-ident" &&
#42 lore raw
Quoted 15 lines · Phillip Wood

Hi Oswald

Quoted 11 lines · Oswald Buddenhagen

Instead of generating a silly-looking Revert "Revert "foo"", make it a more humane Reapply "foo".
This is done for two reasons:
- To cover the actually common case of just a double revert.
- To encourage people to rewrite summaries of recursive reverts by setting an example (a subsequent commit will also do this explicitly in the documentation).
To achieve these goals, the mechanism does not need to be particularly
sophisticated. Therefore, more complicated alternatives which would "compress more efficiently" have not been implemented.

Quoted 2 lines

This all looks good to me, it seems quite sensible just to bail out if we see an existing recursive reversion.

Yes, explicitly refraining from becoming overly cute is a good design decision.

Quoted 17 lines
Quoted 17 lines
sequencer.c +3 -0
index cc9821ece2..12ec158922 100644
@@ -2249,13 +2249,24 @@ 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) &&
Quoted 8 lines

sequencer.c static int do_pick_commit(struct repository *r, · line 2269

Quoted 8 lines
sequencer.c +8 -0
+			   /*
+			    * We don't touch pre-existing repeated reverts, because
+			    * theoretically these can be nested arbitrarily deeply,
+			    * thus requiring excessive complexity to deal with.
+			    */
+			   !starts_with(orig_subject, "Revert \"")) {
+			strbuf_addstr(&msgbuf, "Reapply \"");
+			strbuf_addstr(&msgbuf, orig_subject);

Being simple-and-stupid to deal only with the most common case, and documenting that it is deliberate that we do not deal with more complex cases in the in-code comment and in the log message, are very good in this case.

Quoted 15 lines
Quoted 15 lines
t/t3501-revert-cherry-pick.sh +7 -0
index e2ef619323..7011e3a421 100755
@@ -176,6 +176,31 @@ test_expect_success 'advice from failed revert' '
  	test_cmp expected actual
  '
  +test_expect_success 'title of 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 &&
Quoted 8 lines

t/t3501-revert-cherry-pick.sh test_expect_success 'advice from failed revert' ' · line 194

Quoted 8 lines
t/t3501-revert-cherry-pick.sh +8 -0
+	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
+'

Presumably the next time this gets reverted we will see a doubled reapply? Isn't that something we care about documenting as a part of this test? i.e. another four-line block after the above?

	git revert --no-edit HEAD &&
	echo "Reapply \"Reapply \"B\"\"" >expect &&
	git log -1 --pretty=%s >actual &&
	test_cmp expect actual
Quoted 7 lines

t/t3501-revert-cherry-pick.sh test_expect_success 'advice from failed revert' ' · line 202

Quoted 7 lines
t/t3501-revert-cherry-pick.sh +7 -0
+test_expect_success 'title of legacy double revert' '
+	test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
+	git revert --no-edit HEAD &&
+	echo "Revert \"Revert \"Revert \"B\"\"\"" >expect &&
+	git log -1 --pretty=%s >actual &&
+	test_cmp expect actual
+'

Good.

Quoted 3 lines
Quoted 3 lines
t/t3501-revert-cherry-pick.sh +0 -0
  test_expect_success 'identification of reverted commit (default)' '
  	test_commit to-ident &&
  	test_when_finished "git reset --hard to-ident" &&
#43 lore raw
Quoted 3 lines · Junio C Hamano

Presumably the next time this gets reverted we will see a doubled reapply?

yes

Quoted 3 lines

Isn't that something we care about documenting as a part of this test? i.e. another four-line block after the above?

the third case documents that it's the same as the first case, i.e., "nothing special". so at this point we have full coverage in all regards. going beyond that would be redundant, and we'd again get into the "uh, where do we stop?" situation.

regards

#44 lore raw

PATCH v4 1/2 sequencer: beautify subject of reverts of reverts

In reply to Oswald Buddenhagen

Instead of generating a silly-looking Revert "Revert "foo"", make it a more humane Reapply "foo".

This is done for two reasons:
- To cover the actually common case of just a double revert.
- To encourage people to rewrite summaries of recursive reverts by setting an example (a subsequent commit will also do this explicitly in the documentation).

To achieve these goals, the mechanism does not need to be particularly sophisticated. Therefore, more complicated alternatives which would "compress more efficiently" have not been implemented.

---
v3:
- capitulate at first sight of a pre-existing recursive reversion, as handling the edge cases is a bottomless pit
- reworked commit message again
- moved test into existing file
- generalized docu change and factored it out

v2:
- add discussion to commit message
- add paragraph to docu
- add test
- use skip_prefix() instead of starts_with()
- catch pre-existing double reverts

Cc Junio C Hamano <[email protected]>
Cc Kristoffer Haugsbakk <[email protected]>
Cc Phillip Wood <[email protected]>
---
 sequencer.c                   | 11 +++++++++++
 t/t3501-revert-cherry-pick.sh | 25 +++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
sequencer.c +11 -0
index cc9821ece2..12ec158922 100644
@@ -2249,13 +2249,24 @@ 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) &&
+			   /*
+			    * We don't touch pre-existing repeated reverts, because
+			    * theoretically these can be nested arbitrarily deeply,
+			    * thus requiring excessive complexity to deal with.
+			    */
+			   !starts_with(orig_subject, "Revert \"")) {
+			strbuf_addstr(&msgbuf, "Reapply \"");
+			strbuf_addstr(&msgbuf, orig_subject);
 		} else {
 			strbuf_addstr(&msgbuf, "Revert \"");
 			strbuf_addstr(&msgbuf, msg.subject);
t/t3501-revert-cherry-pick.sh +25 -0
index e2ef619323..7011e3a421 100755
@@ -176,6 +176,31 @@ test_expect_success 'advice from failed revert' '
 	test_cmp expected actual
 '
 
+test_expect_success 'title of 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 'title of legacy double revert' '
+	test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
+	git revert --no-edit HEAD &&
+	echo "Revert \"Revert \"Revert \"B\"\"\"" >expect &&
+	git log -1 --pretty=%s >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'identification of reverted commit (default)' '
 	test_commit to-ident &&
 	test_when_finished "git reset --hard to-ident" &&
Signature · 1 line
2.40.0.152.g15d061e6df
#45 lore raw

PATCH v4 2/2 git-revert.txt: add discussion

The section is inspired by git-commit.txt.

---
v4:
- adjusted summary prefix & payload wording

Cc Junio C Hamano <[email protected]>
Cc Linus Arver <[email protected]>
Cc Phillip Wood <[email protected]>
Cc Kristoffer Haugsbakk <[email protected]>
---
 Documentation/git-revert.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/git-revert.txt +10 -0
index d2e10d3dce..cbe0208834 100644
@@ -142,6 +142,16 @@ EXAMPLES
 	changes. The revert only modifies the working tree and the
 	index.
 
+DISCUSSION
+----------
+
+While git creates a basic commit message automatically, it is
+_strongly_ recommended to explain why the original commit is being
+reverted.
+In addition, repeatedly reverting reverts will result in increasingly
+unwieldy subject lines, for example 'Reapply "Reapply "<original subject>""'.
+Please consider rewording these to be shorter and more unique.
+
 CONFIGURATION
 -------------
 
Signature · 1 line
2.40.0.152.g15d061e6df
#47 lore raw
In reply to Oswald Buddenhagen
Quoted 3 lines · Oswald Buddenhagen

To achieve these goals, the mechanism does not need to be particularly sophisticated. Therefore, more complicated alternatives which would "compress more efficiently" have not been implemented.

This version is looking good. The main functionality is well-reasoned and straightforwardly implemented. One minor suggestion that you could consider squashing in is some test clean-up like so:

--- 8< ---

t/t3501-revert-cherry-pick.sh +10 -12
index 7011e3a421..4dee71d6d5 100755
@@ -176,29 +176,27 @@ test_expect_success 'advice from failed revert' '
 	test_cmp expected actual
 '
 
+test_expect_commit_msg () {
+	echo "$@" >expect &&
+	git log -1 --pretty=%s >actual &&
+	test_cmp expect actual
+}
+
 test_expect_success 'title of 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 &&
+	test_expect_commit_msg "Revert \"B\"" &&
 	git revert --no-edit HEAD &&
-	echo "Reapply \"B\"" >expect &&
-	git log -1 --pretty=%s >actual &&
-	test_cmp expect actual &&
+	test_expect_commit_msg "Reapply \"B\"" &&
 	git revert --no-edit HEAD &&
-	echo "Revert \"Reapply \"B\"\"" >expect &&
-	git log -1 --pretty=%s >actual &&
-	test_cmp expect actual
+	test_expect_commit_msg "Revert \"Reapply \"B\"\""
 '
 
 test_expect_success 'title of legacy double revert' '
 	test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
 	git revert --no-edit HEAD &&
-	echo "Revert \"Revert \"Revert \"B\"\"\"" >expect &&
-	git log -1 --pretty=%s >actual &&
-	test_cmp expect actual
+	test_expect_commit_msg "Revert \"Revert \"Revert \"B\"\"\""
 '
 
 test_expect_success 'identification of reverted commit (default)' '

--- >8 ---

To my eyes, it makes checking the subject of our revert commit against an expected value more readable by factoring out the echo, git log, test_cmp pattern.

Thanks,
Taylor

#48 lore raw
Quoted 51 lines · Taylor Blau

This version is looking good. The main functionality is well-reasoned and straightforwardly implemented. One minor suggestion that you could consider squashing in is some test clean-up like so:

--- 8< ---

t/t3501-revert-cherry-pick.sh +10 -13
index 7011e3a421..4dee71d6d5 100755
@@ -176,29 +176,27 @@ test_expect_success 'advice from failed revert' '
 	test_cmp expected actual
 '
 
+test_expect_commit_msg () {
+	echo "$@" >expect &&
+	git log -1 --pretty=%s >actual &&
+	test_cmp expect actual
+}
+
 test_expect_success 'title of 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 &&
+	test_expect_commit_msg "Revert \"B\"" &&
 	git revert --no-edit HEAD &&
-	echo "Reapply \"B\"" >expect &&
-	git log -1 --pretty=%s >actual &&
-	test_cmp expect actual &&
+	test_expect_commit_msg "Reapply \"B\"" &&
 	git revert --no-edit HEAD &&
-	echo "Revert \"Reapply \"B\"\"" >expect &&
-	git log -1 --pretty=%s >actual &&
-	test_cmp expect actual
+	test_expect_commit_msg "Revert \"Reapply \"B\"\""
 '
 
 test_expect_success 'title of legacy double revert' '
 	test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
 	git revert --no-edit HEAD &&
-	echo "Revert \"Revert \"Revert \"B\"\"\"" >expect &&
-	git log -1 --pretty=%s >actual &&
-	test_cmp expect actual
+	test_expect_commit_msg "Revert \"Revert \"Revert \"B\"\"\""
 '
 
 test_expect_success 'identification of reverted commit (default)' '
--- >8 ---
Quoted 3 lines

To my eyes, it makes checking the subject of our revert commit against an expected value more readable by factoring out the echo, git log, test_cmp pattern.

Yeah it does make the test more concise and what is expected stand out more clearly. Good suggestion.

#49 lore raw
Quoted 10 lines · Junio C Hamano
Quoted 4 lines · Taylor Blau

This version is looking good. The main functionality is well-reasoned and straightforwardly implemented. One minor suggestion that you could consider squashing in is some test clean-up like so:

Yeah it does make the test more concise and what is expected stand out more clearly. Good suggestion.

agreed. do you want to squash it on your end, or should i reroll?

regards

#50 lore raw

PATCH v5 1/1 sequencer: beautify subject of reverts of reverts

In reply to Junio C Hamano

Instead of generating a silly-looking Revert "Revert "foo"", make it a more humane Reapply "foo".

This is done for two reasons:
- To cover the actually common case of just a double revert.
- To encourage people to rewrite summaries of recursive reverts by setting an example (a subsequent commit will also do this explicitly in the documentation).

To achieve these goals, the mechanism does not need to be particularly sophisticated. Therefore, more complicated alternatives which would "compress more efficiently" have not been implemented.

---
v4:
- factor out verification of subject as per taylor's patch, with minor modifications.
fwiw, it might make sense to put this into test-lib-functions.sh right after test_commit_message(), then named test_commit_subject(). not sure it would be worth it, given an equally generic implementation would be kinda over-engineered, and the discoverability is kinda poor.

v3:
- capitulate at first sight of a pre-existing recursive reversion, as handling the edge cases is a bottomless pit
- reworked commit message again
- moved test into existing file
- generalized docu change and factored it out

v2:
- add discussion to commit message
- add paragraph to docu
- add test
- use skip_prefix() instead of starts_with()
- catch pre-existing double reverts

Cc Junio C Hamano <[email protected]>
Cc Kristoffer Haugsbakk <[email protected]>
Cc Phillip Wood <[email protected]>
---
 sequencer.c                   | 11 +++++++++++
 t/t3501-revert-cherry-pick.sh | 23 +++++++++++++++++++++++
 2 files changed, 34 insertions(+)
sequencer.c +11 -0
index cc9821ece2..12ec158922 100644
@@ -2249,13 +2249,24 @@ 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) &&
+			   /*
+			    * We don't touch pre-existing repeated reverts, because
+			    * theoretically these can be nested arbitrarily deeply,
+			    * thus requiring excessive complexity to deal with.
+			    */
+			   !starts_with(orig_subject, "Revert \"")) {
+			strbuf_addstr(&msgbuf, "Reapply \"");
+			strbuf_addstr(&msgbuf, orig_subject);
 		} else {
 			strbuf_addstr(&msgbuf, "Revert \"");
 			strbuf_addstr(&msgbuf, msg.subject);
t/t3501-revert-cherry-pick.sh +23 -0
index e2ef619323..4158590322 100755
@@ -176,6 +176,29 @@ test_expect_success 'advice from failed revert' '
 	test_cmp expected actual
 '
 
+test_expect_subject () {
+	echo "$1" >expect &&
+	git log -1 --pretty=%s >actual &&
+	test_cmp expect actual
+}
+
+test_expect_success 'titles of fresh reverts' '
+	test_commit --no-tag A file1 &&
+	test_commit --no-tag B file1 &&
+	git revert --no-edit HEAD &&
+	test_expect_subject "Revert \"B\"" &&
+	git revert --no-edit HEAD &&
+	test_expect_subject "Reapply \"B\"" &&
+	git revert --no-edit HEAD &&
+	test_expect_subject "Revert \"Reapply \"B\"\""
+'
+
+test_expect_success 'title of legacy double revert' '
+	test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
+	git revert --no-edit HEAD &&
+	test_expect_subject "Revert \"Revert \"Revert \"B\"\"\""
+'
+
 test_expect_success 'identification of reverted commit (default)' '
 	test_commit to-ident &&
 	test_when_finished "git reset --hard to-ident" &&
Signature · 1 line
2.40.0.152.g15d061e6df
#51 lore raw
Quoted 4 lines · Oswald Buddenhagen

---
v4:
- factor out verification of subject as per taylor's patch, with minor modifications.

The change seems to make the test quite straight-forward to read.

Let's mark the topic for 'next'.

Thanks.

Quoted 34 lines
t/t3501-revert-cherry-pick.sh +23 -0
index e2ef619323..4158590322 100755
@@ -176,6 +176,29 @@ test_expect_success 'advice from failed revert' '
 	test_cmp expected actual
 '
 
+test_expect_subject () {
+	echo "$1" >expect &&
+	git log -1 --pretty=%s >actual &&
+	test_cmp expect actual
+}
+
+test_expect_success 'titles of fresh reverts' '
+	test_commit --no-tag A file1 &&
+	test_commit --no-tag B file1 &&
+	git revert --no-edit HEAD &&
+	test_expect_subject "Revert \"B\"" &&
+	git revert --no-edit HEAD &&
+	test_expect_subject "Reapply \"B\"" &&
+	git revert --no-edit HEAD &&
+	test_expect_subject "Revert \"Reapply \"B\"\""
+'
+
+test_expect_success 'title of legacy double revert' '
+	test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
+	git revert --no-edit HEAD &&
+	test_expect_subject "Revert \"Revert \"Revert \"B\"\"\""
+'
+
 test_expect_success 'identification of reverted commit (default)' '
 	test_commit to-ident &&
 	test_when_finished "git reset --hard to-ident" &&
#52 lore raw
In reply to Oswald Buddenhagen
Quoted 2 lines · Oswald Buddenhagen

Instead of generating a silly-looking Revert "Revert "foo"", make it a more humane Reapply "foo".

Congrats on a nice series. It's very “lean and mean”—focused, not excessive.

And I think I will remember the phrase “too nerdy” for a while. ;)

Maybe we will get this message template the next time we revert a merge.[1]

Quoted 8 lines

If you merge the updated side branch (with D at its tip), none of the changes made in A or B will be in the result, because they were reverted by W. That is what Alan saw.

[...]

In such a situation, you would want to first revert the previous revert, which would make the history look like this: ...

🔗 1: https://github.com/git/git/blob/master/Documentation/howto/revert-a-faulty-merge.txt

Cheers

Signature · 1 line
Kristoffer