[PATCH v3 18/18] rerere: un-nest merge() further

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
---
 rerere.c | 50 ++++++++++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/rerere.c b/rerere.c
index 469d8a8..e8d8c02 100644
--- a/rerere.c
+++ b/rerere.c
@@ -571,6 +571,7 @@ int rerere_remaining(struct string_list *merge_rr)
  */
 static int merge(const struct rerere_id *id, const char *path)
 {
+	FILE *f;
 	int ret;
 	mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0};
 	mmbuffer_t result = {NULL, 0};
@@ -579,8 +580,10 @@ static int merge(const struct rerere_id *id, const char *path)
 	 * Normalize the conflicts in path and write it out to
 	 * "thisimage" temporary file.
 	 */
-	if (handle_file(path, NULL, rerere_path(id, "thisimage")) < 0)
-		return 1;
+	if (handle_file(path, NULL, rerere_path(id, "thisimage")) < 0) {
+		ret = 1;
+		goto out;
+	}
 
 	if (read_mmfile(&cur, rerere_path(id, "thisimage")) ||
 	    read_mmfile(&base, rerere_path(id, "preimage")) ||
@@ -594,29 +597,28 @@ static int merge(const struct rerere_id *id, const char *path)
 	 * low-level merge driver settings.
 	 */
 	ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "", NULL);
-	if (!ret) {
-		FILE *f;
+	if (ret)
+		goto out;
 
-		/*
-		 * A successful replay of recorded resolution.
-		 * Mark that "postimage" was used to help gc.
-		 */
-		if (utime(rerere_path(id, "postimage"), NULL) < 0)
-			warning("failed utime() on %s: %s",
-				rerere_path(id, "postimage"),
-				strerror(errno));
-
-		/* Update "path" with the resolution */
-		f = fopen(path, "w");
-		if (!f)
-			return error("Could not open %s: %s", path,
-				     strerror(errno));
-		if (fwrite(result.ptr, result.size, 1, f) != 1)
-			error("Could not write %s: %s", path, strerror(errno));
-		if (fclose(f))
-			return error("Writing %s failed: %s", path,
-				     strerror(errno));
-	}
+	/*
+	 * A successful replay of recorded resolution.
+	 * Mark that "postimage" was used to help gc.
+	 */
+	if (utime(rerere_path(id, "postimage"), NULL) < 0)
+		warning("failed utime() on %s: %s",
+			rerere_path(id, "postimage"),
+			strerror(errno));
+
+	/* Update "path" with the resolution */
+	f = fopen(path, "w");
+	if (!f)
+		return error("Could not open %s: %s", path,
+			     strerror(errno));
+	if (fwrite(result.ptr, result.size, 1, f) != 1)
+		error("Could not write %s: %s", path, strerror(errno));
+	if (fclose(f))
+		return error("Writing %s failed: %s", path,
+			     strerror(errno));
 
 out:
 	free(cur.ptr);
-- 
2.5.0-rc2-340-g0cccc16

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]