]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format-patch: use --notes behavior for format.notes
authorDenton Liu <liu.denton@gmail.com>
Mon, 9 Dec 2019 13:10:46 +0000 (05:10 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Dec 2019 21:37:20 +0000 (13:37 -0800)
When we had multiple `format.notes` config values where we had `<ref1>`,
`false`, `<ref2>` (in that order), then we would print out the notes for
both `<ref1>` and `<ref2>`. This doesn't make sense, however, since we
parse the config in a top-down manner and a `false` should be able to
override previous configurations, just like how `--no-notes` will
override previous `--notes`.

Duplicate the logic that handles the `--[no-]notes[=]` option to
`format.notes` for consistency. As a result, when parsing the config
from top to bottom, `format.notes = true` will behave like `--notes`,
`format.notes = <ref>` will behave like `--notes=<ref>` and
`format.notes = false` will behave like `--no-notes`.

This change isn't strictly backwards compatible but since it is an edge
case where a sane user would not mix notes refs with `false` and this
feature is relatively new (released only in v2.23.0), this change should
be harmless.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c
t/t4014-format-patch.sh

index 622d6a6cb16acf4353170cb60fe6648e3ce2f33f..1f0405f72be8d01bdb3f5d8c54ff455ecb4b1a89 100644 (file)
@@ -867,19 +867,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
                return 0;
        }
        if (!strcmp(var, "format.notes")) {
-               struct strbuf buf = STRBUF_INIT;
                int b = git_parse_maybe_bool(value);
-               if (!b)
-                       return 0;
-               rev->show_notes = 1;
-               if (b < 0) {
-                       strbuf_addstr(&buf, value);
-                       expand_notes_ref(&buf);
-                       string_list_append(&rev->notes_opt.extra_notes_refs,
-                                       strbuf_detach(&buf, NULL));
-               } else {
-                       rev->notes_opt.use_default_notes = 1;
-               }
+               rev->show_notes = set_display_notes(&rev->notes_opt, b, b < 0 ? value : NULL);
                return 0;
        }
 
index 4d5719fe2c1fec661f33bd927dd02c6769f68e45..5c40ea439761b38f4b2eae852e6e311038c6a590 100755 (executable)
@@ -808,6 +808,38 @@ test_expect_success 'format-patch with multiple notes refs' '
        ! grep "this is note 2" out
 '
 
+test_expect_success 'format-patch with multiple notes refs in config' '
+       test_when_finished "test_unconfig format.notes" &&
+
+       git notes --ref note1 add -m "this is note 1" HEAD &&
+       test_when_finished git notes --ref note1 remove HEAD &&
+       git notes --ref note2 add -m "this is note 2" HEAD &&
+       test_when_finished git notes --ref note2 remove HEAD &&
+
+       git config format.notes note1 &&
+       git format-patch -1 --stdout >out &&
+       grep "this is note 1" out &&
+       ! grep "this is note 2" out &&
+       git config format.notes note2 &&
+       git format-patch -1 --stdout >out &&
+       ! grep "this is note 1" out &&
+       grep "this is note 2" out &&
+       git config --add format.notes note1 &&
+       git format-patch -1 --stdout >out &&
+       grep "this is note 1" out &&
+       grep "this is note 2" out &&
+
+       git config --replace-all format.notes note1 &&
+       git config --add format.notes false &&
+       git format-patch -1 --stdout >out &&
+       ! grep "this is note 1" out &&
+       ! grep "this is note 2" out &&
+       git config --add format.notes note2 &&
+       git format-patch -1 --stdout >out &&
+       ! grep "this is note 1" out &&
+       grep "this is note 2" out
+'
+
 echo "fatal: --name-only does not make sense" > expect.name-only
 echo "fatal: --name-status does not make sense" > expect.name-status
 echo "fatal: --check does not make sense" > expect.check