Fix calling parse_pathspec with no paths nor PATHSPEC_PREFER_* flags
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>
Nguyễn Thái Ngọc Duy committed
Oct 19, 2013 at 09:41 UTC
c8556c6213cf6dca63f29f98ad9d074f6c5f8233
3 files changed
+19
-2
line-log.c
+2
-1
@@ -747,7 +747,8 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
747
r = r->next;
748
}
749
paths[count] = NULL;
750
- parse_pathspec(&rev->diffopt.pathspec, 0, 0, "", paths);
750
+ parse_pathspec(&rev->diffopt.pathspec, 0,
751
+ PATHSPEC_PREFER_FULL, "", paths);
752
free(paths);
753
}
754
}
revision.c
+2
-1
@@ -1372,7 +1372,8 @@ static void prepare_show_merge(struct rev_info *revs)
1372
i++;
1373
}
1374
free_pathspec(&revs->prune_data);
1375
- parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC, 0, "", prune);
1375
+ parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC,
1376
+ PATHSPEC_PREFER_FULL, "", prune);
1377
revs->limited = 1;
1378
}
1379
t/t4208-log-magic-pathspec.sh
+15
@@ -46,4 +46,19 @@ test_expect_success 'git log HEAD -- :/' '
46
test_cmp expected actual
47
'
48
49
+test_expect_success 'command line pathspec parsing for "git log"' '
50
+ git reset --hard &&
51
+ >a &&
52
+ git add a &&
53
+ git commit -m "add an empty a" --allow-empty &&
54
+ echo 1 >a &&
55
+ git commit -a -m "update a to 1" &&
56
+ git checkout HEAD^ &&
57
+ echo 2 >a &&
58
+ git commit -a -m "update a to 2" &&
59
+ test_must_fail git merge master &&
60
+ git add a &&
61
+ git log --merge -- a
62
+'
63
+
64
test_done