rerere: un-nest merge() further

By consistently using "upon failure, set 'ret' and jump to out"
pattern, flatten the function further.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Junio C Hamano 2015-07-06 15:32:53 -07:00
parent 1d51eced10
commit 15ed07d532
1 changed files with 25 additions and 23 deletions

View File

@ -580,6 +580,7 @@ int rerere_remaining(struct string_list *merge_rr)
*/ */
static int merge(const struct rerere_id *id, const char *path) static int merge(const struct rerere_id *id, const char *path)
{ {
FILE *f;
int ret; int ret;
mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0}; mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0};
mmbuffer_t result = {NULL, 0}; mmbuffer_t result = {NULL, 0};
@ -588,8 +589,10 @@ static int merge(const struct rerere_id *id, const char *path)
* Normalize the conflicts in path and write it out to * Normalize the conflicts in path and write it out to
* "thisimage" temporary file. * "thisimage" temporary file.
*/ */
if (handle_file(path, NULL, rerere_path(id, "thisimage")) < 0) if (handle_file(path, NULL, rerere_path(id, "thisimage")) < 0) {
return 1; ret = 1;
goto out;
}


if (read_mmfile(&cur, rerere_path(id, "thisimage")) || if (read_mmfile(&cur, rerere_path(id, "thisimage")) ||
read_mmfile(&base, rerere_path(id, "preimage")) || read_mmfile(&base, rerere_path(id, "preimage")) ||
@ -603,8 +606,8 @@ static int merge(const struct rerere_id *id, const char *path)
* low-level merge driver settings. * low-level merge driver settings.
*/ */
ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "", NULL); ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "", NULL);
if (!ret) { if (ret)
FILE *f; goto out;


/* /*
* A successful replay of recorded resolution. * A successful replay of recorded resolution.
@ -625,7 +628,6 @@ static int merge(const struct rerere_id *id, const char *path)
if (fclose(f)) if (fclose(f))
return error("Writing %s failed: %s", path, return error("Writing %s failed: %s", path,
strerror(errno)); strerror(errno));
}


out: out:
free(cur.ptr); free(cur.ptr);