[PATCH v2 0/6] string-list API user: fix API use, some with coccinelle

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A larger v2, this:

 * Renames string_list.cocci to string-list.cocci (to be consistent
   with the string-list.[ch])

 * Answers Elijah's question about why the previous 2/2 left out one
   case, it's due to --disable-worth-trying-opt. That's now split out
   into its own commit.

   FWIW it's the only case with "make coccicheck" that we've "missed",
   including existing rules, but we just got lucky there.

   I have some follow-up patches to fix various such bugs in our
   coccicheck, but let's leave the larger fixes for now.

 * The new 4/6 duplicates Junio's
   https://lore.kernel.org/git/xmqq7d471dns.fsf@gitster.g/, but now
   we've got a coccinelle rule for it and similar inverse cases. It's
   still the only in-tree case, but it's probably good to keep the
   rule around regardless.

   I could also eject that *.C change and say this is based on
   Junio's, or both could make the same change and "merge" will sort
   it out. I do think 4/6 is a bit easier to read with an actual case
   where we change things, but then again there's the added tests...

 * A new 5/6 tweaks some "strdup_strings" dancing to a simpler
   pattern, this is adjusted from my local WIP branch of larger
   string_list API fixes.

 * A new 6/6 fixes a confusing case of dup v.s. nodup to use a more
   obvious callback pattern where we don't flip-flop.

Ævar Arnfjörð Bjarmason (6):
  string_list API users + cocci: use string_list_init_dup()
  cocci: apply string_list.cocci with --disable-worth-trying-opt
  reflog-walk.c: use string_list_init_dup()
  cocci: add "string_list" rule to swap "DUP" <-> "NODUP"
  string-list API users: don't tweak "strdup_strings" to free dupes
  notes.c: make "struct string_list display_notes_refs" non-static

 bisect.c                                 |  7 +++---
 builtin/remote.c                         |  3 +--
 contrib/coccinelle/string-list.cocci     | 26 ++++++++++++++++++++++
 contrib/coccinelle/tests/string-list.c   | 20 +++++++++++++++++
 contrib/coccinelle/tests/string-list.res | 18 +++++++++++++++
 notes-utils.c                            |  4 ++--
 notes.c                                  | 28 ++++++++++++++----------
 reflog-walk.c                            |  2 +-
 refs.c                                   |  4 ++--
 resolve-undo.c                           |  8 +++----
 revision.c                               |  4 ++--
 11 files changed, 95 insertions(+), 29 deletions(-)
 create mode 100644 contrib/coccinelle/string-list.cocci
 create mode 100644 contrib/coccinelle/tests/string-list.c
 create mode 100644 contrib/coccinelle/tests/string-list.res

Range-diff against v1:
1:  c89758491e7 ! 1:  61a62bdf8e9 string_list API users + cocci: use string_list_init_dup()
    @@ Commit message
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
     
    - ## contrib/coccinelle/string_list.cocci (new) ##
    + ## contrib/coccinelle/string-list.cocci (new) ##
     @@
     +@@
     +struct string_list *P;
    @@ contrib/coccinelle/string_list.cocci (new)
     +- (P)->strdup_strings = 1;
     ++ string_list_init_dup(P);
     
    - ## contrib/coccinelle/tests/string_list.c (new) ##
    + ## contrib/coccinelle/tests/string-list.c (new) ##
     @@
     +int init(void)
     +{
    @@ contrib/coccinelle/tests/string_list.c (new)
     +	list->strdup_strings = 1;
     +}
     
    - ## contrib/coccinelle/tests/string_list.res (new) ##
    + ## contrib/coccinelle/tests/string-list.res (new) ##
     @@
     +int init(void)
     +{
2:  5d8baa9cbc4 ! 2:  33e551a2f4c string-list API users: manually use string_list_init_*()
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
     
      ## Commit message ##
    -    string-list API users: manually use string_list_init_*()
    +    cocci: apply string_list.cocci with --disable-worth-trying-opt
     
    -    Convert various code that didn't use string_list_init_*() to do so, in
    -    cases where the only thing being allocated was the string list we can
    -    change from CALLOC_ARRAY() to ALLOC_ARRAY(), the string_list_init_*()
    -    function will zero out the memory.
    +    Apply the new string-list.cocci added in the preceding commit with
    +    --disable-worth-trying-opt. For optimization purposes we run spatch in
    +    a mode where even though we run it with --all-includes we'll miss some
    +    changes because we don't use --disable-worth-trying-opt.
     
    -    This covers cases that weren't matched by tho coccinelle rule in the
    -    preceding commit, which is conservative enough to care about the type
    -    of what we're modifying.
    +    This is because without that option it'll take a look at
    +    notes-utils.c, and conclude that it doesn't need to process
    +    it (irrelevant output excluded with "[...]"):
    +
    +            $ spatch --sp-file contrib/coccinelle/string-list.cocci --patch . notes-utils.c
    +            [...]
    +            (ONCE) Expected tokens string_list strdup_strings CALLOC_ARRAY
    +            Skipping: notes-utils.c
    +
    +    This is just one of the known (and probably some unknown) issues where
    +    our "make coccicheck" fails to include changes for whatever
    +    reason. That should be fixed more generally, but let's just fix this
    +    manually for now.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
     
    @@ notes-utils.c: struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char
      	c->refs_from_env = 0;
      	c->mode_from_env = 0;
      	if (rewrite_mode_env) {
    -
    - ## reflog-walk.c ##
    -@@ reflog-walk.c: struct reflog_walk_info {
    - void init_reflog_walk(struct reflog_walk_info **info)
    - {
    - 	CALLOC_ARRAY(*info, 1);
    --	(*info)->complete_reflogs.strdup_strings = 1;
    -+	string_list_init_dup(&((*info)->complete_reflogs));
    - }
    - 
    - void reflog_walk_info_release(struct reflog_walk_info *info)
-:  ----------- > 3:  62aab32ae77 reflog-walk.c: use string_list_init_dup()
-:  ----------- > 4:  2d858c49243 cocci: add "string_list" rule to swap "DUP" <-> "NODUP"
-:  ----------- > 5:  8c0ac6cbd96 string-list API users: don't tweak "strdup_strings" to free dupes
-:  ----------- > 6:  b0de7a63d1c notes.c: make "struct string_list display_notes_refs" non-static
-- 
2.37.1.1095.g64a1e8362fd




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux