Git fork

use DUP_ARRAY

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>

authored by

René Scharfe and committed by
Junio C Hamano
6e578410 d2ec87a6

+15 -16
+1 -2
attr.c
··· 599 599 600 600 ret->nr = check->nr; 601 601 ret->alloc = check->alloc; 602 - ALLOC_ARRAY(ret->items, ret->nr); 603 - COPY_ARRAY(ret->items, check->items, ret->nr); 602 + DUP_ARRAY(ret->items, check->items, ret->nr); 604 603 605 604 return ret; 606 605 }
+1 -2
builtin/am.c
··· 1489 1489 * apply_opts.v keeps referencing the allocated strings for 1490 1490 * strvec_clear() to release. 1491 1491 */ 1492 - ALLOC_ARRAY(apply_argv, apply_opts.nr); 1493 - COPY_ARRAY(apply_argv, apply_opts.v, apply_opts.nr); 1492 + DUP_ARRAY(apply_argv, apply_opts.v, apply_opts.nr); 1494 1493 1495 1494 opts_left = apply_parse_options(apply_opts.nr, apply_argv, 1496 1495 &apply_state, &force_apply, &options,
+1 -2
commit-graph.c
··· 1594 1594 _("Computing commit changed paths Bloom filters"), 1595 1595 ctx->commits.nr); 1596 1596 1597 - ALLOC_ARRAY(sorted_commits, ctx->commits.nr); 1598 - COPY_ARRAY(sorted_commits, ctx->commits.list, ctx->commits.nr); 1597 + DUP_ARRAY(sorted_commits, ctx->commits.list, ctx->commits.nr); 1599 1598 1600 1599 if (ctx->order_by_pack) 1601 1600 QSORT(sorted_commits, ctx->commits.nr, commit_pos_cmp);
+1 -2
commit-reach.c
··· 245 245 * min_gen_pos points to the current position within 'array' 246 246 * that is not yet known to be STALE. 247 247 */ 248 - ALLOC_ARRAY(sorted, cnt); 249 - COPY_ARRAY(sorted, array, cnt); 248 + DUP_ARRAY(sorted, array, cnt); 250 249 QSORT(sorted, cnt, compare_commits_by_gen); 251 250 min_generation = commit_graph_generation(sorted[0]); 252 251
+1 -2
compat/mingw.c
··· 1396 1396 p += s; 1397 1397 } 1398 1398 1399 - ALLOC_ARRAY(result, size); 1400 - COPY_ARRAY(result, wenv, size); 1399 + DUP_ARRAY(result, wenv, size); 1401 1400 FreeEnvironmentStringsW(wenv); 1402 1401 return result; 1403 1402 }
+7
contrib/coccinelle/array.cocci
··· 94 94 @@ 95 95 - ptr = xcalloc(n, \( sizeof(*ptr) \| sizeof(T) \) ) 96 96 + CALLOC_ARRAY(ptr, n) 97 + 98 + @@ 99 + expression dst, src, n; 100 + @@ 101 + -ALLOC_ARRAY(dst, n); 102 + -COPY_ARRAY(dst, src, n); 103 + +DUP_ARRAY(dst, src, n);
+1 -2
parse-options.c
··· 702 702 if (!nr_aliases) 703 703 return NULL; 704 704 705 - ALLOC_ARRAY(newopt, nr + 1); 706 - COPY_ARRAY(newopt, options, nr + 1); 705 + DUP_ARRAY(newopt, options, nr + 1); 707 706 708 707 /* each alias has two string pointers and NULL */ 709 708 CALLOC_ARRAY(ctx->alias_groups, 3 * (nr_aliases + 1));
+2 -4
pathspec.c
··· 681 681 int i, j; 682 682 683 683 *dst = *src; 684 - ALLOC_ARRAY(dst->items, dst->nr); 685 - COPY_ARRAY(dst->items, src->items, dst->nr); 684 + DUP_ARRAY(dst->items, src->items, dst->nr); 686 685 687 686 for (i = 0; i < dst->nr; i++) { 688 687 struct pathspec_item *d = &dst->items[i]; ··· 691 690 d->match = xstrdup(s->match); 692 691 d->original = xstrdup(s->original); 693 692 694 - ALLOC_ARRAY(d->attr_match, d->attr_match_nr); 695 - COPY_ARRAY(d->attr_match, s->attr_match, d->attr_match_nr); 693 + DUP_ARRAY(d->attr_match, s->attr_match, d->attr_match_nr); 696 694 for (j = 0; j < d->attr_match_nr; j++) { 697 695 const char *value = s->attr_match[j].value; 698 696 d->attr_match[j].value = xstrdup_or_null(value);