diff options
author | Christian Couder <christian.couder@gmail.com> | 2016-08-08 23:03:18 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-08-11 12:41:47 -0700 |
commit | a902edceebd0a25a307163f050326bda8f494204 (patch) | |
tree | 8769abd10e4cc3e0d8cf9605c6976771be1c6c52 /builtin/apply.c | |
parent | 6e8df314692105e7d3e69f548440e4b817bf3211 (diff) | |
download | git-a902edceebd0a25a307163f050326bda8f494204.tar.gz |
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 <sunshine@sunshineco.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/apply.c')
-rw-r--r-- | builtin/apply.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/builtin/apply.c b/builtin/apply.c index 27fb6e20ab..ad0b87510b 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -4224,7 +4224,7 @@ static void create_one_file(struct apply_state *state, die_errno(_("unable to write file '%s' mode %o"), path, mode); } -static void add_conflicted_stages_file(struct apply_state *state, +static int add_conflicted_stages_file(struct apply_state *state, struct patch *patch) { int stage, namelen; @@ -4232,7 +4232,7 @@ static void add_conflicted_stages_file(struct apply_state *state, struct cache_entry *ce; if (!state->update_index) - return; + return 0; namelen = strlen(patch->new_name); ce_size = cache_entry_size(namelen); mode = patch->new_mode ? patch->new_mode : (S_IFREG | 0644); @@ -4247,9 +4247,14 @@ static void add_conflicted_stages_file(struct apply_state *state, ce->ce_flags = create_ce_flags(stage); ce->ce_namelen = namelen; hashcpy(ce->sha1, patch->threeway_stage[stage - 1].hash); - if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) - die(_("unable to add cache entry for %s"), patch->new_name); + if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) { + free(ce); + return error(_("unable to add cache entry for %s"), + patch->new_name); + } } + + return 0; } 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) mode = S_IFREG | 0644; create_one_file(state, path, mode, buf, size); - if (patch->conflicted_threeway) - add_conflicted_stages_file(state, patch); - else + if (patch->conflicted_threeway) { + if (add_conflicted_stages_file(state, patch)) + exit(128); + } else add_index_file(state, path, mode, buf, size); } |