]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Fix calling parse_pathspec with no paths nor PATHSPEC_PREFER_* flags
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 19 Oct 2013 02:41:24 +0000 (09:41 +0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 22 Oct 2013 17:49:43 +0000 (10:49 -0700)
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.

[jc: added a test from Antoine's bug report]

Reported-by: Antoine Pelisse <apelisse@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
line-log.c
revision.c
t/t4208-log-magic-pathspec.sh

index 843a334bf06464f08ceb1a6d68d1599db2a1f1f2..b29f981cc778f138bf5f1760391345b1ce221ee3 100644 (file)
@@ -747,7 +747,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);
        }
 }
index 001623a9213293387bddd51a25039bfd6353d98c..e04fdd0cb1d462e1eae6552e6e14a22abbc2b801 100644 (file)
@@ -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;
 }
 
index 72300b5f244504540a551854cb82f81cf5391a55..d8f23f488e00dad97eeb5d22f5f0db01bcab8021 100755 (executable)
@@ -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