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>
Junio C Hamano committed
Jul 6, 2015 at 15:32 UTC
15ed07d532db743a2a397a38bacc1f20e54b2c80
1 file changed
+26
-24
rerere.c
+26
-24
@@ -580,6 +580,7 @@ int rerere_remaining(struct string_list *merge_rr)
580
*/
581
static int merge(const struct rerere_id *id, const char *path)
582
{
583
+ FILE *f;
584
int ret;
585
mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0};
586
mmbuffer_t result = {NULL, 0};
@@ -588,8 +589,10 @@ static int merge(const struct rerere_id *id, const char *path)
589
* Normalize the conflicts in path and write it out to
590
* "thisimage" temporary file.
591
*/
591
- if (handle_file(path, NULL, rerere_path(id, "thisimage")) < 0)
592
- return 1;
592
+ if (handle_file(path, NULL, rerere_path(id, "thisimage")) < 0) {
593
+ ret = 1;
594
+ goto out;
595
+ }
596
597
if (read_mmfile(&cur, rerere_path(id, "thisimage")) ||
598
read_mmfile(&base, rerere_path(id, "preimage")) ||
@@ -603,29 +606,28 @@ static int merge(const struct rerere_id *id, const char *path)
606
* low-level merge driver settings.
607
*/
608
ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "", NULL);
606
- if (!ret) {
607
- FILE *f;
609
+ if (ret)
610
+ goto out;
611
609
- /*
610
- * A successful replay of recorded resolution.
611
- * Mark that "postimage" was used to help gc.
612
- */
613
- if (utime(rerere_path(id, "postimage"), NULL) < 0)
614
- warning("failed utime() on %s: %s",
615
- rerere_path(id, "postimage"),
616
- strerror(errno));
617
-
618
- /* Update "path" with the resolution */
619
- f = fopen(path, "w");
620
- if (!f)
621
- return error("Could not open %s: %s", path,
622
- strerror(errno));
623
- if (fwrite(result.ptr, result.size, 1, f) != 1)
624
- error("Could not write %s: %s", path, strerror(errno));
625
- if (fclose(f))
626
- return error("Writing %s failed: %s", path,
627
- strerror(errno));
628
- }
612
+ /*
613
+ * A successful replay of recorded resolution.
614
+ * Mark that "postimage" was used to help gc.
615
+ */
616
+ if (utime(rerere_path(id, "postimage"), NULL) < 0)
617
+ warning("failed utime() on %s: %s",
618
+ rerere_path(id, "postimage"),
619
+ strerror(errno));
620
+
621
+ /* Update "path" with the resolution */
622
+ f = fopen(path, "w");
623
+ if (!f)
624
+ return error("Could not open %s: %s", path,
625
+ strerror(errno));
626
+ if (fwrite(result.ptr, result.size, 1, f) != 1)
627
+ error("Could not write %s: %s", path, strerror(errno));
628
+ if (fclose(f))
629
+ return error("Writing %s failed: %s", path,
630
+ strerror(errno));
631
632
out:
633
free(cur.ptr);