]> git.ipfire.org Git - thirdparty/git.git/commitdiff
use DUP_ARRAY
authorRené Scharfe <l.s.r@web.de>
Sun, 1 Jan 2023 21:16:48 +0000 (22:16 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Jan 2023 04:28:36 +0000 (13:28 +0900)
Add a semantic patch for replace ALLOC_ARRAY+COPY_ARRAY with DUP_ARRAY
to reduce code duplication and apply its results.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
attr.c
builtin/am.c
commit-graph.c
commit-reach.c
compat/mingw.c
contrib/coccinelle/array.cocci
parse-options.c
pathspec.c

diff --git a/attr.c b/attr.c
index 42ad6de8c7c61432e4a3c950d940eee433680a74..e4e304a826721a7c87b13cb1776e40ac8eab17c3 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -599,8 +599,7 @@ struct attr_check *attr_check_dup(const struct attr_check *check)
 
        ret->nr = check->nr;
        ret->alloc = check->alloc;
-       ALLOC_ARRAY(ret->items, ret->nr);
-       COPY_ARRAY(ret->items, check->items, ret->nr);
+       DUP_ARRAY(ret->items, check->items, ret->nr);
 
        return ret;
 }
index dddf1b9af0144429c067fc8c1fc6587dc14f7502..eee06bbb6ce9769937ffdedc6a3414ddfdadef27 100644 (file)
@@ -1489,8 +1489,7 @@ static int run_apply(const struct am_state *state, const char *index_file)
         * apply_opts.v keeps referencing the allocated strings for
         * strvec_clear() to release.
         */
-       ALLOC_ARRAY(apply_argv, apply_opts.nr);
-       COPY_ARRAY(apply_argv, apply_opts.v, apply_opts.nr);
+       DUP_ARRAY(apply_argv, apply_opts.v, apply_opts.nr);
 
        opts_left = apply_parse_options(apply_opts.nr, apply_argv,
                                        &apply_state, &force_apply, &options,
index a7d8755932884cfcb05fad4c539c3b8be8322897..c11b59f28b3164cee21ab972088c32082d8f5bb6 100644 (file)
@@ -1594,8 +1594,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
                        _("Computing commit changed paths Bloom filters"),
                        ctx->commits.nr);
 
-       ALLOC_ARRAY(sorted_commits, ctx->commits.nr);
-       COPY_ARRAY(sorted_commits, ctx->commits.list, ctx->commits.nr);
+       DUP_ARRAY(sorted_commits, ctx->commits.list, ctx->commits.nr);
 
        if (ctx->order_by_pack)
                QSORT(sorted_commits, ctx->commits.nr, commit_pos_cmp);
index c226ee3da469c50c82dea58804ad3819230ed112..2e33c599a82c81127b9a24547d0834e6c7a55bcf 100644 (file)
@@ -245,8 +245,7 @@ static int remove_redundant_with_gen(struct repository *r,
         * min_gen_pos points to the current position within 'array'
         * that is not yet known to be STALE.
         */
-       ALLOC_ARRAY(sorted, cnt);
-       COPY_ARRAY(sorted, array, cnt);
+       DUP_ARRAY(sorted, array, cnt);
        QSORT(sorted, cnt, compare_commits_by_gen);
        min_generation = commit_graph_generation(sorted[0]);
 
index e131eb9b07a0d745f1475089ae15a314c53c9d5e..cd8195ab1147190d145f36fb6836bd6b23a9d8ed 100644 (file)
@@ -1396,8 +1396,7 @@ static wchar_t *make_environment_block(char **deltaenv)
                        p += s;
                }
 
-               ALLOC_ARRAY(result, size);
-               COPY_ARRAY(result, wenv, size);
+               DUP_ARRAY(result, wenv, size);
                FreeEnvironmentStringsW(wenv);
                return result;
        }
index aa759379508895ba002c531a13bde3f8995f9251..27a3b479c94e5cb42817c3d2bd1fff6f270ef583 100644 (file)
@@ -94,3 +94,10 @@ expression n != 1;
 @@
 - ptr = xcalloc(n, \( sizeof(*ptr) \| sizeof(T) \) )
 + CALLOC_ARRAY(ptr, n)
+
+@@
+expression dst, src, n;
+@@
+-ALLOC_ARRAY(dst, n);
+-COPY_ARRAY(dst, src, n);
++DUP_ARRAY(dst, src, n);
index a1ec932f0f9ff32e82223735dfd927473051fd3b..fd4743293fc48f9453499ad4f9695462b9c08217 100644 (file)
@@ -702,8 +702,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
        if (!nr_aliases)
                return NULL;
 
-       ALLOC_ARRAY(newopt, nr + 1);
-       COPY_ARRAY(newopt, options, nr + 1);
+       DUP_ARRAY(newopt, options, nr + 1);
 
        /* each alias has two string pointers and NULL */
        CALLOC_ARRAY(ctx->alias_groups, 3 * (nr_aliases + 1));
index 46e77a85fee9d86e6e16e9f466ecfc3db893fd16..e038481dc48bc7c316368f75d276757fbec8c099 100644 (file)
@@ -681,8 +681,7 @@ void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
        int i, j;
 
        *dst = *src;
-       ALLOC_ARRAY(dst->items, dst->nr);
-       COPY_ARRAY(dst->items, src->items, dst->nr);
+       DUP_ARRAY(dst->items, src->items, dst->nr);
 
        for (i = 0; i < dst->nr; i++) {
                struct pathspec_item *d = &dst->items[i];
@@ -691,8 +690,7 @@ void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
                d->match = xstrdup(s->match);
                d->original = xstrdup(s->original);
 
-               ALLOC_ARRAY(d->attr_match, d->attr_match_nr);
-               COPY_ARRAY(d->attr_match, s->attr_match, d->attr_match_nr);
+               DUP_ARRAY(d->attr_match, s->attr_match, d->attr_match_nr);
                for (j = 0; j < d->attr_match_nr; j++) {
                        const char *value = s->attr_match[j].value;
                        d->attr_match[j].value = xstrdup_or_null(value);