summaryrefslogtreecommitdiff
path: root/rerere.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-06-30 19:36:24 -0700
committerJunio C Hamano <gitster@pobox.com>2015-07-24 16:02:37 -0700
commit8e7768b2de8bfdf82cde565d2f42e8d7f91e74e0 (patch)
tree5b237bf896f50cf904f1cae366f3bf5173ab78d5 /rerere.c
parente828de826bd0b852337b9625354c7c73d8de20c0 (diff)
downloadgit-8e7768b2de8bfdf82cde565d2f42e8d7f91e74e0.tar.gz
rerere: refactor "replay" part of do_plain_rerere()
Extract the body of a loop that attempts to replay recorded resolution for each conflicted path into a helper function, not because I want to call it from multiple places later, but because the logic has become too deeply nested and hard to read. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'rerere.c')
-rw-r--r--rerere.c75
1 files changed, 40 insertions, 35 deletions
diff --git a/rerere.c b/rerere.c
index e167670eb4..1d0f69d815 100644
--- a/rerere.c
+++ b/rerere.c
@@ -629,6 +629,44 @@ static void update_paths(struct string_list *update)
rollback_lock_file(&index_lock);
}
+/*
+ * The path indicated by rr_item may still have conflict for which we
+ * have a recorded resolution, in which case replay it and optionally
+ * update it. Or it may have been resolved by the user and we may
+ * only have the preimage for that conflict, in which case the result
+ * needs to be recorded as a resolution in a postimage file.
+ */
+static void do_rerere_one_path(struct string_list_item *rr_item,
+ struct string_list *update)
+{
+ const char *path = rr_item->string;
+ const char *name = (const char *)rr_item->util;
+
+ /* Is there a recorded resolution we could attempt to apply? */
+ if (has_rerere_resolution(name)) {
+ if (merge(name, path))
+ return; /* failed to replay */
+
+ if (rerere_autoupdate)
+ string_list_insert(update, path);
+ else
+ fprintf(stderr,
+ "Resolved '%s' using previous resolution.\n",
+ path);
+ goto mark_resolved;
+ }
+
+ /* Let's see if the user has resolved it. */
+ if (handle_file(path, NULL, NULL))
+ return; /* not yet resolved */
+
+ copy_file(rerere_path(name, "postimage"), path, 0666);
+ fprintf(stderr, "Recorded resolution for '%s'.\n", path);
+mark_resolved:
+ free(rr_item->util);
+ rr_item->util = NULL;
+}
+
static int do_plain_rerere(struct string_list *rr, int fd)
{
struct string_list conflict = STRING_LIST_INIT_DUP;
@@ -682,41 +720,8 @@ static int do_plain_rerere(struct string_list *rr, int fd)
}
}
- /*
- * Some of the paths that had conflicts earlier might have
- * been resolved by the user. Others may be similar to a
- * conflict already that was resolved before.
- */
- for (i = 0; i < rr->nr; i++) {
- int ret;
- const char *path = rr->items[i].string;
- const char *name = (const char *)rr->items[i].util;
-
- /* Is there a recorded resolution we could attempt to apply? */
- if (has_rerere_resolution(name)) {
- if (merge(name, path))
- continue;
-
- if (rerere_autoupdate)
- string_list_insert(&update, path);
- else
- fprintf(stderr,
- "Resolved '%s' using previous resolution.\n",
- path);
- goto mark_resolved;
- }
-
- /* Let's see if the user has resolved it. */
- ret = handle_file(path, NULL, NULL);
- if (ret)
- continue;
-
- copy_file(rerere_path(name, "postimage"), path, 0666);
- fprintf(stderr, "Recorded resolution for '%s'.\n", path);
- mark_resolved:
- free(rr->items[i].util);
- rr->items[i].util = NULL;
- }
+ for (i = 0; i < rr->nr; i++)
+ do_rerere_one_path(&rr->items[i], &update);
if (update.nr)
update_paths(&update);