]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'dl/format-patch-notes-config-fixup'
authorJunio C Hamano <gitster@pobox.com>
Wed, 25 Dec 2019 19:21:58 +0000 (11:21 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Dec 2019 19:21:58 +0000 (11:21 -0800)
"git format-patch" can take a set of configured format.notes values
to specify which notes refs to use in the log message part of the
output.  The behaviour of this was not consistent with multiple
--notes command line options, which has been corrected.

* dl/format-patch-notes-config-fixup:
  notes.h: fix typos in comment
  notes: break set_display_notes() into smaller functions
  config/format.txt: clarify behavior of multiple format.notes
  format-patch: move git_config() before repo_init_revisions()
  format-patch: use --notes behavior for format.notes
  notes: extract logic into set_display_notes()
  notes: create init_display_notes() helper
  notes: rename to load_display_notes()

1  2 
Documentation/config/format.txt
builtin/log.c
notes.c
notes.h
revision.c
revision.h
t/t4014-format-patch.sh

Simple merge
diff --cc builtin/log.c
index 8c664067ca0c3ea0dd12120cb7d2a89100a595a3,b6d43a4a47ebbc39e36c5552b3bd0fdc5ae44404..83a4a6188e221caefc5028e59cb7c95c2f1d1e0c
@@@ -792,25 -767,17 +792,27 @@@ static int base_auto
  static char *from;
  static const char *signature = git_version_string;
  static const char *signature_file;
 -static int config_cover_letter;
 +static enum cover_setting config_cover_letter;
  static const char *config_output_directory;
 +static enum cover_from_description cover_from_description_mode = COVER_FROM_MESSAGE;
+ static int show_notes;
+ static struct display_notes_opt notes_opt;
  
 -enum {
 -      COVER_UNSET,
 -      COVER_OFF,
 -      COVER_ON,
 -      COVER_AUTO
 -};
 +static enum cover_from_description parse_cover_from_description(const char *arg)
 +{
 +      if (!arg || !strcmp(arg, "default"))
 +              return COVER_FROM_MESSAGE;
 +      else if (!strcmp(arg, "none"))
 +              return COVER_FROM_NONE;
 +      else if (!strcmp(arg, "message"))
 +              return COVER_FROM_MESSAGE;
 +      else if (!strcmp(arg, "subject"))
 +              return COVER_FROM_SUBJECT;
 +      else if (!strcmp(arg, "auto"))
 +              return COVER_FROM_AUTO;
 +      else
 +              die(_("%s: invalid cover from description mode"), arg);
 +}
  
  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;
-               }
+               if (b < 0)
+                       enable_ref_display_notes(&notes_opt, &show_notes, value);
+               else if (b)
+                       enable_default_display_notes(&notes_opt, &show_notes);
+               else
+                       disable_display_notes(&notes_opt, &show_notes);
                return 0;
        }
 +      if (!strcmp(var, "format.coverfromdescription")) {
 +              cover_from_description_mode = parse_cover_from_description(value);
 +              return 0;
 +      }
  
        return git_log_config(var, value, cb);
  }
diff --cc notes.c
Simple merge
diff --cc notes.h
index 76337f2384723dbce79e437aa6aaa3ba7e9901a4,bbab1961caf12b13bfa40ef347d7b9b3687d18c1..c1682c39a97bf6d84940b64b353286dfb91282a3
+++ b/notes.h
@@@ -276,12 -296,14 +296,12 @@@ void load_display_notes(struct display_
  
  /*
   * Append notes for the given 'object_sha1' from all trees set up by
-  * init_display_notes() to 'sb'.
 - * load_display_notes() to 'sb'.  The 'flags' are a bitwise
 - * combination of
++ * load_display_notes() to 'sb'.
   *
 - * - NOTES_SHOW_HEADER: add a 'Notes (refname):' header
 - *
 - * - NOTES_INDENT: indent the notes by 4 places
 + * If 'raw' is false the note will be indented by 4 places and
 + * a 'Notes (refname):' header added.
   *
-  * You *must* call init_display_notes() before using this function.
+  * You *must* call load_display_notes() before using this function.
   */
  void format_display_notes(const struct object_id *object_oid,
                          struct strbuf *sb, const char *output_encoding, int raw);
diff --cc revision.c
Simple merge
diff --cc revision.h
Simple merge
index a5b6302a1c93c8e6ad64dd03787bf9a33f3fdf27,5c40ea439761b38f4b2eae852e6e311038c6a590..b653dd7d44521270995b456d7b8e2dcfd6957af5
@@@ -793,24 -808,53 +793,56 @@@ test_expect_success 'format-patch with 
        ! 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
+ 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
  
  test_expect_success 'options no longer allowed for format-patch' '
 -      test_must_fail git format-patch --name-only 2> output &&
 +      test_must_fail git format-patch --name-only 2>output &&
        test_i18ncmp expect.name-only output &&
 -      test_must_fail git format-patch --name-status 2> output &&
 +      test_must_fail git format-patch --name-status 2>output &&
        test_i18ncmp expect.name-status output &&
 -      test_must_fail git format-patch --check 2> output &&
 -      test_i18ncmp expect.check output'
 +      test_must_fail git format-patch --check 2>output &&
 +      test_i18ncmp expect.check output
 +'
  
  test_expect_success 'format-patch --numstat should produce a patch' '
 -      git format-patch --numstat --stdout master..side > output &&
 -      test 5 = $(grep "^diff --git a/" output | wc -l)'
 +      git format-patch --numstat --stdout master..side >output &&
 +      grep "^diff --git a/" output >diff &&
 +      test_line_count = 5 diff
 +'
  
  test_expect_success 'format-patch -- <path>' '
        git format-patch master..side -- file 2>error &&