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

[PATCH v3 09/11] rerere: move code related to "forget" together

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 6, 2016, 23:05 UTC
Message-ID
<1459983935-25267-10-git-send-email-gitster@pobox.com>
In-Reply-To
<1459983935-25267-1-git-send-email-gitster@pobox.com>

"rerere forget" is the only user of handle_cache() helper, which in turn is the only user of rerere_io that reads from an in-core buffer whose getline method is implemented as rerere_mem_getline(). Gather them together.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 rerere.c | 194 +++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 97 insertions(+), 97 deletions(-)
diff --git a/rerere.c b/rerere.c
index 3d4dd33..2b870e0 100644
--- a/rerere.c
+++ b/rerere.c
@@ -517,103 +517,6 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
 }
 
 /*
- * Subclass of rerere_io that reads from an in-core buffer that is a
- * strbuf
- */
-struct rerere_io_mem {
-	struct rerere_io io;
-	struct strbuf input;
-};
-
-/*
- * ... and its getline() method implementation
- */
-static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
-{
-	struct rerere_io_mem *io = (struct rerere_io_mem *)io_;
-	char *ep;
-	size_t len;
-
-	strbuf_release(sb);
-	if (!io->input.len)
-		return -1;
-	ep = memchr(io->input.buf, '\n', io->input.len);
-	if (!ep)
-		ep = io->input.buf + io->input.len;
-	else if (*ep == '\n')
-		ep++;
-	len = ep - io->input.buf;
-	strbuf_add(sb, io->input.buf, len);
-	strbuf_remove(&io->input, 0, len);
-	return 0;
-}
-
-static int handle_cache(const char *path, unsigned char *sha1, const char *output)
-{
-	mmfile_t mmfile[3] = {{NULL}};
-	mmbuffer_t result = {NULL, 0};
-	const struct cache_entry *ce;
-	int pos, len, i, hunk_no;
-	struct rerere_io_mem io;
-	int marker_size = ll_merge_marker_size(path);
-
-	/*
-	 * Reproduce the conflicted merge in-core
-	 */
-	len = strlen(path);
-	pos = cache_name_pos(path, len);
-	if (0 <= pos)
-		return -1;
-	pos = -pos - 1;
-
-	while (pos < active_nr) {
-		enum object_type type;
-		unsigned long size;
-
-		ce = active_cache[pos++];
-		if (ce_namelen(ce) != len || memcmp(ce->name, path, len))
-			break;
-		i = ce_stage(ce) - 1;
-		if (!mmfile[i].ptr) {
-			mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size);
-			mmfile[i].size = size;
-		}
-	}
-	for (i = 0; i < 3; i++)
-		if (!mmfile[i].ptr && !mmfile[i].size)
-			mmfile[i].ptr = xstrdup("");
-
-	/*
-	 * NEEDSWORK: handle conflicts from merges with
-	 * merge.renormalize set, too
-	 */
-	ll_merge(&result, path, &mmfile[0], NULL,
-		 &mmfile[1], "ours",
-		 &mmfile[2], "theirs", NULL);
-	for (i = 0; i < 3; i++)
-		free(mmfile[i].ptr);
-
-	memset(&io, 0, sizeof(io));
-	io.io.getline = rerere_mem_getline;
-	if (output)
-		io.io.output = fopen(output, "w");
-	else
-		io.io.output = NULL;
-	strbuf_init(&io.input, 0);
-	strbuf_attach(&io.input, result.ptr, result.size, result.size);
-
-	/*
-	 * Grab the conflict ID and optionally write the original
-	 * contents with conflict markers out.
-	 */
-	hunk_no = handle_path(sha1, (struct rerere_io *)&io, marker_size);
-	strbuf_release(&io.input);
-	if (io.io.output)
-		fclose(io.io.output);
-	return hunk_no;
-}
-
-/*
  * Look at a cache entry at "i" and see if it is not conflicting,
  * conflicting and we are willing to handle, or conflicting and
  * we are unable to handle, and return the determination in *type.
@@ -1005,6 +908,103 @@ int rerere(int flags)
 	return status;
 }
 
+/*
+ * Subclass of rerere_io that reads from an in-core buffer that is a
+ * strbuf
+ */
+struct rerere_io_mem {
+	struct rerere_io io;
+	struct strbuf input;
+};
+
+/*
+ * ... and its getline() method implementation
+ */
+static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
+{
+	struct rerere_io_mem *io = (struct rerere_io_mem *)io_;
+	char *ep;
+	size_t len;
+
+	strbuf_release(sb);
+	if (!io->input.len)
+		return -1;
+	ep = memchr(io->input.buf, '\n', io->input.len);
+	if (!ep)
+		ep = io->input.buf + io->input.len;
+	else if (*ep == '\n')
+		ep++;
+	len = ep - io->input.buf;
+	strbuf_add(sb, io->input.buf, len);
+	strbuf_remove(&io->input, 0, len);
+	return 0;
+}
+
+static int handle_cache(const char *path, unsigned char *sha1, const char *output)
+{
+	mmfile_t mmfile[3] = {{NULL}};
+	mmbuffer_t result = {NULL, 0};
+	const struct cache_entry *ce;
+	int pos, len, i, hunk_no;
+	struct rerere_io_mem io;
+	int marker_size = ll_merge_marker_size(path);
+
+	/*
+	 * Reproduce the conflicted merge in-core
+	 */
+	len = strlen(path);
+	pos = cache_name_pos(path, len);
+	if (0 <= pos)
+		return -1;
+	pos = -pos - 1;
+
+	while (pos < active_nr) {
+		enum object_type type;
+		unsigned long size;
+
+		ce = active_cache[pos++];
+		if (ce_namelen(ce) != len || memcmp(ce->name, path, len))
+			break;
+		i = ce_stage(ce) - 1;
+		if (!mmfile[i].ptr) {
+			mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size);
+			mmfile[i].size = size;
+		}
+	}
+	for (i = 0; i < 3; i++)
+		if (!mmfile[i].ptr && !mmfile[i].size)
+			mmfile[i].ptr = xstrdup("");
+
+	/*
+	 * NEEDSWORK: handle conflicts from merges with
+	 * merge.renormalize set, too?
+	 */
+	ll_merge(&result, path, &mmfile[0], NULL,
+		 &mmfile[1], "ours",
+		 &mmfile[2], "theirs", NULL);
+	for (i = 0; i < 3; i++)
+		free(mmfile[i].ptr);
+
+	memset(&io, 0, sizeof(io));
+	io.io.getline = rerere_mem_getline;
+	if (output)
+		io.io.output = fopen(output, "w");
+	else
+		io.io.output = NULL;
+	strbuf_init(&io.input, 0);
+	strbuf_attach(&io.input, result.ptr, result.size, result.size);
+
+	/*
+	 * Grab the conflict ID and optionally write the original
+	 * contents with conflict markers out.
+	 */
+	hunk_no = handle_path(sha1, (struct rerere_io *)&io, marker_size);
+	strbuf_release(&io.input);
+	if (io.io.output)
+		fclose(io.io.output);
+	return hunk_no;
+}
+
 static int rerere_forget_one_path(const char *path, struct string_list *rr)
 {
 	const char *filename;
-- 
2.8.1-273-ga2cd0f9
Previous: Junio C HamanoNext: Junio C Hamano
Message 30 of 32 in “saving and replaying multiple variants with rerere”
  1. 0/7 saving and replaying multiple variants with rerereJunio C Hamano, Sep 14, 2015
  2. 1/7 rerere: split conflict ID furtherJunio C Hamano, Sep 14, 2015
  3. 2/7 rerere: scan $GIT_DIR/rr-cache/$ID when instantiating a rerere_idJunio C Hamano, Sep 14, 2015
  4. 3/7 rerere: handle leftover rr-cache/$ID directory and postimage filesJunio C Hamano, Sep 14, 2015
  5. 4/7 rerere: delay the recording of preimageJunio C Hamano, Sep 14, 2015
  6. 5/7 rerere: allow multiple variants to existJunio C Hamano, Sep 14, 2015
  7. 6/7 t4200: rerere a merge with two identical conflictsJunio C Hamano, Sep 14, 2015
  8. 7/7 rerere: do use multiple variantsJunio C Hamano, Sep 14, 2015
  9. 00/11 saving and replaying multiple variants with rerereJunio C Hamano, Mar 28, 2016
  10. 01/11 rerere: split conflict ID furtherJunio C Hamano, Mar 28, 2016
  11. 02/11 rerere: scan $GIT_DIR/rr-cache/$ID when instantiating a rerere_idJunio C Hamano, Mar 28, 2016
  12. 03/11 rerere: handle leftover rr-cache/$ID directory and postimage filesJunio C Hamano, Mar 28, 2016
  13. 04/11 rerere: delay the recording of preimageJunio C Hamano, Mar 28, 2016
  14. 05/11 rerere: allow multiple variants to existJunio C Hamano, Mar 28, 2016
  15. 06/11 t4200: rerere a merge with two identical conflictsJunio C Hamano, Mar 28, 2016
  16. 07/11 rerere: do use multiple variantsJunio C Hamano, Mar 28, 2016
  17. 08/11 rerere: gc and clearJunio C Hamano, Mar 28, 2016
  18. 09/11 rerere: move code related to "forget" togetherJunio C Hamano, Mar 28, 2016
  19. 10/11 rerere: split code to call ll_merge() furtherJunio C Hamano, Mar 28, 2016
  20. 11/11 rerere: adjust 'forget' to multi-variant world orderJunio C Hamano, Mar 28, 2016
  21. 00/11 saving and replaying multiple variants with rerereJunio C Hamano, Apr 6, 2016
  22. 01/11 rerere: split conflict ID furtherJunio C Hamano, Apr 6, 2016
  23. 02/11 rerere: scan $GIT_DIR/rr-cache/$ID when instantiating a rerere_idJunio C Hamano, Apr 6, 2016
  24. 03/11 rerere: handle leftover rr-cache/$ID directory and postimage filesJunio C Hamano, Apr 6, 2016
  25. 04/11 rerere: delay the recording of preimageJunio C Hamano, Apr 6, 2016
  26. 05/11 rerere: allow multiple variants to existJunio C Hamano, Apr 6, 2016
  27. 06/11 t4200: rerere a merge with two identical conflictsJunio C Hamano, Apr 6, 2016
  28. 07/11 rerere: do use multiple variantsJunio C Hamano, Apr 6, 2016
  29. 08/11 rerere: gc and clearJunio C Hamano, Apr 6, 2016
  30. 09/11 rerere: move code related to "forget" togetherJunio C Hamano, Apr 6, 2016
  31. 10/11 rerere: split code to call ll_merge() furtherJunio C Hamano, Apr 6, 2016
  32. 11/11 rerere: adjust 'forget' to multi-variant world orderJunio C Hamano, Apr 6, 2016

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.