MCPcopy Create free account
hub / github.com/git/git / get_correspondences

Function get_correspondences

range-diff.c:327–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325}
326
327static void get_correspondences(struct string_list *a, struct string_list *b,
328 int creation_factor, size_t max_memory)
329{
330 int n = a->nr + b->nr;
331 int *cost, c, *a2b, *b2a;
332 int i, j;
333 size_t cost_size = st_mult(n, n);
334 size_t cost_bytes = st_mult(sizeof(int), cost_size);
335 if (cost_bytes >= max_memory) {
336 struct strbuf cost_str = STRBUF_INIT;
337 struct strbuf max_str = STRBUF_INIT;
338 strbuf_humanise_bytes(&cost_str, cost_bytes);
339 strbuf_humanise_bytes(&max_str, max_memory);
340 die(_("range-diff: unable to compute the range-diff, since it "
341 "exceeds the maximum memory for the cost matrix: %s "
342 "(%"PRIuMAX" bytes) needed, limited to %s (%"PRIuMAX" bytes)"),
343 cost_str.buf, (uintmax_t)cost_bytes, max_str.buf, (uintmax_t)max_memory);
344 }
345 ALLOC_ARRAY(cost, cost_size);
346 ALLOC_ARRAY(a2b, n);
347 ALLOC_ARRAY(b2a, n);
348
349 for (i = 0; i < a->nr; i++) {
350 struct patch_util *a_util = a->items[i].util;
351
352 for (j = 0; j < b->nr; j++) {
353 struct patch_util *b_util = b->items[j].util;
354
355 if (a_util->matching == j)
356 c = 0;
357 else if (a_util->matching < 0 && b_util->matching < 0)
358 c = diffsize(a_util->diff, b_util->diff);
359 else
360 c = COST_MAX;
361 cost[i + n * j] = c;
362 }
363
364 c = a_util->matching < 0 ?
365 a_util->diffsize * creation_factor / 100 : COST_MAX;
366 for (j = b->nr; j < n; j++)
367 cost[i + n * j] = c;
368 }
369
370 for (j = 0; j < b->nr; j++) {
371 struct patch_util *util = b->items[j].util;
372
373 c = util->matching < 0 ?
374 util->diffsize * creation_factor / 100 : COST_MAX;
375 for (i = a->nr; i < n; i++)
376 cost[i + n * j] = c;
377 }
378
379 for (i = a->nr; i < n; i++)
380 for (j = b->nr; j < n; j++)
381 cost[i + n * j] = 0;
382
383 compute_assignment(n, n, cost, a2b, b2a);
384

Callers 1

show_range_diffFunction · 0.85

Calls 5

st_multFunction · 0.85
strbuf_humanise_bytesFunction · 0.85
diffsizeFunction · 0.85
compute_assignmentFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected