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

[PATCH 2/4] diff.c: return filepair from diff_unmerge()

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 24, 2011, 20:51 UTC
Message-ID
<1303678289-27627-3-git-send-email-gitster@pobox.com>
In-Reply-To
<1303678289-27627-1-git-send-email-gitster@pobox.com>

The underlying diff_queue() returns diff_filepair so that the caller can further add information to it, and the helper function diff_unmerge() utilizes the feature itself, but does not expose it to its callers, which was kind of selfish.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff.c |   13 ++++++++-----
 diff.h |    2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/diff.c b/diff.c
index 9a5c77c..4c34c64 100644
--- a/diff.c
+++ b/diff.c
@@ -4308,20 +4308,23 @@ void diff_change(struct diff_options *options,
 		DIFF_OPT_SET(options, HAS_CHANGES);
 }
 
-void diff_unmerge(struct diff_options *options,
-		  const char *path,
-		  unsigned mode, const unsigned char *sha1)
+struct diff_filepair *diff_unmerge(struct diff_options *options,
+				   const char *path,
+				   unsigned mode, const unsigned char *sha1)
 {
+	struct diff_filepair *pair;
 	struct diff_filespec *one, *two;
 
 	if (options->prefix &&
 	    strncmp(path, options->prefix, options->prefix_length))
-		return;
+		return NULL;
 
 	one = alloc_filespec(path);
 	two = alloc_filespec(path);
 	fill_filespec(one, sha1, mode);
-	diff_queue(&diff_queued_diff, one, two)->is_unmerged = 1;
+	pair = diff_queue(&diff_queued_diff, one, two);
+	pair->is_unmerged = 1;
+	return pair;
 }
 
 static char *run_textconv(const char *pgm, struct diff_filespec *spec,
diff --git a/diff.h b/diff.h
index bf2f44d..f51a8ee 100644
--- a/diff.h
+++ b/diff.h
@@ -209,7 +209,7 @@ extern void diff_change(struct diff_options *,
 			const char *fullpath,
 			unsigned dirty_submodule1, unsigned dirty_submodule2);
 
-extern void diff_unmerge(struct diff_options *,
+extern struct diff_filepair *diff_unmerge(struct diff_options *,
 			 const char *path,
 			 unsigned mode,
 			 const unsigned char *sha1);
-- 
1.7.5
Previous: Junio C HamanoNext: Thiago Farina
Message 3 of 8 in “Fix diff-files output for unmerged paths”
  1. 0/4 Fix diff-files output for unmerged pathsJunio C Hamano, Apr 24, 2011
  2. 1/4 test: use $_z40 from test-libJunio C Hamano, Apr 24, 2011
  3. 2/4 diff.c: return filepair from diff_unmerge()Junio C Hamano, Apr 24, 2011
  4. Thiago FarinaApr 24, 2011
  5. Junio C HamanoApr 25, 2011
  6. 3/4 diff: remove often unused parameters from diff_unmerge()Junio C Hamano, Apr 24, 2011
  7. 4/4 diff-files: show unmerged entries correctlyJunio C Hamano, Apr 24, 2011
  8. Fix "add -u" that sometimes fails to resolve unmerged pathsJunio C Hamano, Apr 24, 2011

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.