From e4d92cdcd9450af7ae4c40de2b7c5c27a1faa138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 14 Jul 2013 15:35:27 +0700 Subject: pathspec: add copy_pathspec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- pathspec.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'pathspec.c') diff --git a/pathspec.c b/pathspec.c index 403095ba8c..8fe56cd8e9 100644 --- a/pathspec.c +++ b/pathspec.c @@ -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); +} -- cgit v1.2.1