@@ -1229,10 +1229,9 @@ static int get_one_entry(struct remote *remote, void *priv)
static int show_all(void)
{
- struct string_list list = STRING_LIST_INIT_NODUP;
+ struct string_list list = STRING_LIST_INIT_DUP;
int result;
- list.strdup_strings = 1;
result = for_each_remote(get_one_entry, &list);
if (!result) {
@@ -6,3 +6,21 @@ struct string_list *P;
... when != P
- (P)->strdup_strings = 1;
+ string_list_init_dup(P);
+
+@@
+type T;
+identifier I;
+constant INIT_NODUP =~ "^STRING_LIST_INIT_NODUP$";
+constant INIT_DUP =~ "^STRING_LIST_INIT_DUP$";
+@@
+(
+- T I = INIT_NODUP;
++ T I = STRING_LIST_INIT_DUP;
+... when != &I
+- I.strdup_strings = 1;
+|
+- T I = INIT_DUP;
++ T I = STRING_LIST_INIT_NODUP;
+... when != &I
+- I.strdup_strings = 0;
+)
@@ -1,7 +1,20 @@
int init(void)
{
struct string_list *list;
+ struct string_list list2 = STRING_LIST_INIT_NODUP;
+ struct string_list list3 = STRING_LIST_INIT_DUP;
+ struct string_list list4 = STRING_LIST_INIT_NODUP;
+ struct string_list list5 = STRING_LIST_INIT_DUP;
CALLOC_ARRAY(list, 1);
+
+ /* Exclude these */
+ string_list_append(&list4, "str");
+ string_list_append_nodup(&list5, xstrdup("str"));
+
list->strdup_strings = 1;
+ list2.strdup_strings = 1;
+ list3.strdup_strings = 0;
+ list4.strdup_strings = 1;
+ list5.strdup_strings = 0;
}
@@ -1,7 +1,18 @@
int init(void)
{
struct string_list *list;
+ struct string_list list2 = STRING_LIST_INIT_DUP;
+ struct string_list list3 = STRING_LIST_INIT_NODUP;
+ struct string_list list4 = STRING_LIST_INIT_NODUP;
+ struct string_list list5 = STRING_LIST_INIT_DUP;
ALLOC_ARRAY(list, 1);
+
+ /* Exclude these */
+ string_list_append(&list4, "str");
+ string_list_append_nodup(&list5, xstrdup("str"));
+
string_list_init_dup(list);
+ list4.strdup_strings = 1;
+ list5.strdup_strings = 0;
}
Add a coccinelle rule to swap "NODUP" and "DUP" initialization in cases such as [1], which as this change shows produces an identical change. We happened to have only one change in-tree that matched this criteria, but now we're more certain of that, and will convert these sorts of cases in the future. 1. https://lore.kernel.org/git/xmqq7d471dns.fsf@gitster.g/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- builtin/remote.c | 3 +-- contrib/coccinelle/string-list.cocci | 18 ++++++++++++++++++ contrib/coccinelle/tests/string-list.c | 13 +++++++++++++ contrib/coccinelle/tests/string-list.res | 11 +++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-)