git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH v3 13/18] rerere: refactor "replay" part of do_plain_rerere()
Date: Fri, 17 Jul 2015 15:24:35 -0700	[thread overview]
Message-ID: <1437171880-21590-14-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1437171880-21590-1-git-send-email-gitster@pobox.com>

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>
---
 rerere.c | 75 ++++++++++++++++++++++++++++++++++------------------------------
 1 file changed, 40 insertions(+), 35 deletions(-)

diff --git a/rerere.c b/rerere.c
index 7ef951e..09b72ed 100644
--- a/rerere.c
+++ b/rerere.c
@@ -620,6 +620,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;
@@ -673,41 +711,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);
-- 
2.5.0-rc2-340-g0cccc16

  parent reply	other threads:[~2015-07-17 22:25 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-01  6:04 [PATCH v2 00/13] "rerere" minor clean-up Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 01/13] rerere: fix an off-by-one non-bug Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 02/13] rerere: plug conflict ID leaks Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 03/13] rerere: lift PATH_MAX limitation Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 04/13] rerere: write out each record of MERGE_RR in one go Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 05/13] rerere: report autoupdated paths only after actually updating them Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 06/13] rerere: drop want_sp parameter from is_cmarker() Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 07/13] rerere: stop looping unnecessarily Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 08/13] rerere: explain the rerere I/O abstraction Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 09/13] rerere: explain MERGE_RR management helpers Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 10/13] rerere: explain the primary codepath Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 11/13] rerere: explain "rerere forget" codepath Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 12/13] rerere: explain the remainder Junio C Hamano
2015-07-01  6:04 ` [PATCH v2 13/13] rerere: refactor "replay" part of do_plain_rerere() Junio C Hamano
2015-07-17 22:24 ` [PATCH v3 00/18] "rerere" preparatory clean-up Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 01/18] rerere: fix an off-by-one non-bug Junio C Hamano
2015-07-24 19:46     ` Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 02/18] rerere: plug conflict ID leaks Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 03/18] rerere: lift PATH_MAX limitation Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 04/18] rerere: write out each record of MERGE_RR in one go Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 05/18] rerere: report autoupdated paths only after actually updating them Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 06/18] rerere: drop want_sp parameter from is_cmarker() Junio C Hamano
2015-07-18  8:24     ` Philip Oakley
2015-07-18  8:47       ` Eric Sunshine
2015-07-17 22:24   ` [PATCH v3 07/18] rerere: stop looping unnecessarily Junio C Hamano
2015-07-24 20:06     ` Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 08/18] rerere: explain the rerere I/O abstraction Junio C Hamano
2015-07-24 20:42     ` Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 09/18] rerere: explain MERGE_RR management helpers Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 10/18] rerere: explain the primary codepath Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 11/18] rerere: explain "rerere forget" codepath Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 12/18] rerere: explain the remainder Junio C Hamano
2015-07-17 22:24   ` Junio C Hamano [this message]
2015-07-17 22:24   ` [PATCH v3 14/18] rerere: further de-dent do_plain_rerere() Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 15/18] rerere: further clarify do_rerere_one_path() Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 16/18] rerere: call conflict-ids IDs Junio C Hamano
2015-07-17 22:24   ` [PATCH v3 17/18] rerere: use "struct rerere_id" instead of "char *" for conflict ID Junio C Hamano
2015-07-18  8:47     ` Eric Sunshine
2015-07-17 22:24   ` [PATCH v3 18/18] rerere: un-nest merge() further Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1437171880-21590-14-git-send-email-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).