Skip to content

Commit 0c0d705

Browse files
newrengitster
authored andcommitted
merge-ort: add an err() function similar to one from merge-recursive
Various places in merge-recursive used an err() function when it hit some kind of unrecoverable error. That code was from the reusable bits of merge-recursive.c that we liked, such as merge_3way, writing object files to the object store, reading blobs from the object store, etc. So create a similar function to allow us to port that code over, and use it for when we detect problems returned from collect_merge_info()'s traverse_trees() call, which we will be adding next. While we are at it, also add more documentation for the "clean" field from struct merge_result, particularly since the name suggests a boolean but it is not quite one and this is our first non-boolean usage. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c801717 commit 0c0d705

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

merge-ort.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,27 @@ struct conflict_info {
168168
unsigned match_mask:3;
169169
};
170170

171+
static int err(struct merge_options *opt, const char *err, ...)
172+
{
173+
va_list params;
174+
struct strbuf sb = STRBUF_INIT;
175+
176+
strbuf_addstr(&sb, "error: ");
177+
va_start(params, err);
178+
strbuf_vaddf(&sb, err, params);
179+
va_end(params);
180+
181+
error("%s", sb.buf);
182+
strbuf_release(&sb);
183+
184+
return -1;
185+
}
186+
171187
static int collect_merge_info(struct merge_options *opt,
172188
struct tree *merge_base,
173189
struct tree *side1,
174190
struct tree *side2)
175191
{
176-
/* TODO: Implement this using traverse_trees() */
177192
die("Not yet implemented.");
178193
}
179194

@@ -276,7 +291,19 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt,
276291
{
277292
struct object_id working_tree_oid;
278293

279-
collect_merge_info(opt, merge_base, side1, side2);
294+
if (collect_merge_info(opt, merge_base, side1, side2) != 0) {
295+
/*
296+
* TRANSLATORS: The %s arguments are: 1) tree hash of a merge
297+
* base, and 2-3) the trees for the two trees we're merging.
298+
*/
299+
err(opt, _("collecting merge info failed for trees %s, %s, %s"),
300+
oid_to_hex(&merge_base->object.oid),
301+
oid_to_hex(&side1->object.oid),
302+
oid_to_hex(&side2->object.oid));
303+
result->clean = -1;
304+
return;
305+
}
306+
280307
result->clean = detect_and_process_renames(opt, merge_base,
281308
side1, side2);
282309
process_entries(opt, &working_tree_oid);

merge-ort.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ struct commit;
77
struct tree;
88

99
struct merge_result {
10-
/* Whether the merge is clean */
10+
/*
11+
* Whether the merge is clean; possible values:
12+
* 1: clean
13+
* 0: not clean (merge conflicts)
14+
* <0: operation aborted prematurely. (object database
15+
* unreadable, disk full, etc.) Worktree may be left in an
16+
* inconsistent state if operation failed near the end.
17+
*/
1118
int clean;
1219

1320
/*

0 commit comments

Comments
 (0)