Re: [PATCH 02/14] combine-diff: add combine_diff_path_new()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 9, 2025, 18:05 UTC
- Message-ID
- <xmqqseprj216.fsf@gitster.g>
- In-Reply-To
- <20250109083236.GB2748836@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 20 quoted lines
> +struct combine_diff_path *combine_diff_path_new(const char *path,
> + size_t path_len,
> + unsigned int mode,
> + const struct object_id *oid,
> + size_t num_parents)
> +{
> + struct combine_diff_path *p;
> +
> + p = xmalloc(combine_diff_path_size(num_parents, path_len));
> + p->path = (char *)&(p->parent[num_parents]);
> + memcpy(p->path, path, path_len);
> + p->path[path_len] = 0;
> + p->next = NULL;
> + p->mode = mode;
> + oidcpy(&p->oid, oid);
> +
> + memset(p->parent, 0, sizeof(p->parent[0]) * num_parents);
> +
> + return p;
> +}OK, I can see how the structure is laid out clearly in this code, but I have to say it is one ugly hack X-<. At least with the refactoring, it becomes much easier to see what the caller is doing.