git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* BUG: PATHSPEC_PREFER_CWD requires arguments
@ 2013-10-18  9:21 Antoine Pelisse
  2013-10-19  2:41 ` [PATCH] Fix calling parse_pathspec with no paths nor PATHSPEC_PREFER_* flags Nguyễn Thái Ngọc Duy
  0 siblings, 1 reply; 4+ messages in thread
From: Antoine Pelisse @ 2013-10-18  9:21 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Hello,

I ran into the following bug today: "BUG: PATHSPEC_PREFER_CWD requires
arguments". It's not that bad because I'm trying to run `git log
--merge` on an already resolved conflict. Still, I don't think I
should hit a "BUG:" :-)

Here is a script to reproduce:
git init .
>a
git add a
git commit -m"create a"
git branch other
echo "1" >a
git commit -m"add 1" a
git checkout other
echo "2" >a
git commit -m"add 2" a
git merge master
git add a
git log --merge -- a
# Fails with "fatal: BUG: PATHSPEC_PREFER_CWD requires arguments"

Here is what GDB gives me when I break on die():
Breakpoint 1, die (err=0x57e3a8 "BUG: PATHSPEC_PREFER_CWD requires
arguments") at usage.c:97
97              if (die_is_recursing()) {
(gdb) bt
#0  die (err=0x57e3a8 "BUG: PATHSPEC_PREFER_CWD requires arguments")
at usage.c:97
#1  0x00000000004ea58a in parse_pathspec (pathspec=0x7fffffffc288,
magic_mask=31, flags=0, prefix=0x580dad "", argv=0x0) at
pathspec.c:377
#2  0x00000000005097b4 in prepare_show_merge (revs=0x7fffffffc240) at
revision.c:1375
#3  0x000000000050c32e in setup_revisions (argc=2,
argv=0x7fffffffcb08, revs=0x7fffffffc240, opt=0x7fffffffc220) at
revision.c:2147
#4  0x0000000000446efc in cmd_log_init_finish (argc=4,
argv=0x7fffffffcb08, prefix=0x0, rev=0x7fffffffc240,
opt=0x7fffffffc220)
    at builtin/log.c:147
#5  0x000000000044716a in cmd_log_init (argc=4, argv=0x7fffffffcb08,
prefix=0x0, rev=0x7fffffffc240, opt=0x7fffffffc220) at
builtin/log.c:203
#6  0x0000000000448349 in cmd_log (argc=4, argv=0x7fffffffcb08,
prefix=0x0) at builtin/log.c:635
#7  0x000000000040584a in run_builtin (p=0x7bdb30, argc=4,
argv=0x7fffffffcb08) at git.c:314
#8  0x00000000004059d5 in handle_internal_command (argc=4,
argv=0x7fffffffcb08) at git.c:478
#9  0x0000000000405b88 in main (argc=4, av=0x7fffffffcb08) at git.c:575

And here is what bisect found:
commit 9a0872744315da67db3c81eb9270751e31fcc8f5
Author: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date:   Sun Jul 14 15:35:59 2013 +0700

    remove init_pathspec() in favor of parse_pathspec()

    While at there, move free_pathspec() to pathspec.c

    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thanks,
Antoine

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Fix calling parse_pathspec with no paths nor PATHSPEC_PREFER_* flags
  2013-10-18  9:21 BUG: PATHSPEC_PREFER_CWD requires arguments Antoine Pelisse
@ 2013-10-19  2:41 ` Nguyễn Thái Ngọc Duy
  2013-10-22 17:21   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2013-10-19  2:41 UTC (permalink / raw)
  To: git; +Cc: Antoine Pelisse, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

When parse_pathspec() is called with no paths, the behavior could be
either return no paths, or return one path that is cwd. Some commands
do the former, some the latter. parse_pathspec() itself does not make
either the default and requires the caller to specify either flag if
it may run into this situation.

I've grep'd through all parse_pathspec() call sites. Some pass
neither, but those are guaranteed never pass empty path to
parse_pathspec(). There are two call sites that may pass empty path
and are fixed with this patch.

Reported-by: Antoine Pelisse <apelisse@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 line-log.c | 3 ++-
 revision.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/line-log.c b/line-log.c
index 8b6e497..717638b 100644
--- a/line-log.c
+++ b/line-log.c
@@ -760,7 +760,8 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
 			r = r->next;
 		}
 		paths[count] = NULL;
-		parse_pathspec(&rev->diffopt.pathspec, 0, 0, "", paths);
+		parse_pathspec(&rev->diffopt.pathspec, 0,
+			       PATHSPEC_PREFER_FULL, "", paths);
 		free(paths);
 	}
 }
