rerere: only return whether a path has conflicts or not

We currently return the exact number of conflict hunks a certain path has from the 'handle_paths' function. However all of its callers only care whether there are conflicts or not or if there is an error. Return only that information, and document that only that information is returned. This will simplify the code in the subsequent steps. Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Gummerer committed Aug 5, 2018 at 18:20 UTC 221444f5d11a8fac84514447c2902430e237759c
1 file changed +12 -11
rerere.c
+12 -11
@@ -393,12 +393,13 @@ static int is_cmarker(char *buf, int marker_char, int marker_size)
393 * one side of the conflict, NUL, the other side of the conflict,
394 * and NUL concatenated together.
395 *
396 - * Return the number of conflict hunks found.
396 + * Return 1 if conflict hunks are found, 0 if there are no conflict
397 + * hunks and -1 if an error occured.
398 */
399 static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_size)
400 {
401 git_SHA_CTX ctx;
401 - int hunk_no = 0;
402 + int has_conflicts = 0;
403 enum {
404 RR_CONTEXT = 0, RR_SIDE_1, RR_SIDE_2, RR_ORIGINAL
405 } hunk = RR_CONTEXT;
@@ -426,7 +427,7 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz
427 goto bad;
428 if (strbuf_cmp(&one, &two) > 0)
429 strbuf_swap(&one, &two);
429 - hunk_no++;
430 + has_conflicts = 1;
431 hunk = RR_CONTEXT;
432 rerere_io_putconflict('<', marker_size, io);
433 rerere_io_putmem(one.buf, one.len, io);
@@ -462,7 +463,7 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz
463 git_SHA1_Final(sha1, &ctx);
464 if (hunk != RR_CONTEXT)
465 return -1;
465 - return hunk_no;
466 + return has_conflicts;
467 }
468
469 /*
@@ -471,7 +472,7 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz
472 */
473 static int handle_file(const char *path, unsigned char *sha1, const char *output)
474 {
474 - int hunk_no = 0;
475 + int has_conflicts = 0;
476 struct rerere_io_file io;
477 int marker_size = ll_merge_marker_size(path);
478
@@ -491,7 +492,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
492 }
493 }
494
494 - hunk_no = handle_path(sha1, (struct rerere_io *)&io, marker_size);
495 + has_conflicts = handle_path(sha1, (struct rerere_io *)&io, marker_size);
496
497 fclose(io.input);
498 if (io.io.wrerror)
@@ -500,14 +501,14 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
501 if (io.io.output && fclose(io.io.output))
502 io.io.wrerror = error_errno(_("failed to flush '%s'"), path);
503
503 - if (hunk_no < 0) {
504 + if (has_conflicts < 0) {
505 if (output)
506 unlink_or_warn(output);
507 return error(_("could not parse conflict hunks in '%s'"), path);
508 }
509 if (io.io.wrerror)
510 return -1;
510 - return hunk_no;
511 + return has_conflicts;
512 }
513
514 /*
@@ -954,7 +955,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
955 mmfile_t mmfile[3] = {{NULL}};
956 mmbuffer_t result = {NULL, 0};
957 const struct cache_entry *ce;
957 - int pos, len, i, hunk_no;
958 + int pos, len, i, has_conflicts;
959 struct rerere_io_mem io;
960 int marker_size = ll_merge_marker_size(path);
961
@@ -1008,11 +1009,11 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
1009 * Grab the conflict ID and optionally write the original
1010 * contents with conflict markers out.
1011 */
1011 - hunk_no = handle_path(sha1, (struct rerere_io *)&io, marker_size);
1012 + has_conflicts = handle_path(sha1, (struct rerere_io *)&io, marker_size);
1013 strbuf_release(&io.input);
1014 if (io.io.output)
1015 fclose(io.io.output);
1015 - return hunk_no;
1016 + return has_conflicts;
1017 }
1018
1019 static int rerere_forget_one_path(const char *path, struct string_list *rr)