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

[PATCH 2/8] apply: accept --threeway command line option

From
Junio C Hamano <gitster@pobox.com>
Date
May 10, 2012, 06:02 UTC
Message-ID
<1336629745-22436-3-git-send-email-gitster@pobox.com>
In-Reply-To
<1336629745-22436-1-git-send-email-gitster@pobox.com>

This is the beginning of teaching the three-way merge fallback logic "git am -3" uses to the underlying "git apply". It only implements the command line parsing part, and does not do anything interesting yet.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/apply.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index fc7f07b..cb6aad5 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -46,6 +46,7 @@ static int apply_with_reject;
 static int apply_verbosely;
 static int allow_overlap;
 static int no_add;
+static int threeway;
 static const char *fake_ancestor;
 static int line_termination = '\n';
 static unsigned int p_context = UINT_MAX;
@@ -3024,6 +3025,11 @@ static void prepare_fn_table(struct patch *patch)
 	}
 }
 
+static int try_threeway_fallback(struct image *image, struct patch *patch)
+{
+	return -1; /* for now */
+}
+
 static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *ce)
 {
 	struct strbuf buf = STRBUF_INIT;
@@ -3068,7 +3074,8 @@ static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *
 
 	if (apply_fragments(&image, patch) < 0) {
 		/* Note: with --reject, the above call succeeds. */
-		return -1;
+		if (!threeway || try_threeway_fallback(&image, patch) < 0)
+			return -1;
 	}
 	patch->result = image.buf;
 	patch->resultsize = image.len;
@@ -3981,6 +3988,8 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
 			"apply a patch without touching the working tree"),
 		OPT_BOOLEAN(0, "apply", &force_apply,
 			"also apply the patch (use with --stat/--summary/--check)"),
+		OPT_BOOL(0, "threeway", &threeway,
+			 "attempt three-way merge if a patch does not apply"),
 		OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
 			"build a temporary index based on embedded index information"),
 		{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,
-- 
1.7.10.1.562.gfc79b1c
Previous: Junio C HamanoNext: Nguyen Thai Ngoc Duy
Message 3 of 19 in “"git apply --threeway"”
  1. 0/8 "git apply --threeway"Junio C Hamano, May 10, 2012
  2. 1/8 apply: reformat commentJunio C Hamano, May 10, 2012
  3. 2/8 apply: accept --threeway command line optionJunio C Hamano, May 10, 2012
  4. Nguyen Thai Ngoc DuyMay 10, 2012
  5. Junio C HamanoMay 10, 2012
  6. 3/8 apply: split load_preimage() helper function outJunio C Hamano, May 10, 2012
  7. 4/8 apply: clear_image() clears things a bit moreJunio C Hamano, May 10, 2012
  8. 5/8 apply: refactor read_file_or_gitlink()Junio C Hamano, May 10, 2012
  9. 6/8 apply: fall back on three-way mergeJunio C Hamano, May 10, 2012
  10. Matthieu MoyMay 10, 2012
  11. Junio C HamanoMay 10, 2012
  12. Matthieu MoyMay 10, 2012
  13. Jeff KingMay 10, 2012
  14. Junio C HamanoMay 10, 2012
  15. Jeff KingMay 10, 2012
  16. 7/8 apply: plug the three-way merge logic inJunio C Hamano, May 10, 2012
  17. 8/8 apply: register conflicted stages to the indexJunio C Hamano, May 10, 2012
  18. Matthieu MoyMay 10, 2012
  19. Junio C HamanoMay 10, 2012

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.