pathspec: add copy_pathspec
Because free_pathspec wants to free "items" pointer in the pathspec structure, a simple structure assignment is not enough if you want to copy an existing pathspec into another. Freeing the original will damage the copy unless a deep copy is made. Note that the strings in pathspec->items->match and the array pathspec->raw[] are still shared between the original and the copy. 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
f01d9820e7
commit
e4d92cdcd9
@ -249,3 +249,11 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
|
||||
return NULL;
|
||||
return pathspec;
|
||||
}
|
||||
|
||||
void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
|
||||
{
|
||||
*dst = *src;
|
||||
dst->items = xmalloc(sizeof(struct pathspec_item) * dst->nr);
|
||||
memcpy(dst->items, src->items,
|
||||
sizeof(struct pathspec_item) * dst->nr);
|
||||
}
|
||||
|
Reference in New Issue
Block a user