sequencer: beautify subject of reverts of reverts
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. Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Oswald Buddenhagen committed
Sep 2, 2023 at 09:20 UTC
883cb1b8f86d437a9d664ec046fa66e5e24f4a19
2 files changed
+34
sequencer.c
+11
@@ -2249,6 +2249,8 @@ static int do_pick_commit(struct repository *r,
2249
*/
2250
2251
if (command == TODO_REVERT) {
2252
+ const char *orig_subject;
2253
+
2254
base = commit;
2255
base_label = msg.label;
2256
next = parent;
@@ -2256,6 +2258,15 @@ static int do_pick_commit(struct repository *r,
2258
if (opts->commit_use_reference) {
2259
strbuf_addstr(&msgbuf,
2260
"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
2261
+ } else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
2262
+ /*
2263
+ * We don't touch pre-existing repeated reverts, because
2264
+ * theoretically these can be nested arbitrarily deeply,
2265
+ * thus requiring excessive complexity to deal with.
2266
+ */
2267
+ !starts_with(orig_subject, "Revert \"")) {
2268
+ strbuf_addstr(&msgbuf, "Reapply \"");
2269
+ strbuf_addstr(&msgbuf, orig_subject);
2270
} else {
2271
strbuf_addstr(&msgbuf, "Revert \"");
2272
strbuf_addstr(&msgbuf, msg.subject);
t/t3501-revert-cherry-pick.sh
+23
@@ -176,6 +176,29 @@ test_expect_success 'advice from failed revert' '
176
test_cmp expected actual
177
'
178
179
+test_expect_subject () {
180
+ echo "$1" >expect &&
181
+ git log -1 --pretty=%s >actual &&
182
+ test_cmp expect actual
183
+}
184
+
185
+test_expect_success 'titles of fresh reverts' '
186
+ test_commit --no-tag A file1 &&
187
+ test_commit --no-tag B file1 &&
188
+ git revert --no-edit HEAD &&
189
+ test_expect_subject "Revert \"B\"" &&
190
+ git revert --no-edit HEAD &&
191
+ test_expect_subject "Reapply \"B\"" &&
192
+ git revert --no-edit HEAD &&
193
+ test_expect_subject "Revert \"Reapply \"B\"\""
194
+'
195
+
196
+test_expect_success 'title of legacy double revert' '
197
+ test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
198
+ git revert --no-edit HEAD &&
199
+ test_expect_subject "Revert \"Revert \"Revert \"B\"\"\""
200
+'
201
+
202
test_expect_success 'identification of reverted commit (default)' '
203
test_commit to-ident &&
204
test_when_finished "git reset --hard to-ident" &&