@matheusbsbs / matheus-bagliano / commits / 8164c961e1
Fork 0

format-patch: use --notes behavior for format.notes

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>

Denton Liu committed Dec 9, 2019 at 05:10 UTC 8164c961e16834da283cbf5ac5d22313b982a484
2 files changed +33 -12
builtin/log.c
+1 -12
@@ -867,19 +867,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
867 return 0;
868 }
869 if (!strcmp(var, "format.notes")) {
870 - struct strbuf buf = STRBUF_INIT;
870 int b = git_parse_maybe_bool(value);
872 - if (!b)
873 - return 0;
874 - rev->show_notes = 1;
875 - if (b < 0) {
876 - strbuf_addstr(&buf, value);
877 - expand_notes_ref(&buf);
878 - string_list_append(&rev->notes_opt.extra_notes_refs,
879 - strbuf_detach(&buf, NULL));
880 - } else {
881 - rev->notes_opt.use_default_notes = 1;
882 - }
871 + rev->show_notes = set_display_notes(&rev->notes_opt, b, b < 0 ? value : NULL);
872 return 0;
873 }
874
t/t4014-format-patch.sh
+32
@@ -808,6 +808,38 @@ test_expect_success 'format-patch with multiple notes refs' '
808 ! grep "this is note 2" out
809 '
810
811 +test_expect_success 'format-patch with multiple notes refs in config' '
812 + test_when_finished "test_unconfig format.notes" &&
813 +
814 + git notes --ref note1 add -m "this is note 1" HEAD &&
815 + test_when_finished git notes --ref note1 remove HEAD &&
816 + git notes --ref note2 add -m "this is note 2" HEAD &&
817 + test_when_finished git notes --ref note2 remove HEAD &&
818 +
819 + git config format.notes note1 &&
820 + git format-patch -1 --stdout >out &&
821 + grep "this is note 1" out &&
822 + ! grep "this is note 2" out &&
823 + git config format.notes note2 &&
824 + git format-patch -1 --stdout >out &&
825 + ! grep "this is note 1" out &&
826 + grep "this is note 2" out &&
827 + git config --add format.notes note1 &&
828 + git format-patch -1 --stdout >out &&
829 + grep "this is note 1" out &&
830 + grep "this is note 2" out &&
831 +
832 + git config --replace-all format.notes note1 &&
833 + git config --add format.notes false &&
834 + git format-patch -1 --stdout >out &&
835 + ! grep "this is note 1" out &&
836 + ! grep "this is note 2" out &&
837 + git config --add format.notes note2 &&
838 + git format-patch -1 --stdout >out &&
839 + ! grep "this is note 1" out &&
840 + grep "this is note 2" out
841 +'
842 +
843 echo "fatal: --name-only does not make sense" > expect.name-only
844 echo "fatal: --name-status does not make sense" > expect.name-status
845 echo "fatal: --check does not make sense" > expect.check