mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
parse_pathspec: make sure the prefix part is wildcard-free
Prepending prefix to pathspec is a trick to workaround the fact that commands can be executed in a subdirectory, but all git commands run at worktree's root. The prefix part should always be treated as literal string. Make it so. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
b3920bbdc5
commit
645a29c40a
15
path.c
15
path.c
@@ -492,8 +492,14 @@ const char *relative_path(const char *abs, const char *base)
|
||||
*
|
||||
* Note that this function is purely textual. It does not follow symlinks,
|
||||
* verify the existence of the path, or make any system calls.
|
||||
*
|
||||
* prefix_len != NULL is for a specific case of prefix_pathspec():
|
||||
* assume that src == dst and src[0..prefix_len-1] is already
|
||||
* normalized, any time "../" eats up to the prefix_len part,
|
||||
* prefix_len is reduced. In the end prefix_len is the remaining
|
||||
* prefix that has not been overridden by user pathspec.
|
||||
*/
|
||||
int normalize_path_copy(char *dst, const char *src)
|
||||
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
|
||||
{
|
||||
char *dst0;
|
||||
|
||||
@@ -568,11 +574,18 @@ int normalize_path_copy(char *dst, const char *src)
|
||||
/* Windows: dst[-1] cannot be backslash anymore */
|
||||
while (dst0 < dst && dst[-1] != '/')
|
||||
dst--;
|
||||
if (prefix_len && *prefix_len > dst - dst0)
|
||||
*prefix_len = dst - dst0;
|
||||
}
|
||||
*dst = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
int normalize_path_copy(char *dst, const char *src)
|
||||
{
|
||||
return normalize_path_copy_len(dst, src, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* path = Canonical absolute path
|
||||
* prefixes = string_list containing normalized, absolute paths without
|
||||
|
||||
Reference in New Issue
Block a user