{"thread":{"id":"55701","subject":"[RFC PATCH] rev-parse: fix segfault with missing --path-format argument","startedAt":"2021-05-16T12:14:15Z","lastAt":"2021-05-19T14:21:28Z","messageCount":12,"participants":["Wolfgang Müller","Junio C Hamano","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"424679","messageId":"20210516120449.661636-1-wolf@oriole.systems","threadId":"55701","inReplyTo":null,"subject":"[RFC PATCH] rev-parse: fix segfault with missing --path-format argument","fromName":"Wolfgang Müller","fromEmail":"wolf@oriole.systems","sentAt":"2021-05-16T12:04:49Z","receivedAt":"2021-05-16T12:14:15Z","isPatch":true,"sender":{"key":"wolf@oriole.systems","avatar":"https://avatars.githubusercontent.com/u/397518?v=4"},"body":"Calling \"git rev-parse --path-format\" without an argument segfaults\ninstead of giving an error message. Commit fac60b8925 (rev-parse: add\noption for absolute or relative path formatting, 2020-12-13) added the\nargument parsing code but forgot to handle NULL.\n\nReturning an error makes sense here because there is no default value we\ncould use. Add a test case to verify.\n\nSigned-off-by: Wolfgang Müller <wolf@oriole.systems>\n---\nSince this is my first contribution to the project and I'm still\nlearning the ropes, I left this patch as RFC.\n\nFor a bit of background information, I ran into this expecting the\nfollowing to work:\n\n\tgit rev-parse --path-format relative --show-toplevel\n\nI'm unsure how many git subcommands specifically require \"=\" between the\noption and the argument, but before now I always expected things to\n\"just work\" when leaving it out.\n\nThis fix is based on maint.\n\nThanks for your time and attention.\n\n builtin/rev-parse.c  | 2 ++\n t/t1500-rev-parse.sh | 4 ++++\n 2 files changed, 6 insertions(+)\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 85bad9052e..7af8dab8bc 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -759,6 +759,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (opt_with_value(arg, \"--path-format\", &arg)) {\n+\t\t\t\tif (!arg)\n+\t\t\t\t\tdie(\"--path-format requires an argument\");\n \t\t\t\tif (!strcmp(arg, \"absolute\")) {\n \t\t\t\t\tformat = FORMAT_CANONICAL;\n \t\t\t\t} else if (!strcmp(arg, \"relative\")) {\ndiff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh\nindex deae916707..a1a8ce5265 100755\n--- a/t/t1500-rev-parse.sh\n+++ b/t/t1500-rev-parse.sh\n@@ -146,6 +146,10 @@ test_expect_success '--path-format can change in the middle of the command line'\n \ttest_cmp expect actual\n '\n \n+test_expect_success '--path-format does not segfault without an argument' '\n+\ttest_must_fail git rev-parse --path-format --show-toplevel\n+'\n+\n test_expect_success 'git-common-dir from worktree root' '\n \techo .git >expect &&\n \tgit rev-parse --git-common-dir >actual &&\n-- \n2.31.1\n\n"},{"id":"424681","messageId":"xmqqsg2m6dsi.fsf@gitster.g","threadId":"55701","inReplyTo":"20210516120449.661636-1-wolf@oriole.systems","subject":"Re: [RFC PATCH] rev-parse: fix segfault with missing --path-format argument","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-05-16T12:53:01Z","receivedAt":"2021-05-16T12:53:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Wolfgang Müller <wolf@oriole.systems> writes:\n\n> Calling \"git rev-parse --path-format\" without an argument segfaults\n> instead of giving an error message. Commit fac60b8925 (rev-parse: add\n> option for absolute or relative path formatting, 2020-12-13) added the\n> argument parsing code but forgot to handle NULL.\n>\n> Returning an error makes sense here because there is no default value we\n> could use. Add a test case to verify.\n>\n> Signed-off-by: Wolfgang Müller <wolf@oriole.systems>\n> ---\n> Since this is my first contribution to the project and I'm still\n> learning the ropes, I left this patch as RFC.\n>\n> For a bit of background information, I ran into this expecting the\n> following to work:\n>\n> \tgit rev-parse --path-format relative --show-toplevel\n>\n> I'm unsure how many git subcommands specifically require \"=\" between the\n> option and the argument, but before now I always expected things to\n> \"just work\" when leaving it out.\n>\n> This fix is based on maint.\n>\n> Thanks for your time and attention.\n\nNicely done.\n\n>  builtin/rev-parse.c  | 2 ++\n>  t/t1500-rev-parse.sh | 4 ++++\n>  2 files changed, 6 insertions(+)\n>\n> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\n> index 85bad9052e..7af8dab8bc 100644\n> --- a/builtin/rev-parse.c\n> +++ b/builtin/rev-parse.c\n> @@ -759,6 +759,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n>  \t\t\t\tcontinue;\n>  \t\t\t}\n>  \t\t\tif (opt_with_value(arg, \"--path-format\", &arg)) {\n> +\t\t\t\tif (!arg)\n> +\t\t\t\t\tdie(\"--path-format requires an argument\");\n\nAs die() is end-user facing, you'd probably want\n\n\tdie(_(\"--path-format requires an argument\"));\n\nWe do have untranslated die() nearby for the same option, which may\nwant to be cleaned up either in a preliminary patch, or in this same\npatch as an unrelated fix \"while we are at it\".\n\n>  \t\t\t\tif (!strcmp(arg, \"absolute\")) {\n>  \t\t\t\t\tformat = FORMAT_CANONICAL;\n>  \t\t\t\t} else if (!strcmp(arg, \"relative\")) {\n> diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh\n> index deae916707..a1a8ce5265 100755\n> --- a/t/t1500-rev-parse.sh\n> +++ b/t/t1500-rev-parse.sh\n> @@ -146,6 +146,10 @@ test_expect_success '--path-format can change in the middle of the command line'\n>  \ttest_cmp expect actual\n>  '\n>  \n> +test_expect_success '--path-format does not segfault without an argument' '\n> +\ttest_must_fail git rev-parse --path-format --show-toplevel\n\nThe above is certainly worth testing for, but if we ever upgrade the\ncommand line parser of \"rev-parse\" to be compatible with the parser\nbased on the parse-options API to allow both \"--opt=val\" and \"--opt\nval\", it will start to fail for an entirely different reason, namely\n\"--show-toplevel\" will be taken as the argument to \"--path-format\",\nand we'd get \"unknown argument to --path-format\".  So it might be\nprudent to test both, i.e.\n\n\ttest_must_fail git rev-parse --path-format --show-toplevel &&\n\ttest_must_fail git rev-parse --show-toplevel --path-format\n"},{"id":"424684","messageId":"20210516143156.mauc2ukryx5j2e2r@nabokov.fritz.box","threadId":"55701","inReplyTo":"xmqqsg2m6dsi.fsf@gitster.g","subject":"Re: [RFC PATCH] rev-parse: fix segfault with missing --path-format argument","fromName":"Wolfgang Müller","fromEmail":"wolf@oriole.systems","sentAt":"2021-05-16T14:31:56Z","receivedAt":"2021-05-16T14:32:14Z","isPatch":true,"sender":{"key":"wolf@oriole.systems","avatar":"https://avatars.githubusercontent.com/u/397518?v=4"},"body":"On 2021-05-16 21:53, Junio C Hamano wrote:\n\n> As die() is end-user facing, you'd probably want\n> \n> \tdie(_(\"--path-format requires an argument\"));\n> \n> We do have untranslated die() nearby for the same option, which may\n> want to be cleaned up either in a preliminary patch, or in this same\n> patch as an unrelated fix \"while we are at it\".\n\nI would not mind preparing a preliminary patch that cleans up all\nuntranslated user-facing calls to die(). My editor finds 15 of those in\nrev-parse.c, and I think they all qualify.\n\nIf you'd rather not touch unrelated code paths I'll instead include it\nin v2 as an unrelated fix in the same commit.\n\n> The above is certainly worth testing for, but if we ever upgrade the\n> command line parser of \"rev-parse\" to be compatible with the parser\n> based on the parse-options API to allow both \"--opt=val\" and \"--opt\n> val\", it will start to fail for an entirely different reason, namely\n> \"--show-toplevel\" will be taken as the argument to \"--path-format\",\n> and we'd get \"unknown argument to --path-format\".  So it might be\n> prudent to test both, i.e.\n> \n> \ttest_must_fail git rev-parse --path-format --show-toplevel &&\n> \ttest_must_fail git rev-parse --show-toplevel --path-format\n\nI think I initially went for \"--path-format --show-toplevel\" because I\nwas under the assumption that --path-format needs another option it can\nmodify. It seems that this is not the case, so wouldn't it be simpler\nhere to do the following instead:\n\n\ttest_must_fail git rev-parse --path-format\n\nThat way we do not have to worry about subsequent changes to other,\nunrelated, options.\n\n-- \nWolfgang\n"},{"id":"424693","messageId":"xmqqk0ny5oi1.fsf@gitster.g","threadId":"55701","inReplyTo":"20210516143156.mauc2ukryx5j2e2r@nabokov.fritz.box","subject":"Re: [RFC PATCH] rev-parse: fix segfault with missing --path-format argument","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-05-16T21:59:18Z","receivedAt":"2021-05-16T21:59:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Wolfgang Müller <wolf@oriole.systems> writes:\n\n> On 2021-05-16 21:53, Junio C Hamano wrote:\n>\n>> As die() is end-user facing, you'd probably want\n>> \n>> \tdie(_(\"--path-format requires an argument\"));\n>> \n>> We do have untranslated die() nearby for the same option, which may\n>> want to be cleaned up either in a preliminary patch, or in this same\n>> patch as an unrelated fix \"while we are at it\".\n>\n> I would not mind preparing a preliminary patch that cleans up all\n> untranslated user-facing calls to die(). My editor finds 15 of those in\n> rev-parse.c, and I think they all qualify.\n>\n> If you'd rather not touch unrelated code paths I'll instead include it\n> in v2 as an unrelated fix in the same commit.\n\nI am puzzled by the last paragraph.  Somebody who does not want to\nsee \"unrelated\" codepaths touched would appreciate if a commit that\nfixes this segfault does not touch them at the same time.\n\nIn any case, I now counted existing die() messages in this file, and\namong 15 of them, only 1 is marked with _(...).  I think that it\nis the best to apply the patch as-is (without _(...)), adding one\nuntranslated message to the file.\n\nThen, on top of this change, the 15 untranslated messages can be\nmarked with _(...) a separate commit (and it does not even have to\nbe done by you).\n\n> I think I initially went for \"--path-format --show-toplevel\" because I\n> was under the assumption that --path-format needs another option it can\n> modify. It seems that this is not the case, so wouldn't it be simpler\n> here to do the following instead:\n>\n> \ttest_must_fail git rev-parse --path-format\n>\n> That way we do not have to worry about subsequent changes to other,\n> unrelated, options.\n\nThat's good, too.  Simple.\n\nThanks.\n\n"},{"id":"424708","messageId":"20210517071950.lhj5tmvfj4vxmpkr@nabokov.fritz.box","threadId":"55701","inReplyTo":"xmqqk0ny5oi1.fsf@gitster.g","subject":"Re: [RFC PATCH] rev-parse: fix segfault with missing --path-format argument","fromName":"Wolfgang Müller","fromEmail":"wolf@oriole.systems","sentAt":"2021-05-17T07:19:50Z","receivedAt":"2021-05-17T07:20:00Z","isPatch":true,"sender":{"key":"wolf@oriole.systems","avatar":"https://avatars.githubusercontent.com/u/397518?v=4"},"body":"On 2021-05-17 06:59, Junio C Hamano wrote:\n\n> >> We do have untranslated die() nearby for the same option, which may\n> >> want to be cleaned up either in a preliminary patch, or in this\n> >> same patch as an unrelated fix \"while we are at it\".\n> >\n> > I would not mind preparing a preliminary patch that cleans up all\n> > untranslated user-facing calls to die(). My editor finds 15 of those\n> > in rev-parse.c, and I think they all qualify.\n> >\n> > If you'd rather not touch unrelated code paths I'll instead include\n> > it in v2 as an unrelated fix in the same commit.\n> \n> I am puzzled by the last paragraph.  Somebody who does not want to see\n> \"unrelated\" codepaths touched would appreciate if a commit that fixes\n> this segfault does not touch them at the same time.\n\nApologies, I was being unclear here. I was meaning to offer either\ncleaning up all calls to die() in a separate patch, or fixing only the\nnearby occurrence that you mentioned in the same patch. I had implicitly\nassumed you had seen the other untranslated messages already but only\nwanted to fix the one for the same option (ie in a nearby, \"related\"\npath).\n\n> In any case, I now counted existing die() messages in this file, and\n> among 15 of them, only 1 is marked with _(...).  I think that it\n> is the best to apply the patch as-is (without _(...)), adding one\n> untranslated message to the file.\n\nWill do.\n\n> Then, on top of this change, the 15 untranslated messages can be\n> marked with _(...) a separate commit (and it does not even have to\n> be done by you).\n\nI don't mind doing this, so I'll include it.\n\n> That's good, too.  Simple.\n> \n> Thanks.\n\nThanks a lot for your feedback, I'll be sending v2 along shortly.\n\n-- \nWolfgang\n"},{"id":"424711","messageId":"20210517080243.10191-1-wolf@oriole.systems","threadId":"55701","inReplyTo":"20210516120449.661636-1-wolf@oriole.systems","subject":"[PATCH v2 0/2] rev-parse: Fix segfault and translate messages","fromName":"Wolfgang Müller","fromEmail":"wolf@oriole.systems","sentAt":"2021-05-17T08:02:41Z","receivedAt":"2021-05-17T08:03:21Z","isPatch":true,"sender":{"key":"wolf@oriole.systems","avatar":"https://avatars.githubusercontent.com/u/397518?v=4"},"body":"This series fixes a segfault in rev-parse and, whilst we're there, marks\npreviously untranslated error messages for translation.\n\nCompared to v1, this series simplifies the test for --path-format\nwithout and argument and adds the translation fix on top.\n\nWolfgang Müller (2):\n  rev-parse: fix segfault with missing --path-format argument\n  rev-parse: Mark die() messages for translation\n\n builtin/rev-parse.c  | 30 ++++++++++++++++--------------\n t/t1500-rev-parse.sh |  4 ++++\n 2 files changed, 20 insertions(+), 14 deletions(-)\n\n-- \n2.31.1\n\n"},{"id":"424712","messageId":"20210517080243.10191-2-wolf@oriole.systems","threadId":"55701","inReplyTo":"20210517080243.10191-1-wolf@oriole.systems","subject":"[PATCH v2 1/2] rev-parse: fix segfault with missing --path-format argument","fromName":"Wolfgang Müller","fromEmail":"wolf@oriole.systems","sentAt":"2021-05-17T08:02:42Z","receivedAt":"2021-05-17T08:03:22Z","isPatch":true,"sender":{"key":"wolf@oriole.systems","avatar":"https://avatars.githubusercontent.com/u/397518?v=4"},"body":"Calling \"git rev-parse --path-format\" without an argument segfaults\ninstead of giving an error message. Commit fac60b8925 (rev-parse: add\noption for absolute or relative path formatting, 2020-12-13) added the\nargument parsing code but forgot to handle NULL.\n\nReturning an error makes sense here because there is no default value we\ncould use. Add a test case to verify.\n\nSigned-off-by: Wolfgang Müller <wolf@oriole.systems>\n---\n builtin/rev-parse.c  | 2 ++\n t/t1500-rev-parse.sh | 4 ++++\n 2 files changed, 6 insertions(+)\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 85bad9052e..7af8dab8bc 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -759,6 +759,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (opt_with_value(arg, \"--path-format\", &arg)) {\n+\t\t\t\tif (!arg)\n+\t\t\t\t\tdie(\"--path-format requires an argument\");\n \t\t\t\tif (!strcmp(arg, \"absolute\")) {\n \t\t\t\t\tformat = FORMAT_CANONICAL;\n \t\t\t\t} else if (!strcmp(arg, \"relative\")) {\ndiff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh\nindex deae916707..1c2df08333 100755\n--- a/t/t1500-rev-parse.sh\n+++ b/t/t1500-rev-parse.sh\n@@ -146,6 +146,10 @@ test_expect_success '--path-format can change in the middle of the command line'\n \ttest_cmp expect actual\n '\n \n+test_expect_success '--path-format does not segfault without an argument' '\n+\ttest_must_fail git rev-parse --path-format\n+'\n+\n test_expect_success 'git-common-dir from worktree root' '\n \techo .git >expect &&\n \tgit rev-parse --git-common-dir >actual &&\n-- \n2.31.1\n\n"},{"id":"424713","messageId":"20210517080243.10191-3-wolf@oriole.systems","threadId":"55701","inReplyTo":"20210517080243.10191-1-wolf@oriole.systems","subject":"[PATCH v2 2/2] rev-parse: Mark die() messages for translation","fromName":"Wolfgang Müller","fromEmail":"wolf@oriole.systems","sentAt":"2021-05-17T08:02:43Z","receivedAt":"2021-05-17T08:03:23Z","isPatch":true,"sender":{"key":"wolf@oriole.systems","avatar":"https://avatars.githubusercontent.com/u/397518?v=4"},"body":"These error messages are intended for the user. Let's touch them up\nsince we're here from the previous commit.\n\nSigned-off-by: Wolfgang Müller <wolf@oriole.systems>\n---\n builtin/rev-parse.c | 30 +++++++++++++++---------------\n 1 file changed, 15 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 7af8dab8bc..22c4e1a4ff 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -435,11 +435,11 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)\n \t/* get the usage up to the first line with a -- on it */\n \tfor (;;) {\n \t\tif (strbuf_getline(&sb, stdin) == EOF)\n-\t\t\tdie(\"premature end of input\");\n+\t\t\tdie(_(\"premature end of input\"));\n \t\tALLOC_GROW(usage, unb + 1, usz);\n \t\tif (!strcmp(\"--\", sb.buf)) {\n \t\t\tif (unb < 1)\n-\t\t\t\tdie(\"no usage string given before the `--' separator\");\n+\t\t\t\tdie(_(\"no usage string given before the `--' separator\"));\n \t\t\tusage[unb] = NULL;\n \t\t\tbreak;\n \t\t}\n@@ -545,7 +545,7 @@ static void die_no_single_rev(int quiet)\n \tif (quiet)\n \t\texit(1);\n \telse\n-\t\tdie(\"Needed a single revision\");\n+\t\tdie(_(\"Needed a single revision\"));\n }\n \n static const char builtin_rev_parse_usage[] =\n@@ -709,10 +709,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\tif (!strcmp(arg, \"--resolve-git-dir\")) {\n \t\t\t\tconst char *gitdir = argv[++i];\n \t\t\t\tif (!gitdir)\n-\t\t\t\t\tdie(\"--resolve-git-dir requires an argument\");\n+\t\t\t\t\tdie(_(\"--resolve-git-dir requires an argument\"));\n \t\t\t\tgitdir = resolve_gitdir(gitdir);\n \t\t\t\tif (!gitdir)\n-\t\t\t\t\tdie(\"not a gitdir '%s'\", argv[i]);\n+\t\t\t\t\tdie(_(\"not a gitdir '%s'\"), argv[i]);\n \t\t\t\tputs(gitdir);\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -736,7 +736,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\tif (!seen_end_of_options && *arg == '-') {\n \t\t\tif (!strcmp(arg, \"--git-path\")) {\n \t\t\t\tif (!argv[i + 1])\n-\t\t\t\t\tdie(\"--git-path requires an argument\");\n+\t\t\t\t\tdie(_(\"--git-path requires an argument\"));\n \t\t\t\tstrbuf_reset(&buf);\n \t\t\t\tprint_path(git_path(\"%s\", argv[i + 1]), prefix,\n \t\t\t\t\t\tformat,\n@@ -746,7 +746,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t}\n \t\t\tif (!strcmp(arg,\"-n\")) {\n \t\t\t\tif (++i >= argc)\n-\t\t\t\t\tdie(\"-n requires an argument\");\n+\t\t\t\t\tdie(_(\"-n requires an argument\"));\n \t\t\t\tif ((filter & DO_FLAGS) && (filter & DO_REVS)) {\n \t\t\t\t\tshow(arg);\n \t\t\t\t\tshow(argv[i]);\n@@ -760,26 +760,26 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t}\n \t\t\tif (opt_with_value(arg, \"--path-format\", &arg)) {\n \t\t\t\tif (!arg)\n-\t\t\t\t\tdie(\"--path-format requires an argument\");\n+\t\t\t\t\tdie(_(\"--path-format requires an argument\"));\n \t\t\t\tif (!strcmp(arg, \"absolute\")) {\n \t\t\t\t\tformat = FORMAT_CANONICAL;\n \t\t\t\t} else if (!strcmp(arg, \"relative\")) {\n \t\t\t\t\tformat = FORMAT_RELATIVE;\n \t\t\t\t} else {\n-\t\t\t\t\tdie(\"unknown argument to --path-format: %s\", arg);\n+\t\t\t\t\tdie(_(\"unknown argument to --path-format: %s\"), arg);\n \t\t\t\t}\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--default\")) {\n \t\t\t\tdef = argv[++i];\n \t\t\t\tif (!def)\n-\t\t\t\t\tdie(\"--default requires an argument\");\n+\t\t\t\t\tdie(_(\"--default requires an argument\"));\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--prefix\")) {\n \t\t\t\tprefix = argv[++i];\n \t\t\t\tif (!prefix)\n-\t\t\t\t\tdie(\"--prefix requires an argument\");\n+\t\t\t\t\tdie(_(\"--prefix requires an argument\"));\n \t\t\t\tstartup_info->prefix = prefix;\n \t\t\t\toutput_prefix = 1;\n \t\t\t\tcontinue;\n@@ -848,7 +848,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\t\telse if (!strcmp(arg, \"loose\"))\n \t\t\t\t\t\tabbrev_ref_strict = 0;\n \t\t\t\t\telse\n-\t\t\t\t\t\tdie(\"unknown mode for --abbrev-ref: %s\",\n+\t\t\t\t\t\tdie(_(\"unknown mode for --abbrev-ref: %s\"),\n \t\t\t\t\t\t    arg);\n \t\t\t\t}\n \t\t\t\tcontinue;\n@@ -892,7 +892,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tif (work_tree)\n \t\t\t\t\tprint_path(work_tree, prefix, format, DEFAULT_UNMODIFIED);\n \t\t\t\telse\n-\t\t\t\t\tdie(\"this operation must be run in a work tree\");\n+\t\t\t\t\tdie(_(\"this operation must be run in a work tree\"));\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--show-superproject-working-tree\")) {\n@@ -1020,7 +1020,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tif (strcmp(val, \"storage\") &&\n \t\t\t\t    strcmp(val, \"input\") &&\n \t\t\t\t    strcmp(val, \"output\"))\n-\t\t\t\t\tdie(\"unknown mode for --show-object-format: %s\",\n+\t\t\t\t\tdie(_(\"unknown mode for --show-object-format: %s\"),\n \t\t\t\t\t    arg);\n \t\t\t\tputs(the_hash_algo->name);\n \t\t\t\tcontinue;\n@@ -1058,7 +1058,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\tif (verify)\n \t\t\tdie_no_single_rev(quiet);\n \t\tif (has_dashdash)\n-\t\t\tdie(\"bad revision '%s'\", arg);\n+\t\t\tdie(_(\"bad revision '%s'\"), arg);\n \t\tas_is = 1;\n \t\tif (!show_file(arg, output_prefix))\n \t\t\tcontinue;\n-- \n2.31.1\n\n"},{"id":"424714","messageId":"YKImcgntKHryLLfv@coredump.intra.peff.net","threadId":"55701","inReplyTo":"20210517080243.10191-2-wolf@oriole.systems","subject":"Re: [PATCH v2 1/2] rev-parse: fix segfault with missing --path-format argument","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-05-17T08:16:50Z","receivedAt":"2021-05-17T08:18:48Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, May 17, 2021 at 10:02:42AM +0200, Wolfgang Müller wrote:\n\n> Calling \"git rev-parse --path-format\" without an argument segfaults\n> instead of giving an error message. Commit fac60b8925 (rev-parse: add\n> option for absolute or relative path formatting, 2020-12-13) added the\n> argument parsing code but forgot to handle NULL.\n> \n> Returning an error makes sense here because there is no default value we\n> could use. Add a test case to verify.\n> \n> Signed-off-by: Wolfgang Müller <wolf@oriole.systems>\n> ---\n>  builtin/rev-parse.c  | 2 ++\n>  t/t1500-rev-parse.sh | 4 ++++\n>  2 files changed, 6 insertions(+)\n> \n> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\n> index 85bad9052e..7af8dab8bc 100644\n> --- a/builtin/rev-parse.c\n> +++ b/builtin/rev-parse.c\n> @@ -759,6 +759,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n>  \t\t\t\tcontinue;\n>  \t\t\t}\n>  \t\t\tif (opt_with_value(arg, \"--path-format\", &arg)) {\n> +\t\t\t\tif (!arg)\n> +\t\t\t\t\tdie(\"--path-format requires an argument\");\n>  \t\t\t\tif (!strcmp(arg, \"absolute\")) {\n>  \t\t\t\t\tformat = FORMAT_CANONICAL;\n>  \t\t\t\t} else if (!strcmp(arg, \"relative\")) {\n\nThis looks like a fine solution, but I do think this code using\nopt_with_value() is a bit of a curiosity in the first place. I looked at\nthe other callers (because I wanted to see if there were similar\nproblems), and they are all cases where the argument is truly optional\n(so matching \"--foo\" or \"--foo=bar\" is correct, and matching \"--foo bar\"\nwould be actively wrong).\n\nFor cases where the argument is not optional, we seem to use\nskip_prefix(), like:\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex c4263404bd..9553cc7c10 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -760,7 +760,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tshow(arg);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (opt_with_value(arg, \"--path-format\", &arg)) {\n+\t\t\tif (skip_prefix(arg, \"--path-format=\", &arg)) {\n \t\t\t\tif (!strcmp(arg, \"absolute\")) {\n \t\t\t\t\tformat = FORMAT_CANONICAL;\n \t\t\t\t} else if (!strcmp(arg, \"relative\")) {\n\nI don't have a strong preference for one or the other. It is maybe\nhelpful to diagnose \"--path-format\" without an equals as an error, as\nyour patch would, rather than quietly passing it along as an unknown (as\nthe hunk above would). I dunno. That perhaps applies to the rest of the\noptions, too. :)\n\n(In an ideal world, we would probably match \"--path-format <arg>\" here,\nas our usual parse-options API does. But that is a much bigger change).\n\n-Peff\n"},{"id":"424930","messageId":"20210519095235.cydjlj2qoko6xm4v@nabokov.fritz.box","threadId":"55701","inReplyTo":"YKImcgntKHryLLfv@coredump.intra.peff.net","subject":"Re: [PATCH v2 1/2] rev-parse: fix segfault with missing --path-format argument","fromName":"Wolfgang Müller","fromEmail":"wolf@oriole.systems","sentAt":"2021-05-19T09:52:35Z","receivedAt":"2021-05-19T09:53:39Z","isPatch":true,"sender":{"key":"wolf@oriole.systems","avatar":"https://avatars.githubusercontent.com/u/397518?v=4"},"body":"On 2021-05-17 04:16, Jeff King wrote:\n\n> I don't have a strong preference for one or the other. It is maybe\n> helpful to diagnose \"--path-format\" without an equals as an error, as\n> your patch would, rather than quietly passing it along as an unknown\n> (as the hunk above would). I dunno. That perhaps applies to the rest\n> of the options, too. :)\n\nI have a very slight preference for throwing an error: that is what I\nexpected to happen as a user. At the same time, passing it along as an\nunknown seems more consistent with the other options that take equals.\nI'm split on this, and would defer to what people here prefer.\n\nShort of fully migrating to the parse-options API, I do not see a\nperfect solution for this, especially since there are options that take\noptional arguments which are not delimited by equals. These seem to be\nsprinkled throughout and all error out if no argument is given.\n\nHere's a small selection:\n\n\tOption                   Section in manual        Parser\n\n\t--default <arg>          Options for Output       manual\n\t--prefix <arg>           Options for Output       manual\n\t--short[=length]         Options for Output       opt_with_value\n\t--path-format=[..]       Options for Files        opt_with_value\n\t--git-path <path>        Options for Files        manual\n\t--disambiguate=<prefix>  Options for Objects      skip_prefix\n\nOut of curiosity I decided to dig around a bit, my hunch being that\narguments without equals are older.\n\nI can trace --default back to 178cb24338 (Add 'git-rev-parse' helper\nscript, 2005-06-13). That seems to be the very first version of\ngit-rev-parse.\n\nThe first options with equals, --since= et al., were added in c1babb1d65\n([PATCH] Teach \"git-rev-parse\" about date-based cut-offs, 2005-09-20)\n\nThe --short option used to be --abbrev, and was added in d50125085a\n(rev-parse: --abbrev option., 2006-01-25). Then, quite a bit later, the\nsecond option without equals was added in abc06822af (rev-parse: add\noption --resolve-git-dir <path>, 2011-08-15).\n\n--prefix goes back to 12b9d32790 (rev-parse: add --prefix option,\n2013-06-16) and --git-path is 557bd833bb (git_path(): be aware of file\nrelocation in $GIT_DIR, 2014-11-30)\n\nSo it turns out that my hunch was not really correct. Maybe there's also\na pattern that I am not seeing. Obviously this has no bearing on the\nsegfault fix, but is maybe valuable information for a conversion to the\nparse-options API down the line. It was also fun to figure out, since I\ncould not stop thinking about rev-parse having a bunch of different\noption semantics.\n\n-- \nWolfgang\n"},{"id":"424933","messageId":"20210519101933.stqe4bnilu22rmgl@nabokov.fritz.box","threadId":"55701","inReplyTo":"20210519095235.cydjlj2qoko6xm4v@nabokov.fritz.box","subject":"Re: [PATCH v2 1/2] rev-parse: fix segfault with missing --path-format argument","fromName":"Wolfgang Müller","fromEmail":"wolf@oriole.systems","sentAt":"2021-05-19T10:19:33Z","receivedAt":"2021-05-19T10:19:36Z","isPatch":true,"sender":{"key":"wolf@oriole.systems","avatar":"https://avatars.githubusercontent.com/u/397518?v=4"},"body":"On 2021-05-19 11:52, Wolfgang Müller wrote:\n\n> Short of fully migrating to the parse-options API, I do not see a\n> perfect solution for this, especially since there are options that take\n> optional arguments which are not delimited by equals. These seem to be\n> sprinkled throughout and all error out if no argument is given.\n\nUpon rereading this I noticed an error, I meant to say \"especially since\nthere are options that *require* arguments which are not delimited by\nequals.\", like --default, --prefix, and --git-path for example.\n\n-- \nWolfgang\n"},{"id":"424962","messageId":"YKUe5WD3ci3J4roO@coredump.intra.peff.net","threadId":"55701","inReplyTo":"20210519095235.cydjlj2qoko6xm4v@nabokov.fritz.box","subject":"Re: [PATCH v2 1/2] rev-parse: fix segfault with missing --path-format argument","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-05-19T14:21:25Z","receivedAt":"2021-05-19T14:21:28Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 19, 2021 at 11:52:35AM +0200, Wolfgang Müller wrote:\n\n> On 2021-05-17 04:16, Jeff King wrote:\n> \n> > I don't have a strong preference for one or the other. It is maybe\n> > helpful to diagnose \"--path-format\" without an equals as an error, as\n> > your patch would, rather than quietly passing it along as an unknown\n> > (as the hunk above would). I dunno. That perhaps applies to the rest\n> > of the options, too. :)\n> \n> I have a very slight preference for throwing an error: that is what I\n> expected to happen as a user. At the same time, passing it along as an\n> unknown seems more consistent with the other options that take equals.\n> I'm split on this, and would defer to what people here prefer.\n\nYeah, I don't feel strongly at all. I like consistency, but noticing\nbogus input is good, too. ;)\n\n> Short of fully migrating to the parse-options API, I do not see a\n> perfect solution for this, especially since there are options that take\n> optional arguments which are not delimited by equals. These seem to be\n> sprinkled throughout and all error out if no argument is given.\n\nUltimately I think using the parse-options API would be nice. In the\nmeantime, I suspect (but didn't think too hard on it) that you could get\nby with two helpers:\n\n  - rename the current opt_with_value() to opt_with_optional_value()\n    to make its assumptions clear.\n\n  - add a new helper opt_with_required_value() that accepts either:\n\n      --default <arg>\n      --default=<arg>\n      --disambiguate <arg>\n      --disambiguate=<arg>\n      etc...\n\n     and complains when the \"=\" is missing, or there is no extra \"<arg>\"\n     available.\n\nThe second helper is a little tricky to write, because it sometimes\nneeds to advance argv (and decrement argc) to account for the extra\nconsumed arg.\n\nThat's definitely something we can leave off for now, though.\n\n> So it turns out that my hunch was not really correct. Maybe there's also\n> a pattern that I am not seeing.\n\nI don't find it hard to believe that there's no obvious pattern. :) I\nwould say that rev-parse is one of the messiest and most \"organically\ngrown\" parts of Git.\n\nThanks for digging, though. It is always nice to see contributors going\nthe extra mile to figure out how their solutions fit into the bigger\npicture of the project.\n\n-Peff\n"}]}