git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC 2/3] rerere: make recording of the preimage reusable

From
Johannes Sixt <j6t@kdbg.org>
Date
Nov 21, 2009, 19:01 UTC
Message-ID
<200911212001.06207.j6t@kdbg.org>
In-Reply-To
<200911212000.19326.j6t@kdbg.org>

This factors the code that computes the conflict hash and records the preimage into a helper function.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 rerere.c |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/rerere.c b/rerere.c
index 84d0bb7..11fef88 100644
--- a/rerere.c
+++ b/rerere.c
@@ -229,6 +229,25 @@ static int find_conflict(struct string_list *conflict)
 	return 0;
 }
 
+static int record_preimage(struct string_list *rr, const char *path, int force)
+{
+	unsigned char sha1[20];
+	char *hex;
+	int ret;
+
+	ret = handle_file(path, sha1, NULL);
+	if (ret < 1)
+		return -1;
+
+	hex = xstrdup(sha1_to_hex(sha1));
+	string_list_insert(path, rr)->util = hex;
+	if (mkdir(git_path("rr-cache/%s", hex), 0755) && !force)
+		return -1;
+
+	handle_file(path, NULL, rerere_path(hex, "preimage"));
+	return 0;
+}
+
 static int merge(const char *name, const char *path)
 {
 	int ret;
@@ -310,17 +329,8 @@ static int do_plain_rerere(struct string_list *rr,
 	for (i = 0; i < conflict.nr; i++) {
 		const char *path = conflict.items[i].string;
 		if (!string_list_has_string(rr, path)) {
-			unsigned char sha1[20];
-			char *hex;
-			int ret;
-			ret = handle_file(path, sha1, NULL);
-			if (ret < 1)
-				continue;
-			hex = xstrdup(sha1_to_hex(sha1));
-			string_list_insert(path, rr)->util = hex;
-			if (mkdir(git_path("rr-cache/%s", hex), 0755))
+			if (record_preimage(rr, path, 0))
 				continue;
-			handle_file(path, NULL, rerere_path(hex, "preimage"));
 			fprintf(stderr, "Recorded preimage for '%s'\n", path);
 		}
 	}
-- 
1.6.5.2.182.ge039a
Previous: Johannes SixtNext: Johannes Sixt
Message 3 of 7 in “git rerere unresolve file”
  1. 0/3 git rerere unresolve fileJohannes Sixt, Nov 21, 2009
  2. 1/3 rerere: keep a list of resolved files in MERGE_RRJohannes Sixt, Nov 21, 2009
  3. 2/3 rerere: make recording of the preimage reusableJohannes Sixt, Nov 21, 2009
  4. 3/3 git rerere unresolve file...Johannes Sixt, Nov 21, 2009
  5. Junio C HamanoNov 22, 2009
  6. Johannes SixtNov 22, 2009
  7. Nanako ShiraishiNov 24, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.