Commit 57ee5d5084c5c07c321352b7412a51d2f89ef298

Stefan Sperling 2019-02-08T15:10:49

allow callers of diff3 code to detect merge conflicts

diff --git a/lib/diff3.c b/lib/diff3.c
index 2d7faf8..9e996be 100644
--- a/lib/diff3.c
+++ b/lib/diff3.c
@@ -263,8 +263,8 @@ done:
  * For merge(1).
  */
 const struct got_error *
-got_merge_diff3(int outfd, const char *p1, const char *p2, const char *p3,
-    const char *label1, const char *label3)
+got_merge_diff3(int *overlapcnt, int outfd, const char *p1, const char *p2,
+    const char *p3, const char *label1, const char *label3)
 {
 	const struct got_error *err = NULL;
 	char *dp13, *dp23, *path1, *path2, *path3;
@@ -275,6 +275,8 @@ got_merge_diff3(int outfd, const char *p1, const char *p2, const char *p3,
 	struct diff3_state *d3s;
 	int i;
 
+	*overlapcnt = 0;
+
 	SLIST_INIT(&temp_files);
 
 	d3s = calloc(1, sizeof(*d3s));
@@ -399,11 +401,12 @@ out:
 		if (d3s->fp[i])
 			fclose(d3s->fp[i]);
 	}
-	free(d3s);
 	if (err == NULL && diffb) {
 		if (buf_write_fd(diffb, outfd) < 0)
 			err = got_error_from_errno();
+		*overlapcnt = d3s->overlapcnt;
 	}
+	free(d3s);
 	buf_free(diffb);
 	return err;
 }
diff --git a/lib/got_lib_diff.h b/lib/got_lib_diff.h
index 0db5171..66906a1 100644
--- a/lib/got_lib_diff.h
+++ b/lib/got_lib_diff.h
@@ -140,5 +140,5 @@ const struct got_error *got_diff_blob_lines_changed(struct got_diff_changes **,
     struct got_blob_object *, struct got_blob_object *);
 void got_diff_free_changes(struct got_diff_changes *);
 
-const struct got_error *got_merge_diff3(int, const char *, const char *,
+const struct got_error *got_merge_diff3(int *, int, const char *, const char *,
     const char *, const char *, const char *);