merge-ort: make `path_messages` a strmap to a string_list

This allows us once again to get away with less data copying. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 18, 2022 at 00:20 UTC 2715e8a931ce1ad3a7bcffbdc6c0e556ae87d158
3 files changed +22 -41
diff.c
+20 -7
@@ -3362,23 +3362,23 @@ struct userdiff_driver *get_textconv(struct repository *r,
3362 return userdiff_get_textconv(r, one->driver);
3363 }
3364
3365 -static struct strbuf *additional_headers(struct diff_options *o,
3366 - const char *path)
3365 +static struct string_list *additional_headers(struct diff_options *o,
3366 + const char *path)
3367 {
3368 if (!o->additional_path_headers)
3369 return NULL;
3370 return strmap_get(o->additional_path_headers, path);
3371 }
3372
3373 -static void add_formatted_headers(struct strbuf *msg,
3374 - struct strbuf *more_headers,
3373 +static void add_formatted_header(struct strbuf *msg,
3374 + const char *header,
3375 const char *line_prefix,
3376 const char *meta,
3377 const char *reset)
3378 {
3379 - char *next, *newline;
3379 + const char *next, *newline;
3380
3381 - for (next = more_headers->buf; *next; next = newline) {
3381 + for (next = header; *next; next = newline) {
3382 newline = strchrnul(next, '\n');
3383 strbuf_addf(msg, "%s%s%.*s%s\n", line_prefix, meta,
3384 (int)(newline - next), next, reset);
@@ -3387,6 +3387,19 @@ static void add_formatted_headers(struct strbuf *msg,
3387 }
3388 }
3389
3390 +static void add_formatted_headers(struct strbuf *msg,
3391 + struct string_list *more_headers,
3392 + const char *line_prefix,
3393 + const char *meta,
3394 + const char *reset)
3395 +{
3396 + int i;
3397 +
3398 + for (i = 0; i < more_headers->nr; i++)
3399 + add_formatted_header(msg, more_headers->items[i].string,
3400 + line_prefix, meta, reset);
3401 +}
3402 +
3403 static void builtin_diff(const char *name_a,
3404 const char *name_b,
3405 struct diff_filespec *one,
@@ -4314,7 +4327,7 @@ static void fill_metainfo(struct strbuf *msg,
4327 const char *set = diff_get_color(use_color, DIFF_METAINFO);
4328 const char *reset = diff_get_color(use_color, DIFF_RESET);
4329 const char *line_prefix = diff_line_prefix(o);
4317 - struct strbuf *more_headers = NULL;
4330 + struct string_list *more_headers = NULL;
4331
4332 *must_show_header = 1;
4333 strbuf_init(msg, PATH_MAX * 2 + 300);
merge-ort.c
+1 -33
@@ -4371,8 +4371,6 @@ void merge_finalize(struct merge_options *opt,
4371 struct merge_result *result)
4372 {
4373 struct merge_options_internal *opti = result->priv;
4374 - struct hashmap_iter iter;
4375 - struct strmap_entry *e;
4374
4375 if (opt->renormalize)
4376 git_attr_set_direction(GIT_ATTR_CHECKIN);
@@ -4380,15 +4378,6 @@ void merge_finalize(struct merge_options *opt,
4378
4379 clear_or_reinit_internal_opts(opti, 0);
4380 FREE_AND_NULL(opti);
4383 -
4384 - /* Release and free each strbuf found in path_messages */
4385 - strmap_for_each_entry(result->path_messages, &iter, e) {
4386 - struct strbuf *buf = e->value;
4387 -
4388 - strbuf_release(buf);
4389 - }
4390 - strmap_clear(result->path_messages, 1);
4391 - FREE_AND_NULL(result->path_messages);
4381 }
4382
4383 /*** Function Grouping: helper functions for merge_incore_*() ***/
@@ -4612,8 +4601,6 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt,
4601 struct merge_result *result)
4602 {
4603 struct object_id working_tree_oid;
4615 - struct hashmap_iter iter;
4616 - struct strmap_entry *e;
4604
4605 if (opt->subtree_shift) {
4606 side2 = shift_tree_object(opt->repo, side1, side2,
@@ -4654,26 +4641,7 @@ redo:
4641 trace2_region_leave("merge", "process_entries", opt->repo);
4642
4643 /* Set return values */
4657 - result->path_messages = xcalloc(1, sizeof(*result->path_messages));
4658 - strmap_init_with_options(result->path_messages, NULL, 0);
4659 - strmap_for_each_entry(&opt->priv->conflicts, &iter, e) {
4660 - const char *path = e->key;
4661 - struct strbuf *buf = strmap_get(result->path_messages, path);
4662 - struct string_list *conflicts = e->value;
4663 -
4664 - if (!buf) {
4665 - buf = xcalloc(1, sizeof(*buf));
4666 - strbuf_init(buf, 0);
4667 - strmap_put(result->path_messages, path, buf);
4668 - }
4669 -
4670 - for (int i = 0; i < conflicts->nr; i++) {
4671 - if (buf->len)
4672 - strbuf_addch(buf, '\n');
4673 - strbuf_addstr(buf, conflicts->items[i].string);
4674 - strbuf_trim_trailing_newline(buf);
4675 - }
4676 - }
4644 + result->path_messages = &opt->priv->conflicts;
4645
4646 result->tree = parse_tree_indirect(&working_tree_oid);
4647 /* existence of conflicted entries implies unclean */
merge-ort.h
+1 -1
@@ -28,7 +28,7 @@ struct merge_result {
28 /*
29 * Special messages and conflict notices for various paths
30 *
31 - * This is a map of pathnames to strbufs. It contains various
31 + * This is a map of pathnames to a string_list. It contains various
32 * warning/conflict/notice messages (possibly multiple per path)
33 * that callers may want to use.
34 */