diff --git a/revision.c b/revision.c
index 0173e01..dd994e9 100644
--- a/revision.c
+++ b/revision.c
@@ -1372,7 +1372,8 @@ static void prepare_show_merge(struct rev_info *revs)
 			i++;
 	}
 	free_pathspec(&revs->prune_data);
-	parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC, 0, "", prune);
+	parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC,
+		       PATHSPEC_PREFER_FULL, "", prune);
 	revs->limited = 1;
 }
 
-- 
1.8.2.83.gc99314b

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix calling parse_pathspec with no paths nor PATHSPEC_PREFER_* flags
  2013-10-19  2:41 ` [PATCH] Fix calling parse_pathspec with no paths nor PATHSPEC_PREFER_* flags Nguyễn Thái Ngọc Duy
@ 2013-10-22 17:21   ` Junio C Hamano
  2013-10-22 18:16     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2013-10-22 17:21 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Antoine Pelisse

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> When parse_pathspec() is called with no paths, the behavior could be
> either return no paths, or return one path that is cwd. Some commands
> do the former, some the latter. parse_pathspec() itself does not make
> either the default and requires the caller to specify either flag if
> it may run into this situation.
>
> I've grep'd through all parse_pathspec() call sites. Some pass
> neither, but those are guaranteed never pass empty path to
> parse_pathspec(). There are two call sites that may pass empty path
> and are fixed with this patch.
>
> Reported-by: Antoine Pelisse <apelisse@gmail.com>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---

Thanks.

>  line-log.c | 3 ++-
>  revision.c | 3 ++-
>  2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/line-log.c b/line-log.c
> index 8b6e497..717638b 100644
> --- a/line-log.c
> +++ b/line-log.c
> @@ -760,7 +760,8 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
>  			r = r->next;
>  		}
>  		paths[count] = NULL;
> -		parse_pathspec(&rev->diffopt.pathspec, 0, 0, "", paths);
> +		parse_pathspec(&rev->diffopt.pathspec, 0,
> +			       PATHSPEC_PREFER_FULL, "", paths);
>  		free(paths);
>  	}
>  }
> diff --git a/revision.c b/revision.c
> index 0173e01..dd994e9 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -1372,7 +1372,8 @@ static void prepare_show_merge(struct rev_info *revs)
>  			i++;
>  	}
>  	free_pathspec(&revs->prune_data);
> -	parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC, 0, "", prune);
> +	parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC,
> +		       PATHSPEC_PREFER_FULL, "", prune);
>  	revs->limited = 1;
>  }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix calling parse_pathspec with no paths nor PATHSPEC_PREFER_* flags
  2013-10-22 17:21   ` Junio C Hamano
@ 2013-10-22 18:16     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2013-10-22 18:16 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Antoine Pelisse

Junio C Hamano <gitster@pobox.com> writes:

> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>
>> When parse_pathspec() is called with no paths, the behavior could be
>> either return no paths, or return one path that is cwd. Some commands
>> do the former, some the latter. parse_pathspec() itself does not make
>> either the default and requires the caller to specify either flag if
>> it may run into this situation.
>>
>> I've grep'd through all parse_pathspec() call sites. Some pass
>> neither, but those are guaranteed never pass empty path to
>> parse_pathspec(). There are two call sites that may pass empty path
>> and are fixed with this patch.
>>
>> Reported-by: Antoine Pelisse <apelisse@gmail.com>
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>
> Thanks.

I've amended it with the following taken from Antoine's initial
report.

diff --git a/t/t4208-log-magic-pathspec.sh b/t/t4208-log-magic-pathspec.sh
index 72300b5..d8f23f4 100755
--- a/t/t4208-log-magic-pathspec.sh
+++ b/t/t4208-log-magic-pathspec.sh
@@ -46,4 +46,19 @@ test_expect_success 'git log HEAD -- :/' '
 	test_cmp expected actual
 '
 
+test_expect_success 'command line pathspec parsing for "git log"' '
+	git reset --hard &&
+	>a &&
+	git add a &&
+	git commit -m "add an empty a" --allow-empty &&
+	echo 1 >a &&
+	git commit -a -m "update a to 1" &&
+	git checkout HEAD^ &&
+	echo 2 >a &&
+	git commit -a -m "update a to 2" &&
+	test_must_fail git merge master &&
+	git add a &&
+	git log --merge -- a
+'
+
 test_done

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-10-22 18:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-18  9:21 BUG: PATHSPEC_PREFER_CWD requires arguments Antoine Pelisse
2013-10-19  2:41 ` [PATCH] Fix calling parse_pathspec with no paths nor PATHSPEC_PREFER_* flags Nguyễn Thái Ngọc Duy
2013-10-22 17:21   ` Junio C Hamano
2013-10-22 18:16     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).