Re: [PATCH v2 2/2] range-diff: add configurable memory limit for cost matrix
- From
Elijah Newren <newren@gmail.com>
- Date
- Aug 28, 2025, 17:04 UTC
- Message-ID
- <CABPp-BEDje5dYZHEyYMN6j_LdR5CqRN1cxc0riRK06qK-OxiTA@mail.gmail.com>
- In-Reply-To
- <c81f920fee0ed8672783728fae70b6435e800f82.1756370289.git.gitgitgadget@gmail.com>
On Thu, Aug 28, 2025 at 2:00 AM pcasaretto via GitGitGadget <gitgitgadget@gmail.com> wrote:
> > From: pcasaretto <paulo.casaretto@shopify.com> > Signed-off-by: Paulo Casaretto <paulo.casaretto@shopify.com>
The names (and emails) in these should match; I believe the name in the From field is set by Gitgitgadget based on your profile settings; see https://github.com/settings/profile and set your name there.
Show 19 quoted lines
> static void get_correspondences(struct string_list *a, struct string_list *b,
> - int creation_factor)
> + int creation_factor, size_t max_memory)
> {
> int n = a->nr + b->nr;
> int *cost, c, *a2b, *b2a;
> int i, j;
> -
> - ALLOC_ARRAY(cost, st_mult(n, n));
> + size_t cost_size = st_mult(n, n);
> + size_t cost_bytes = st_mult(sizeof(int), cost_size);
> + if (cost_bytes >= max_memory) {
> + struct strbuf cost_str = STRBUF_INIT;
> + struct strbuf max_str = STRBUF_INIT;
> + strbuf_humanise_bytes(&cost_str, cost_bytes);
> + strbuf_humanise_bytes(&max_str, max_memory);
> + die(_("range-diff: unable to compute the range-diff, since it "
> + "exceeds the maximum memory for the cost matrix: %s "
> + "(%"PRIuMAX" bytes) needed, %s (%"PRIuMAX" bytes) available"),available? I'm worried the error message will report in users checking system memory, claiming they have 14GB available on their system, and then reporting a "bug".
Perhaps something like:
+ "(%"PRIuMAX" bytes) needed, limited to %s (%"PRIuMAX" bytes)"),
?
The rest of the patch looks good to me.