Skip to content

Commit a902edc

Browse files
chriscoolgitster
authored andcommitted
builtin/apply: make add_conflicted_stages_file() return -1 on error
To libify `git apply` functionality we have to signal errors to the caller instead of die()ing. To do that in a compatible manner with the rest of the error handling in "builtin/apply.c", add_conflicted_stages_file() should return -1 instead of calling die(). Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6e8df31 commit a902edc

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

builtin/apply.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4224,15 +4224,15 @@ static void create_one_file(struct apply_state *state,
42244224
die_errno(_("unable to write file '%s' mode %o"), path, mode);
42254225
}
42264226

4227-
static void add_conflicted_stages_file(struct apply_state *state,
4227+
static int add_conflicted_stages_file(struct apply_state *state,
42284228
struct patch *patch)
42294229
{
42304230
int stage, namelen;
42314231
unsigned ce_size, mode;
42324232
struct cache_entry *ce;
42334233

42344234
if (!state->update_index)
4235-
return;
4235+
return 0;
42364236
namelen = strlen(patch->new_name);
42374237
ce_size = cache_entry_size(namelen);
42384238
mode = patch->new_mode ? patch->new_mode : (S_IFREG | 0644);
@@ -4247,9 +4247,14 @@ static void add_conflicted_stages_file(struct apply_state *state,
42474247
ce->ce_flags = create_ce_flags(stage);
42484248
ce->ce_namelen = namelen;
42494249
hashcpy(ce->sha1, patch->threeway_stage[stage - 1].hash);
4250-
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)
4251-
die(_("unable to add cache entry for %s"), patch->new_name);
4250+
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
4251+
free(ce);
4252+
return error(_("unable to add cache entry for %s"),
4253+
patch->new_name);
4254+
}
42524255
}
4256+
4257+
return 0;
42534258
}
42544259

42554260
static void create_file(struct apply_state *state, struct patch *patch)
@@ -4263,9 +4268,10 @@ static void create_file(struct apply_state *state, struct patch *patch)
42634268
mode = S_IFREG | 0644;
42644269
create_one_file(state, path, mode, buf, size);
42654270

4266-
if (patch->conflicted_threeway)
4267-
add_conflicted_stages_file(state, patch);
4268-
else
4271+
if (patch->conflicted_threeway) {
4272+
if (add_conflicted_stages_file(state, patch))
4273+
exit(128);
4274+
} else
42694275
add_index_file(state, path, mode, buf, size);
42704276
}
42714277

0 commit comments

Comments
 (0)