{"thread":{"id":"35161","subject":"BUG: PATHSPEC_PREFER_CWD requires arguments","startedAt":"2013-10-18T09:21:33Z","lastAt":"2013-10-22T18:16:15Z","messageCount":4,"participants":["Antoine Pelisse","Nguyễn Thái Ngọc Duy","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"229157","messageId":"CALWbr2zTZzGZ9fkUonQr77Vn_dfzP57CZR1vNxNJW_touxNstQ@mail.gmail.com","threadId":"35161","inReplyTo":null,"subject":"BUG: PATHSPEC_PREFER_CWD requires arguments","fromName":"Antoine Pelisse","fromEmail":"apelisse@gmail.com","sentAt":"2013-10-18T09:21:33Z","receivedAt":"2013-10-18T09:21:33Z","isPatch":false,"sender":{"key":"apelisse@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1929644?v=4"},"body":"Hello,\n\nI ran into the following bug today: \"BUG: PATHSPEC_PREFER_CWD requires\narguments\". It's not that bad because I'm trying to run `git log\n--merge` on an already resolved conflict. Still, I don't think I\nshould hit a \"BUG:\" :-)\n\nHere is a script to reproduce:\ngit init .\n>a\ngit add a\ngit commit -m\"create a\"\ngit branch other\necho \"1\" >a\ngit commit -m\"add 1\" a\ngit checkout other\necho \"2\" >a\ngit commit -m\"add 2\" a\ngit merge master\ngit add a\ngit log --merge -- a\n# Fails with \"fatal: BUG: PATHSPEC_PREFER_CWD requires arguments\"\n\nHere is what GDB gives me when I break on die():\nBreakpoint 1, die (err=0x57e3a8 \"BUG: PATHSPEC_PREFER_CWD requires\narguments\") at usage.c:97\n97              if (die_is_recursing()) {\n(gdb) bt\n#0  die (err=0x57e3a8 \"BUG: PATHSPEC_PREFER_CWD requires arguments\")\nat usage.c:97\n#1  0x00000000004ea58a in parse_pathspec (pathspec=0x7fffffffc288,\nmagic_mask=31, flags=0, prefix=0x580dad \"\", argv=0x0) at\npathspec.c:377\n#2  0x00000000005097b4 in prepare_show_merge (revs=0x7fffffffc240) at\nrevision.c:1375\n#3  0x000000000050c32e in setup_revisions (argc=2,\nargv=0x7fffffffcb08, revs=0x7fffffffc240, opt=0x7fffffffc220) at\nrevision.c:2147\n#4  0x0000000000446efc in cmd_log_init_finish (argc=4,\nargv=0x7fffffffcb08, prefix=0x0, rev=0x7fffffffc240,\nopt=0x7fffffffc220)\n    at builtin/log.c:147\n#5  0x000000000044716a in cmd_log_init (argc=4, argv=0x7fffffffcb08,\nprefix=0x0, rev=0x7fffffffc240, opt=0x7fffffffc220) at\nbuiltin/log.c:203\n#6  0x0000000000448349 in cmd_log (argc=4, argv=0x7fffffffcb08,\nprefix=0x0) at builtin/log.c:635\n#7  0x000000000040584a in run_builtin (p=0x7bdb30, argc=4,\nargv=0x7fffffffcb08) at git.c:314\n#8  0x00000000004059d5 in handle_internal_command (argc=4,\nargv=0x7fffffffcb08) at git.c:478\n#9  0x0000000000405b88 in main (argc=4, av=0x7fffffffcb08) at git.c:575\n\nAnd here is what bisect found:\ncommit 9a0872744315da67db3c81eb9270751e31fcc8f5\nAuthor: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\nDate:   Sun Jul 14 15:35:59 2013 +0700\n\n    remove init_pathspec() in favor of parse_pathspec()\n\n    While at there, move free_pathspec() to pathspec.c\n\n    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n    Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\nThanks,\nAntoine\n"},{"id":"229203","messageId":"1382150484-13207-1-git-send-email-pclouds@gmail.com","threadId":"35161","inReplyTo":"CALWbr2zTZzGZ9fkUonQr77Vn_dfzP57CZR1vNxNJW_touxNstQ@mail.gmail.com","subject":"[PATCH] Fix calling parse_pathspec with no paths nor PATHSPEC_PREFER_* flags","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2013-10-19T02:41:24Z","receivedAt":"2013-10-19T02:41:24Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"When parse_pathspec() is called with no paths, the behavior could be\neither return no paths, or return one path that is cwd. Some commands\ndo the former, some the latter. parse_pathspec() itself does not make\neither the default and requires the caller to specify either flag if\nit may run into this situation.\n\nI've grep'd through all parse_pathspec() call sites. Some pass\nneither, but those are guaranteed never pass empty path to\nparse_pathspec(). There are two call sites that may pass empty path\nand are fixed with this patch.\n\nReported-by: Antoine Pelisse <apelisse@gmail.com>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n line-log.c | 3 ++-\n revision.c | 3 ++-\n 2 files changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/line-log.c b/line-log.c\nindex 8b6e497..717638b 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -760,7 +760,8 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list\n \t\t\tr = r->next;\n \t\t}\n \t\tpaths[count] = NULL;\n-\t\tparse_pathspec(&rev->diffopt.pathspec, 0, 0, \"\", paths);\n+\t\tparse_pathspec(&rev->diffopt.pathspec, 0,\n+\t\t\t       PATHSPEC_PREFER_FULL, \"\", paths);\n \t\tfree(paths);\n \t}\n }\ndiff --git a/revision.c b/revision.c\nindex 0173e01..dd994e9 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1372,7 +1372,8 @@ static void prepare_show_merge(struct rev_info *revs)\n \t\t\ti++;\n \t}\n \tfree_pathspec(&revs->prune_data);\n-\tparse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC, 0, \"\", prune);\n+\tparse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC,\n+\t\t       PATHSPEC_PREFER_FULL, \"\", prune);\n \trevs->limited = 1;\n }\n \n-- \n1.8.2.83.gc99314b\n"},{"id":"229295","messageId":"xmqq38ntusq6.fsf@gitster.dls.corp.google.com","threadId":"35161","inReplyTo":"1382150484-13207-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] Fix calling parse_pathspec with no paths nor PATHSPEC_PREFER_* flags","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-10-22T17:21:21Z","receivedAt":"2013-10-22T17:21:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> When parse_pathspec() is called with no paths, the behavior could be\n> either return no paths, or return one path that is cwd. Some commands\n> do the former, some the latter. parse_pathspec() itself does not make\n> either the default and requires the caller to specify either flag if\n> it may run into this situation.\n>\n> I've grep'd through all parse_pathspec() call sites. Some pass\n> neither, but those are guaranteed never pass empty path to\n> parse_pathspec(). There are two call sites that may pass empty path\n> and are fixed with this patch.\n>\n> Reported-by: Antoine Pelisse <apelisse@gmail.com>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n\nThanks.\n\n>  line-log.c | 3 ++-\n>  revision.c | 3 ++-\n>  2 files changed, 4 insertions(+), 2 deletions(-)\n>\n> diff --git a/line-log.c b/line-log.c\n> index 8b6e497..717638b 100644\n> --- a/line-log.c\n> +++ b/line-log.c\n> @@ -760,7 +760,8 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list\n>  \t\t\tr = r->next;\n>  \t\t}\n>  \t\tpaths[count] = NULL;\n> -\t\tparse_pathspec(&rev->diffopt.pathspec, 0, 0, \"\", paths);\n> +\t\tparse_pathspec(&rev->diffopt.pathspec, 0,\n> +\t\t\t       PATHSPEC_PREFER_FULL, \"\", paths);\n>  \t\tfree(paths);\n>  \t}\n>  }\n> diff --git a/revision.c b/revision.c\n> index 0173e01..dd994e9 100644\n> --- a/revision.c\n> +++ b/revision.c\n> @@ -1372,7 +1372,8 @@ static void prepare_show_merge(struct rev_info *revs)\n>  \t\t\ti++;\n>  \t}\n>  \tfree_pathspec(&revs->prune_data);\n> -\tparse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC, 0, \"\", prune);\n> +\tparse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC,\n> +\t\t       PATHSPEC_PREFER_FULL, \"\", prune);\n>  \trevs->limited = 1;\n>  }\n"},{"id":"229298","messageId":"xmqqd2mxtbm8.fsf@gitster.dls.corp.google.com","threadId":"35161","inReplyTo":"xmqq38ntusq6.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] Fix calling parse_pathspec with no paths nor PATHSPEC_PREFER_* flags","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-10-22T18:16:15Z","receivedAt":"2013-10-22T18:16:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n>\n>> When parse_pathspec() is called with no paths, the behavior could be\n>> either return no paths, or return one path that is cwd. Some commands\n>> do the former, some the latter. parse_pathspec() itself does not make\n>> either the default and requires the caller to specify either flag if\n>> it may run into this situation.\n>>\n>> I've grep'd through all parse_pathspec() call sites. Some pass\n>> neither, but those are guaranteed never pass empty path to\n>> parse_pathspec(). There are two call sites that may pass empty path\n>> and are fixed with this patch.\n>>\n>> Reported-by: Antoine Pelisse <apelisse@gmail.com>\n>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n>> ---\n>\n> Thanks.\n\nI've amended it with the following taken from Antoine's initial\nreport.\n\ndiff --git a/t/t4208-log-magic-pathspec.sh b/t/t4208-log-magic-pathspec.sh\nindex 72300b5..d8f23f4 100755\n--- a/t/t4208-log-magic-pathspec.sh\n+++ b/t/t4208-log-magic-pathspec.sh\n@@ -46,4 +46,19 @@ test_expect_success 'git log HEAD -- :/' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'command line pathspec parsing for \"git log\"' '\n+\tgit reset --hard &&\n+\t>a &&\n+\tgit add a &&\n+\tgit commit -m \"add an empty a\" --allow-empty &&\n+\techo 1 >a &&\n+\tgit commit -a -m \"update a to 1\" &&\n+\tgit checkout HEAD^ &&\n+\techo 2 >a &&\n+\tgit commit -a -m \"update a to 2\" &&\n+\ttest_must_fail git merge master &&\n+\tgit add a &&\n+\tgit log --merge -- a\n+'\n+\n test_done\n"}]}