Skip to content

Commit 2715e8a

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6debb75 commit 2715e8a

File tree

3 files changed

+22
-41
lines changed

3 files changed

+22
-41
lines changed

diff.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3362,23 +3362,23 @@ struct userdiff_driver *get_textconv(struct repository *r,
33623362
return userdiff_get_textconv(r, one->driver);
33633363
}
33643364

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)
33673367
{
33683368
if (!o->additional_path_headers)
33693369
return NULL;
33703370
return strmap_get(o->additional_path_headers, path);
33713371
}
33723372

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,
33753375
const char *line_prefix,
33763376
const char *meta,
33773377
const char *reset)
33783378
{
3379-
char *next, *newline;
3379+
const char *next, *newline;
33803380

3381-
for (next = more_headers->buf; *next; next = newline) {
3381+
for (next = header; *next; next = newline) {
33823382
newline = strchrnul(next, '\n');
33833383
strbuf_addf(msg, "%s%s%.*s%s\n", line_prefix, meta,
33843384
(int)(newline - next), next, reset);
@@ -3387,6 +3387,19 @@ static void add_formatted_headers(struct strbuf *msg,
33873387
}
33883388
}
33893389

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+
33903403
static void builtin_diff(const char *name_a,
33913404
const char *name_b,
33923405
struct diff_filespec *one,
@@ -4314,7 +4327,7 @@ static void fill_metainfo(struct strbuf *msg,
43144327
const char *set = diff_get_color(use_color, DIFF_METAINFO);
43154328
const char *reset = diff_get_color(use_color, DIFF_RESET);
43164329
const char *line_prefix = diff_line_prefix(o);
4317-
struct strbuf *more_headers = NULL;
4330+
struct string_list *more_headers = NULL;
43184331

43194332
*must_show_header = 1;
43204333
strbuf_init(msg, PATH_MAX * 2 + 300);

merge-ort.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,24 +4371,13 @@ void merge_finalize(struct merge_options *opt,
43714371
struct merge_result *result)
43724372
{
43734373
struct merge_options_internal *opti = result->priv;
4374-
struct hashmap_iter iter;
4375-
struct strmap_entry *e;
43764374

43774375
if (opt->renormalize)
43784376
git_attr_set_direction(GIT_ATTR_CHECKIN);
43794377
assert(opt->priv == NULL);
43804378

43814379
clear_or_reinit_internal_opts(opti, 0);
43824380
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);
43924381
}
43934382

43944383
/*** Function Grouping: helper functions for merge_incore_*() ***/
@@ -4612,8 +4601,6 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt,
46124601
struct merge_result *result)
46134602
{
46144603
struct object_id working_tree_oid;
4615-
struct hashmap_iter iter;
4616-
struct strmap_entry *e;
46174604

46184605
if (opt->subtree_shift) {
46194606
side2 = shift_tree_object(opt->repo, side1, side2,
@@ -4654,26 +4641,7 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt,
46544641
trace2_region_leave("merge", "process_entries", opt->repo);
46554642

46564643
/* 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;
46774645

46784646
result->tree = parse_tree_indirect(&working_tree_oid);
46794647
/* existence of conflicted entries implies unclean */

merge-ort.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct merge_result {
2828
/*
2929
* Special messages and conflict notices for various paths
3030
*
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
3232
* warning/conflict/notice messages (possibly multiple per path)
3333
* that callers may want to use.
3434
*/

0 commit comments

Comments
 (0)