mirror of
https://github.com/git/git.git
synced 2024-10-30 22:07:53 +01:00
builtin/apply: make add_index_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_index_file() should return -1 instead of calling die(). Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
a902edceeb
commit
69e1609f81
1 changed files with 31 additions and 17 deletions
|
@ -4099,7 +4099,7 @@ static int remove_file(struct apply_state *state, struct patch *patch, int rmdir
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_index_file(struct apply_state *state,
|
static int add_index_file(struct apply_state *state,
|
||||||
const char *path,
|
const char *path,
|
||||||
unsigned mode,
|
unsigned mode,
|
||||||
void *buf,
|
void *buf,
|
||||||
|
@ -4111,7 +4111,7 @@ static void add_index_file(struct apply_state *state,
|
||||||
unsigned ce_size = cache_entry_size(namelen);
|
unsigned ce_size = cache_entry_size(namelen);
|
||||||
|
|
||||||
if (!state->update_index)
|
if (!state->update_index)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
ce = xcalloc(1, ce_size);
|
ce = xcalloc(1, ce_size);
|
||||||
memcpy(ce->name, path, namelen);
|
memcpy(ce->name, path, namelen);
|
||||||
|
@ -4122,20 +4122,32 @@ static void add_index_file(struct apply_state *state,
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
if (!skip_prefix(buf, "Subproject commit ", &s) ||
|
if (!skip_prefix(buf, "Subproject commit ", &s) ||
|
||||||
get_sha1_hex(s, ce->sha1))
|
get_sha1_hex(s, ce->sha1)) {
|
||||||
die(_("corrupt patch for submodule %s"), path);
|
free(ce);
|
||||||
|
return error(_("corrupt patch for submodule %s"), path);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!state->cached) {
|
if (!state->cached) {
|
||||||
if (lstat(path, &st) < 0)
|
if (lstat(path, &st) < 0) {
|
||||||
die_errno(_("unable to stat newly created file '%s'"),
|
free(ce);
|
||||||
path);
|
return error(_("unable to stat newly "
|
||||||
|
"created file '%s': %s"),
|
||||||
|
path, strerror(errno));
|
||||||
|
}
|
||||||
fill_stat_cache_info(ce, &st);
|
fill_stat_cache_info(ce, &st);
|
||||||
}
|
}
|
||||||
if (write_sha1_file(buf, size, blob_type, ce->sha1) < 0)
|
if (write_sha1_file(buf, size, blob_type, ce->sha1) < 0) {
|
||||||
die(_("unable to create backing store for newly created file %s"), path);
|
free(ce);
|
||||||
|
return error(_("unable to create backing store "
|
||||||
|
"for newly created file %s"), path);
|
||||||
}
|
}
|
||||||
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)
|
}
|
||||||
die(_("unable to add cache entry for %s"), path);
|
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
|
||||||
|
free(ce);
|
||||||
|
return error(_("unable to add cache entry for %s"), path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
|
static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
|
||||||
|
@ -4271,8 +4283,10 @@ static void create_file(struct apply_state *state, struct patch *patch)
|
||||||
if (patch->conflicted_threeway) {
|
if (patch->conflicted_threeway) {
|
||||||
if (add_conflicted_stages_file(state, patch))
|
if (add_conflicted_stages_file(state, patch))
|
||||||
exit(128);
|
exit(128);
|
||||||
} else
|
} else {
|
||||||
add_index_file(state, path, mode, buf, size);
|
if (add_index_file(state, path, mode, buf, size))
|
||||||
|
exit(128);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* phase zero is to remove, phase one is to create */
|
/* phase zero is to remove, phase one is to create */
|
||||||
|
|
Loading…
Reference in a new issue