{"thread":{"id":"66693","subject":"[PATCH v2] builtin/diff-files: convert ad hoc option parsing to parse-options API","startedAt":"2026-10-28T19:14:00Z","lastAt":"2026-11-02T14:16:03Z","messageCount":8,"participants":["Edson","Junio C Hamano","Wasswa Edson"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"556694","messageId":"20261028191400.799-1-edsonwasswa54@gmail.com","threadId":"66693","inReplyTo":"20261028170432.3524465-1-gitster@pobox.com","subject":"[PATCH v2] builtin/diff-files: convert ad hoc option parsing to parse-options API","fromName":"Edson","fromEmail":"edsonwasswa54@gmail.com","sentAt":"2026-10-28T19:14:00Z","receivedAt":"2026-10-28T19:14:00Z","isPatch":true,"sender":{"key":"edsonwasswa54@gmail.com","avatar":null},"body":"From: Wasswa Edson <edsonwasswa54@gmail.com>\n\nThe cmd_diff_files() function manually parses --base, --ours, --theirs,\nand -q options using a hand-rolled loop with strcmp() calls. This is\ninconsistent with the rest of Git's codebase and lacks features provided\nby the parse-options API such as auto-generated help text, git completion\nsupport, and option abbreviation.\n\nChanges since v1:\n- Fixed author name to \"Wasswa Edson\" for DCO compliance\n- Removed vague \"error-prone\" claim, replaced with specific justification\n- Removed unnecessary block scope around option array\n- Changed from function-scope static to regular local variable\n\nConvert this to use the parse-options API by:\n- Adding option definitions using OPT_* macros\n- Removing the manual parsing loop\n- Using parse_options() for consistent argument handling\n\nThe --base, --ours, and --theirs options use PARSE_OPT_NONEG to prevent\nnegated forms (--no-base, etc.) which are not meaningful for merge stage\nselection. This follows the pattern used in builtin/checkout.c for similar\nstage selection options.\n\nThis makes the code more maintainable and brings it in line with Git's\ncoding standards.\n\nSigned-off-by: Wasswa Edson <edsonwasswa54@gmail.com>\n---\n builtin/diff-files.c | 28 +++++++++++++++-------------\n 1 file changed, 15 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/diff-files.c b/builtin/diff-files.c\nindex ea91347ce2..bd761443b9 100644\n--- a/builtin/diff-files.c\n+++ b/builtin/diff-files.c\n@@ -14,6 +14,7 @@\n #include \"commit.h\"\n #include \"preload-index.h\"\n #include \"revision.h\"\n+#include \"parse-options.h\"\n \n static const char diff_files_usage[] =\n \"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]\"\n@@ -48,19 +49,20 @@ int cmd_diff_files(int argc,\n \tprefix = precompose_argv_prefix(argc, argv, prefix);\n \n \targc = setup_revisions(argc, argv, &rev, NULL);\n-\twhile (1 < argc && argv[1][0] == '-') {\n-\t\tif (!strcmp(argv[1], \"--base\"))\n-\t\t\trev.max_count = 1;\n-\t\telse if (!strcmp(argv[1], \"--ours\"))\n-\t\t\trev.max_count = 2;\n-\t\telse if (!strcmp(argv[1], \"--theirs\"))\n-\t\t\trev.max_count = 3;\n-\t\telse if (!strcmp(argv[1], \"-q\"))\n-\t\t\toptions |= DIFF_SILENT_ON_REMOVED;\n-\t\telse\n-\t\t\tusage(diff_files_usage);\n-\t\targv++; argc--;\n-\t}\n+\n+\tstruct option diff_files_options[] = {\n+\t\tOPT_SET_INT_F(0, \"base\", &rev.max_count,\n+\t\t\t      N_(\"show base version\"), 1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"ours\", &rev.max_count,\n+\t\t\t      N_(\"show our version\"), 2, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"theirs\", &rev.max_count,\n+\t\t\t      N_(\"show their version\"), 3, PARSE_OPT_NONEG),\n+\t\tOPT_BIT('q', NULL, &options,\n+\t\t       N_(\"be quiet\"), DIFF_SILENT_ON_REMOVED),\n+\t\tOPT_END()\n+\t};\n+\targc = parse_options(argc, argv, prefix, diff_files_options,\n+\t\t\t     diff_files_usage, 0);\n \tif (!rev.diffopt.output_format)\n \t\trev.diffopt.output_format = DIFF_FORMAT_RAW;\n \trev.diffopt.rotate_to_strict = 1;\n-- \n2.46.0.windows.1\n\n\n"},{"id":"556695","messageId":"20261028192647.976-1-edsonwasswa54@gmail.com","threadId":"66693","inReplyTo":"20261028170432.3524465-1-gitster@pobox.com","subject":"[PATCH v3] builtin/diff-files: convert ad hoc option parsing to parse-options API","fromName":"Edson","fromEmail":"edsonwasswa54@gmail.com","sentAt":"2026-10-28T19:26:47Z","receivedAt":"2026-10-28T19:26:47Z","isPatch":true,"sender":{"key":"edsonwasswa54@gmail.com","avatar":null},"body":"From: Wasswa Edson <edsonwasswa54@gmail.com>\n\nThe cmd_diff_files() function manually parses --base, --ours, --theirs,\nand -q options using a hand-rolled loop with strcmp() calls. This is\ninconsistent with the rest of Git's codebase and lacks features provided\nby the parse-options API such as auto-generated help text, git completion\nsupport, and option abbreviation.\n\nConvert this to use the parse-options API by:\n- Adding option definitions using OPT_* macros\n- Removing the manual parsing loop\n- Using parse_options() for consistent argument handling\n\nThe --base, --ours, and --theirs options use PARSE_OPT_NONEG to prevent\nnegated forms (--no-base, etc.) which are not meaningful for merge stage\nselection. This follows the pattern used in builtin/checkout.c for similar\nstage selection options.\n\nThis makes the code more maintainable and brings it in line with Git's\ncoding standards.\n\nSigned-off-by: Wasswa Edson <edsonwasswa54@gmail.com>\n---\n builtin/diff-files.c | 28 +++++++++++++++-------------\n 1 file changed, 15 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/diff-files.c b/builtin/diff-files.c\nindex ea91347ce2..bd761443b9 100644\n--- a/builtin/diff-files.c\n+++ b/builtin/diff-files.c\n@@ -14,6 +14,7 @@\n #include \"commit.h\"\n #include \"preload-index.h\"\n #include \"revision.h\"\n+#include \"parse-options.h\"\n \n static const char diff_files_usage[] =\n \"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]\"\n@@ -48,19 +49,20 @@ int cmd_diff_files(int argc,\n \tprefix = precompose_argv_prefix(argc, argv, prefix);\n \n \targc = setup_revisions(argc, argv, &rev, NULL);\n-\twhile (1 < argc && argv[1][0] == '-') {\n-\t\tif (!strcmp(argv[1], \"--base\"))\n-\t\t\trev.max_count = 1;\n-\t\telse if (!strcmp(argv[1], \"--ours\"))\n-\t\t\trev.max_count = 2;\n-\t\telse if (!strcmp(argv[1], \"--theirs\"))\n-\t\t\trev.max_count = 3;\n-\t\telse if (!strcmp(argv[1], \"-q\"))\n-\t\t\toptions |= DIFF_SILENT_ON_REMOVED;\n-\t\telse\n-\t\t\tusage(diff_files_usage);\n-\t\targv++; argc--;\n-\t}\n+\n+\tstruct option diff_files_options[] = {\n+\t\tOPT_SET_INT_F(0, \"base\", &rev.max_count,\n+\t\t\t      N_(\"show base version\"), 1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"ours\", &rev.max_count,\n+\t\t\t      N_(\"show our version\"), 2, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"theirs\", &rev.max_count,\n+\t\t\t      N_(\"show their version\"), 3, PARSE_OPT_NONEG),\n+\t\tOPT_BIT('q', NULL, &options,\n+\t\t       N_(\"be quiet\"), DIFF_SILENT_ON_REMOVED),\n+\t\tOPT_END()\n+\t};\n+\targc = parse_options(argc, argv, prefix, diff_files_options,\n+\t\t\t     diff_files_usage, 0);\n \tif (!rev.diffopt.output_format)\n \t\trev.diffopt.output_format = DIFF_FORMAT_RAW;\n \trev.diffopt.rotate_to_strict = 1;\n-- \n2.46.0.windows.1\n\n\n"},{"id":"556715","messageId":"xmqq4ie579ac.fsf@gitster.g","threadId":"66693","inReplyTo":"20261028192647.976-1-edsonwasswa54@gmail.com","subject":"Re: [PATCH v3] builtin/diff-files: convert ad hoc option parsing to parse-options API","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-28T22:24:59Z","receivedAt":"2026-10-28T22:24:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Edson <edsonwasswa54@gmail.com> writes:\n\n> From: Wasswa Edson <edsonwasswa54@gmail.com>\n>\n> The cmd_diff_files() function manually parses --base, --ours, --theirs,\n> and -q options using a hand-rolled loop with strcmp() calls. This is\n> inconsistent with the rest of Git's codebase and lacks features provided\n> by the parse-options API such as auto-generated help text, git completion\n> support, and option abbreviation.\n>\n> Convert this to use the parse-options API by:\n> - Adding option definitions using OPT_* macros\n> - Removing the manual parsing loop\n> - Using parse_options() for consistent argument handling\n>\n> The --base, --ours, and --theirs options use PARSE_OPT_NONEG to prevent\n> negated forms (--no-base, etc.) which are not meaningful for merge stage\n> selection. This follows the pattern used in builtin/checkout.c for similar\n> stage selection options.\n>\n> This makes the code more maintainable and brings it in line with Git's\n> coding standards.\n>\n> Signed-off-by: Wasswa Edson <edsonwasswa54@gmail.com>\n\nNicely described.\n\n$ make DEVELOPER=YesPlease builtin/diff-files.o\n\nis your friend.\n\n>  \n>  static const char diff_files_usage[] =\n>  \"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]\"\n> @@ -48,19 +49,20 @@ int cmd_diff_files(int argc,\n>  \tprefix = precompose_argv_prefix(argc, argv, prefix);\n>  \n>  \targc = setup_revisions(argc, argv, &rev, NULL);\n> -\twhile (1 < argc && argv[1][0] == '-') {\n> -\t\tif (!strcmp(argv[1], \"--base\"))\n> -\t\t\trev.max_count = 1;\n> -\t\telse if (!strcmp(argv[1], \"--ours\"))\n> -\t\t\trev.max_count = 2;\n> -\t\telse if (!strcmp(argv[1], \"--theirs\"))\n> -\t\t\trev.max_count = 3;\n> -\t\telse if (!strcmp(argv[1], \"-q\"))\n> -\t\t\toptions |= DIFF_SILENT_ON_REMOVED;\n> -\t\telse\n> -\t\t\tusage(diff_files_usage);\n> -\t\targv++; argc--;\n> -\t}\n> +\n> +\tstruct option diff_files_options[] = {\n> +\t\tOPT_SET_INT_F(0, \"base\", &rev.max_count,\n> +\t\t\t      N_(\"show base version\"), 1, PARSE_OPT_NONEG),\n> +\t\tOPT_SET_INT_F(0, \"ours\", &rev.max_count,\n> +\t\t\t      N_(\"show our version\"), 2, PARSE_OPT_NONEG),\n> +\t\tOPT_SET_INT_F(0, \"theirs\", &rev.max_count,\n> +\t\t\t      N_(\"show their version\"), 3, PARSE_OPT_NONEG),\n> +\t\tOPT_BIT('q', NULL, &options,\n> +\t\t       N_(\"be quiet\"), DIFF_SILENT_ON_REMOVED),\n> +\t\tOPT_END()\n> +\t};\n\nMove this a lot higher.\n\nbuiltin/diff-files.c:53:9: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]\n   53 |         struct option diff_files_options[] = {\n\n\n> +\targc = parse_options(argc, argv, prefix, diff_files_options,\n> +\t\t\t     diff_files_usage, 0);\n\nparse_options() takes a NULL-terminated array of constant strings,\nbut diff_files_usage is a single constant string.\n\nbuiltin/diff-files.c:65:30: error: passing argument 5 of ‘parse_options’ from incompatible pointer type [-Wincompatible-pointer-types]\n   65 |                              diff_files_usage, 0);\n      |                              ^~~~~~~~~~~~~~~~\n      |                              |\n      |                              const char *\nIn file included from builtin/diff-files.c:17:\n./parse-options.h:424:38: note: expected ‘const char * const*’ but argument is of type ‘const char *’\n  424 |                   const char * const usagestr[],\n      |                   ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~\n\nAs I said in my earlier message, conversion of parse-options API\nrequires adjustment of usage string.\n\n>  \tif (!rev.diffopt.output_format)\n>  \t\trev.diffopt.output_format = DIFF_FORMAT_RAW;\n>  \trev.diffopt.rotate_to_strict = 1;\n\n"},{"id":"556828","messageId":"20261029203904.432-1-edsonwasswa54@gmail.com","threadId":"66693","inReplyTo":"20261028170432.3524465-1-gitster@pobox.com","subject":"[PATCH v4] builtin/diff-files: convert ad hoc option parsing to parse-options API","fromName":"Edson","fromEmail":"edsonwasswa54@gmail.com","sentAt":"2026-10-29T20:39:03Z","receivedAt":"2026-10-29T20:39:03Z","isPatch":true,"sender":{"key":"edsonwasswa54@gmail.com","avatar":null},"body":"From: Wasswa Edson <edsonwasswa54@gmail.com>\n\nThe cmd_diff_files() function manually parses --base, --ours, --theirs,\nand -q options using a hand-rolled loop with strcmp() calls. This is\ninconsistent with the rest of Git's codebase and lacks features provided\nby the parse-options API such as auto-generated help text, git completion\nsupport, and option abbreviation.\n\nConvert this to use the parse-options API by:\n- Adding option definitions using OPT_* macros\n- Removing the manual parsing loop\n- Using parse_options() for consistent argument handling\n\nThe --base, --ours, and --theirs options use PARSE_OPT_NONEG to prevent\nnegated forms (--no-base, etc.) which are not meaningful for merge stage\nselection. This follows the pattern used in builtin/checkout.c for similar\nstage selection options.\n\nThis makes the code more maintainable and brings it in line with Git's\ncoding standards.\n\nSigned-off-by: Wasswa Edson <edsonwasswa54@gmail.com>\n---\n builtin/diff-files.c | 39 ++++++++++++++++++++-------------------\n 1 file changed, 20 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/diff-files.c b/builtin/diff-files.c\nindex ea91347ce2..e9e4907311 100644\n--- a/builtin/diff-files.c\n+++ b/builtin/diff-files.c\n@@ -14,11 +14,12 @@\n #include \"commit.h\"\n #include \"preload-index.h\"\n #include \"revision.h\"\n+#include \"parse-options.h\"\n \n-static const char diff_files_usage[] =\n-\"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]\"\n-\"\\n\"\n-COMMON_DIFF_OPTIONS_HELP;\n+static const char * const diff_files_usage[] = {\n+\t\"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]\",\n+\tNULL\n+};\n \n int cmd_diff_files(int argc,\n \t\t   const char **argv,\n@@ -28,8 +29,19 @@ int cmd_diff_files(int argc,\n \tstruct rev_info rev;\n \tint result;\n \tunsigned options = 0;\n+\tstruct option diff_files_options[] = {\n+\t\tOPT_SET_INT_F(0, \"base\", &rev.max_count,\n+\t\t\t      N_(\"show base version\"), 1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"ours\", &rev.max_count,\n+\t\t\t      N_(\"show our version\"), 2, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"theirs\", &rev.max_count,\n+\t\t\t      N_(\"show their version\"), 3, PARSE_OPT_NONEG),\n+\t\tOPT_BIT('q', NULL, &options,\n+\t\t       N_(\"be quiet\"), DIFF_SILENT_ON_REMOVED),\n+\t\tOPT_END()\n+\t};\n \n-\tshow_usage_if_asked(argc, argv, diff_files_usage);\n+\tshow_usage_with_options_if_asked(argc, argv, diff_files_usage, diff_files_options);\n \n \trepo_config(the_repository, git_diff_basic_config, NULL); /* no \"diff\" UI options */\n \n@@ -48,19 +60,8 @@ int cmd_diff_files(int argc,\n \tprefix = precompose_argv_prefix(argc, argv, prefix);\n \n \targc = setup_revisions(argc, argv, &rev, NULL);\n-\twhile (1 < argc && argv[1][0] == '-') {\n-\t\tif (!strcmp(argv[1], \"--base\"))\n-\t\t\trev.max_count = 1;\n-\t\telse if (!strcmp(argv[1], \"--ours\"))\n-\t\t\trev.max_count = 2;\n-\t\telse if (!strcmp(argv[1], \"--theirs\"))\n-\t\t\trev.max_count = 3;\n-\t\telse if (!strcmp(argv[1], \"-q\"))\n-\t\t\toptions |= DIFF_SILENT_ON_REMOVED;\n-\t\telse\n-\t\t\tusage(diff_files_usage);\n-\t\targv++; argc--;\n-\t}\n+\targc = parse_options(argc, argv, prefix, diff_files_options,\n+\t\t\t     diff_files_usage, 0);\n \tif (!rev.diffopt.output_format)\n \t\trev.diffopt.output_format = DIFF_FORMAT_RAW;\n \trev.diffopt.rotate_to_strict = 1;\n@@ -73,7 +74,7 @@ int cmd_diff_files(int argc,\n \tif (rev.pending.nr ||\n \t    rev.min_age != -1 || rev.max_age != -1 ||\n \t    3 < rev.max_count)\n-\t\tusage(diff_files_usage);\n+\t\tusage_with_options(diff_files_usage, diff_files_options);\n \n \t/*\n \t * \"diff-files --base -p\" should not combine merges because it\n-- \n2.46.0.windows.1\n\n\n"},{"id":"556834","messageId":"xmqq4ie418zm.fsf@gitster.g","threadId":"66693","inReplyTo":"20261029203904.432-1-edsonwasswa54@gmail.com","subject":"Re: [PATCH v4] builtin/diff-files: convert ad hoc option parsing to parse-options API","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-29T21:40:13Z","receivedAt":"2026-10-29T21:40:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Edson <edsonwasswa54@gmail.com> writes:\n\nYour message has these headers\n\n    In-Reply-To: <20261028170432.3524465-1-gitster@pobox.com>\n    References: <20261028170432.3524465-1-gitster@pobox.com>\n\nbut that does not look anything like the message ID of the previous\nround of your patch.  I do not see any such messages on the mailing\nlist.\n\nThis hurts both automation and human readers, as people cannot find\nand compare the previous round (v3) from the message of v4.  It seems\nthat your v3 had exactly the same issue.\n\nPlease sort it out before sending more patches, as messages with\nbroken threading will take more resources and time out of your\nrecipients.\n\nThanks.\n\n"},{"id":"557089","messageId":"20261101192502.1920-1-edsonwasswa54@gmail.com","threadId":"66693","inReplyTo":"20261029203904.432-1-edsonwasswa54@gmail.com","subject":"[PATCH v6] builtin/diff-files: convert ad hoc option parsing to parse-options API","fromName":"Edson","fromEmail":"edsonwasswa54@gmail.com","sentAt":"2026-11-01T19:25:01Z","receivedAt":"2026-11-01T19:25:01Z","isPatch":true,"sender":{"key":"edsonwasswa54@gmail.com","avatar":null},"body":"From: Wasswa Edson <edsonwasswa54@gmail.com>\n\nThe cmd_diff_files() function manually parses --base, --ours, --theirs,\nand -q options using a hand-rolled loop with strcmp() calls. This is\ninconsistent with the rest of Git's codebase and lacks features provided\nby the parse-options API such as auto-generated help text, git completion\nsupport, and option abbreviation.\n\nConvert this to use the parse-options API by:\n- Adding option definitions using OPT_* macros\n- Removing the manual parsing loop\n- Using parse_options() for consistent argument handling\n\nThe --base, --ours, and --theirs options use PARSE_OPT_NONEG to prevent\nnegated forms (--no-base, etc.) which are not meaningful for merge stage\nselection. This follows the pattern used in builtin/checkout.c for similar\nstage selection options.\n\nThis makes the code more maintainable and brings it in line with Git's\ncoding standards.\n\nSigned-off-by: Wasswa Edson <edsonwasswa54@gmail.com>\n---\n builtin/diff-files.c | 39 ++++++++++++++++++++-------------------\n 1 file changed, 20 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/diff-files.c b/builtin/diff-files.c\nindex ea91347ce2..e9e4907311 100644\n--- a/builtin/diff-files.c\n+++ b/builtin/diff-files.c\n@@ -14,11 +14,12 @@\n #include \"commit.h\"\n #include \"preload-index.h\"\n #include \"revision.h\"\n+#include \"parse-options.h\"\n \n-static const char diff_files_usage[] =\n-\"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]\"\n-\"\\n\"\n-COMMON_DIFF_OPTIONS_HELP;\n+static const char * const diff_files_usage[] = {\n+\t\"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]\",\n+\tNULL\n+};\n \n int cmd_diff_files(int argc,\n \t\t   const char **argv,\n@@ -28,8 +29,19 @@ int cmd_diff_files(int argc,\n \tstruct rev_info rev;\n \tint result;\n \tunsigned options = 0;\n+\tstruct option diff_files_options[] = {\n+\t\tOPT_SET_INT_F(0, \"base\", &rev.max_count,\n+\t\t\t      N_(\"show base version\"), 1, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"ours\", &rev.max_count,\n+\t\t\t      N_(\"show our version\"), 2, PARSE_OPT_NONEG),\n+\t\tOPT_SET_INT_F(0, \"theirs\", &rev.max_count,\n+\t\t\t      N_(\"show their version\"), 3, PARSE_OPT_NONEG),\n+\t\tOPT_BIT('q', NULL, &options,\n+\t\t       N_(\"be quiet\"), DIFF_SILENT_ON_REMOVED),\n+\t\tOPT_END()\n+\t};\n \n-\tshow_usage_if_asked(argc, argv, diff_files_usage);\n+\tshow_usage_with_options_if_asked(argc, argv, diff_files_usage, diff_files_options);\n \n \trepo_config(the_repository, git_diff_basic_config, NULL); /* no \"diff\" UI options */\n \n@@ -48,19 +60,8 @@ int cmd_diff_files(int argc,\n \tprefix = precompose_argv_prefix(argc, argv, prefix);\n \n \targc = setup_revisions(argc, argv, &rev, NULL);\n-\twhile (1 < argc && argv[1][0] == '-') {\n-\t\tif (!strcmp(argv[1], \"--base\"))\n-\t\t\trev.max_count = 1;\n-\t\telse if (!strcmp(argv[1], \"--ours\"))\n-\t\t\trev.max_count = 2;\n-\t\telse if (!strcmp(argv[1], \"--theirs\"))\n-\t\t\trev.max_count = 3;\n-\t\telse if (!strcmp(argv[1], \"-q\"))\n-\t\t\toptions |= DIFF_SILENT_ON_REMOVED;\n-\t\telse\n-\t\t\tusage(diff_files_usage);\n-\t\targv++; argc--;\n-\t}\n+\targc = parse_options(argc, argv, prefix, diff_files_options,\n+\t\t\t     diff_files_usage, 0);\n \tif (!rev.diffopt.output_format)\n \t\trev.diffopt.output_format = DIFF_FORMAT_RAW;\n \trev.diffopt.rotate_to_strict = 1;\n@@ -73,7 +74,7 @@ int cmd_diff_files(int argc,\n \tif (rev.pending.nr ||\n \t    rev.min_age != -1 || rev.max_age != -1 ||\n \t    3 < rev.max_count)\n-\t\tusage(diff_files_usage);\n+\t\tusage_with_options(diff_files_usage, diff_files_options);\n \n \t/*\n \t * \"diff-files --base -p\" should not combine merges because it\n-- \n2.46.0.windows.1\n\n\n"},{"id":"557140","messageId":"xmqq8q3blfh1.fsf@gitster.g","threadId":"66693","inReplyTo":"20261101192502.1920-1-edsonwasswa54@gmail.com","subject":"Re: [PATCH v6] builtin/diff-files: convert ad hoc option parsing to parse-options API","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-02T10:01:14Z","receivedAt":"2026-11-02T10:01:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Edson <edsonwasswa54@gmail.com> writes:\n\n> -static const char diff_files_usage[] =\n> -\"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]\"\n> -\"\\n\"\n> -COMMON_DIFF_OPTIONS_HELP;\n> +static const char * const diff_files_usage[] = {\n> +\t\"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]\",\n> +\tNULL\n> +};\n\nThe loss of COMMON_DIFF_OPTIONS_HELP here gives us a regression in\nthe help output (\"git diff-files -h\").  By replacing the single string\nwith a string array and passing it to parse_options() or\nshow_usage_with_options_if_asked(), the COMMON_DIFF_OPTIONS_HELP\nmacro is omitted.\n\nSince parse_options() or show_usage_with_options_if_asked() only\nknows about the options explicitly defined in the diff_files_options[]\narray (leaving standard diff options to be parsed by\nsetup_revisions()), the common diff options (like -p, --stat, and -z)\nwill no longer be documented when the user runs \"git diff-files -h\".\n\nYou probably could shove COMMON_DIFF_OPTIONS_HELP into OPT_GROUP()\nor something that produces static text in the help output to avoid\nthe regression if you really wanted to, but given that \"diff-files\"\nis plumbing meant for use by scripts, I am not sure how much value\nwe get by rewriting its command-line parsing.  Being able to say\n\"git diff-files --bas\" and get it understood as \"--base\" is\nsomething we may appreciate if it were a Porcelain command, but is\nit worth the hassle for a plumbing?  I have to wonder.\n\nEspecially when the parsing loop the patch wants to replace ...\n\n>  \targc = setup_revisions(argc, argv, &rev, NULL);\n> -\twhile (1 < argc && argv[1][0] == '-') {\n> -\t\tif (!strcmp(argv[1], \"--base\"))\n> -\t\t\trev.max_count = 1;\n> -\t\telse if (!strcmp(argv[1], \"--ours\"))\n> -\t\t\trev.max_count = 2;\n> -\t\telse if (!strcmp(argv[1], \"--theirs\"))\n> -\t\t\trev.max_count = 3;\n> -\t\telse if (!strcmp(argv[1], \"-q\"))\n> -\t\t\toptions |= DIFF_SILENT_ON_REMOVED;\n> -\t\telse\n> -\t\t\tusage(diff_files_usage);\n> -\t\targv++; argc--;\n> -\t}\n\n... is not anything that is ugly or overly hard to understand.\n\nI dunno.\n\n\n> +\targc = parse_options(argc, argv, prefix, diff_files_options,\n> +\t\t\t     diff_files_usage, 0);\n>  \tif (!rev.diffopt.output_format)\n>  \t\trev.diffopt.output_format = DIFF_FORMAT_RAW;\n>  \trev.diffopt.rotate_to_strict = 1;\n> @@ -73,7 +74,7 @@ int cmd_diff_files(int argc,\n>  \tif (rev.pending.nr ||\n>  \t    rev.min_age != -1 || rev.max_age != -1 ||\n>  \t    3 < rev.max_count)\n> -\t\tusage(diff_files_usage);\n> +\t\tusage_with_options(diff_files_usage, diff_files_options);\n>  \n>  \t/*\n>  \t * \"diff-files --base -p\" should not combine merges because it\n\n"},{"id":"557180","messageId":"CA+ew3JuD_FKhpw=pUT+p-r2750A0qyKTbTXZvxxvvNovjxLgyw@mail.gmail.com","threadId":"66693","inReplyTo":"xmqq8q3blfh1.fsf@gitster.g","subject":"Re: [PATCH v6] builtin/diff-files: convert ad hoc option parsing to parse-options API","fromName":"Wasswa Edson","fromEmail":"edsonwasswa54@gmail.com","sentAt":"2026-11-02T14:16:03Z","receivedAt":"2026-11-02T14:16:03Z","isPatch":true,"sender":{"key":"edsonwasswa54@gmail.com","avatar":null},"body":"Hi Junio,\n\nThanks for the review. You make a good point about the value trade-off\nfor a plumbing command - the loss of COMMON_DIFF_OPTIONS_HELP in the\nhelp output isn't worth the benefits parse-options would bring i had\nnot seen that coming ......lol.\n\nI'll drop this patch and look for a better target to work on.\n\nThanks for the guidance.\n\nBest regards,\nWasswa Edson\n\nOn Mon, 2 Nov 2026 at 13:01, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Edson <edsonwasswa54@gmail.com> writes:\n>\n> > -static const char diff_files_usage[] =\n> > -\"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]\"\n> > -\"\\n\"\n> > -COMMON_DIFF_OPTIONS_HELP;\n> > +static const char * const diff_files_usage[] = {\n> > +     \"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]\",\n> > +     NULL\n> > +};\n>\n> The loss of COMMON_DIFF_OPTIONS_HELP here gives us a regression in\n> the help output (\"git diff-files -h\").  By replacing the single string\n> with a string array and passing it to parse_options() or\n> show_usage_with_options_if_asked(), the COMMON_DIFF_OPTIONS_HELP\n> macro is omitted.\n>\n> Since parse_options() or show_usage_with_options_if_asked() only\n> knows about the options explicitly defined in the diff_files_options[]\n> array (leaving standard diff options to be parsed by\n> setup_revisions()), the common diff options (like -p, --stat, and -z)\n> will no longer be documented when the user runs \"git diff-files -h\".\n>\n> You probably could shove COMMON_DIFF_OPTIONS_HELP into OPT_GROUP()\n> or something that produces static text in the help output to avoid\n> the regression if you really wanted to, but given that \"diff-files\"\n> is plumbing meant for use by scripts, I am not sure how much value\n> we get by rewriting its command-line parsing.  Being able to say\n> \"git diff-files --bas\" and get it understood as \"--base\" is\n> something we may appreciate if it were a Porcelain command, but is\n> it worth the hassle for a plumbing?  I have to wonder.\n>\n> Especially when the parsing loop the patch wants to replace ...\n>\n> >       argc = setup_revisions(argc, argv, &rev, NULL);\n> > -     while (1 < argc && argv[1][0] == '-') {\n> > -             if (!strcmp(argv[1], \"--base\"))\n> > -                     rev.max_count = 1;\n> > -             else if (!strcmp(argv[1], \"--ours\"))\n> > -                     rev.max_count = 2;\n> > -             else if (!strcmp(argv[1], \"--theirs\"))\n> > -                     rev.max_count = 3;\n> > -             else if (!strcmp(argv[1], \"-q\"))\n> > -                     options |= DIFF_SILENT_ON_REMOVED;\n> > -             else\n> > -                     usage(diff_files_usage);\n> > -             argv++; argc--;\n> > -     }\n>\n> ... is not anything that is ugly or overly hard to understand.\n>\n> I dunno.\n>\n>\n> > +     argc = parse_options(argc, argv, prefix, diff_files_options,\n> > +                          diff_files_usage, 0);\n> >       if (!rev.diffopt.output_format)\n> >               rev.diffopt.output_format = DIFF_FORMAT_RAW;\n> >       rev.diffopt.rotate_to_strict = 1;\n> > @@ -73,7 +74,7 @@ int cmd_diff_files(int argc,\n> >       if (rev.pending.nr ||\n> >           rev.min_age != -1 || rev.max_age != -1 ||\n> >           3 < rev.max_count)\n> > -             usage(diff_files_usage);\n> > +             usage_with_options(diff_files_usage, diff_files_options);\n> >\n> >       /*\n> >        * \"diff-files --base -p\" should not combine merges because it\n\n"}]}