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

[PATCH 06/20] diff-parseopt: convert --binary

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 5, 2019, 12:30 UTC
Message-ID
<20190305123026.7266-7-pclouds@gmail.com>
In-Reply-To
<20190305123026.7266-1-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/diff-options.txt |  2 +-
 diff.c                         | 21 ++++++++++++++++-----
 2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 915f2fec8b..6810c94fea 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -425,7 +425,7 @@ endif::git-format-patch[]
 
 --binary::
 	In addition to `--full-index`, output a binary diff that
-	can be applied with `git-apply`.
+	can be applied with `git-apply`. Implies `--patch`.
 
 --abbrev[=<n>]::
 	Instead of showing the full 40-byte hexadecimal object
diff --git a/diff.c b/diff.c
index 5195526db9..214728c892 100644
--- a/diff.c
+++ b/diff.c
@@ -4852,6 +4852,18 @@ static int diff_opt_anchored(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_binary(const struct option *opt,
+			   const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	BUG_ON_OPT_ARG(arg);
+	enable_patch_output(&options->output_format);
+	options->flags.binary = 1;
+	return 0;
+}
+
 static int diff_opt_break_rewrites(const struct option *opt,
 				   const char *arg, int unset)
 {
@@ -5116,6 +5128,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "compact-summary", options, NULL,
 			       N_("generate compact summary in diffstat"),
 			       PARSE_OPT_NOARG, diff_opt_compact_summary),
+		OPT_CALLBACK_F(0, "binary", options, NULL,
+			       N_("output a binary diff that can be applied"),
+			       PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_binary),
 		OPT_CALLBACK_F(0, "output-indicator-new",
 			       &options->output_indicators[OUTPUT_INDICATOR_NEW],
 			       N_("<char>"),
@@ -5229,11 +5244,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* flags options */
-	if (!strcmp(arg, "--binary")) {
-		enable_patch_output(&options->output_format);
-		options->flags.binary = 1;
-	}
-	else if (!strcmp(arg, "--full-index"))
+	if (!strcmp(arg, "--full-index"))
 		options->flags.full_index = 1;
 	else if (!strcmp(arg, "-a") || !strcmp(arg, "--text"))
 		options->flags.text = 1;
-- 
2.21.0.rc1.337.gdf7f8d0522
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 7 of 23 in “nd/diff-parseopt part 3”
  1. 00/20 nd/diff-parseopt part 3Nguyễn Thái Ngọc Duy, Mar 5, 2019
  2. 01/20 diff-parseopt: convert --[no-]indent-heuristicNguyễn Thái Ngọc Duy, Mar 5, 2019
  3. 02/20 diff-parseopt: convert --patienceNguyễn Thái Ngọc Duy, Mar 5, 2019
  4. 03/20 diff-parseopt: convert --histogramNguyễn Thái Ngọc Duy, Mar 5, 2019
  5. 04/20 diff-parseopt: convert --diff-algorithmNguyễn Thái Ngọc Duy, Mar 5, 2019
  6. 05/20 diff-parseopt: convert --anchoredNguyễn Thái Ngọc Duy, Mar 5, 2019
  7. 06/20 diff-parseopt: convert --binaryNguyễn Thái Ngọc Duy, Mar 5, 2019
  8. 07/20 diff-parseopt: convert --full-indexNguyễn Thái Ngọc Duy, Mar 5, 2019
  9. 08/20 diff-parseopt: convert -a|--textNguyễn Thái Ngọc Duy, Mar 5, 2019
  10. 09/20 diff-parseopt: convert -RNguyễn Thái Ngọc Duy, Mar 5, 2019
  11. 10/20 diff-parseopt: convert --[no-]followNguyễn Thái Ngọc Duy, Mar 5, 2019
  12. 11/20 diff-parseopt: convert --[no-]colorNguyễn Thái Ngọc Duy, Mar 5, 2019
  13. 12/20 diff-parseopt: convert --word-diffNguyễn Thái Ngọc Duy, Mar 5, 2019
  14. 13/20 diff-parseopt: convert --word-diff-regexNguyễn Thái Ngọc Duy, Mar 5, 2019
  15. 14/20 diff-parseopt: convert --color-wordsNguyễn Thái Ngọc Duy, Mar 5, 2019
  16. 15/20 diff-parseopt: convert --exit-codeNguyễn Thái Ngọc Duy, Mar 5, 2019
  17. 16/20 diff-parseopt: convert --quietNguyễn Thái Ngọc Duy, Mar 5, 2019
  18. Eric SunshineMar 5, 2019
  19. Duy NguyenMar 6, 2019
  20. 17/20 diff-parseopt: convert --ext-diffNguyễn Thái Ngọc Duy, Mar 5, 2019
  21. 18/20 diff-parseopt: convert --textconvNguyễn Thái Ngọc Duy, Mar 5, 2019
  22. 19/20 diff-parseopt: convert --ignore-submodulesNguyễn Thái Ngọc Duy, Mar 5, 2019
  23. 20/20 diff-parseopt: convert --submoduleNguyễn Thái Ngọc Duy, Mar 5, 2019

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.