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