allow callers of diff3 code to detect merge conflicts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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 *);