Skip to content

Commit

Permalink
merge-ort: convert more error() cases to path_msg()
Browse files Browse the repository at this point in the history
merge_submodule() stores errors using path_msg(), whereas other call
sites make use of the error() function.  This is inconsistent, and
moving towards path_msg() seems more friendly for libification efforts
since it will allow the caller to determine whether the error messages
need to be printed.

Signed-off-by: Elijah Newren <[email protected]>
  • Loading branch information
newren committed Jun 10, 2024
1 parent 789485b commit eb6d1ba
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions merge-ort.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@ enum conflict_and_info_types {
* Keep this group _last_ other than NB_CONFLICT_TYPES
*/
CONFLICT_SUBMODULE_CORRUPT,
CONFLICT_THREEWAY_CONTENT_MERGE_FAILED,
CONFLICT_OBJECT_WRITE_FAILED,

/* Keep this entry _last_ in the list */
NB_CONFLICT_TYPES,
Expand Down Expand Up @@ -614,6 +616,10 @@ static const char *type_short_descriptions[] = {
/* Something is seriously wrong; cannot even perform merge */
[CONFLICT_SUBMODULE_CORRUPT] =
"CONFLICT (submodule corrupt)",
[CONFLICT_THREEWAY_CONTENT_MERGE_FAILED] =
"CONFLICT (three-way content merge failed)",
[CONFLICT_OBJECT_WRITE_FAILED] =
"CONFLICT (object write failed)",
};

struct logical_conflict_info {
Expand Down Expand Up @@ -2188,15 +2194,24 @@ static int handle_content_merge(struct merge_options *opt,
pathnames, extra_marker_size,
&result_buf);

if ((merge_status < 0) || !result_buf.ptr)
ret = error(_("failed to execute internal merge"));
if ((merge_status < 0) || !result_buf.ptr) {
path_msg(opt, CONFLICT_THREEWAY_CONTENT_MERGE_FAILED, 0,
pathnames[0], pathnames[1], pathnames[2], NULL,
_("failed to execute internal merge for %s"),
path);
ret = -1;
}

if (!ret &&
write_object_file(result_buf.ptr, result_buf.size,
OBJ_BLOB, &result->oid))
ret = error(_("unable to add %s to database"), path);

OBJ_BLOB, &result->oid)) {
path_msg(opt, CONFLICT_OBJECT_WRITE_FAILED, 0,
pathnames[0], pathnames[1], pathnames[2], NULL,
_("unable to add %s to database"), path);
ret = -1;
}
free(result_buf.ptr);

if (ret)
return -1;
if (merge_status > 0)
Expand Down

0 comments on commit eb6d1ba

Please sign in to comment.