diff options
author | Russell Belfer <rb@github.com> | 2012-04-13 15:00:29 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-04-13 15:00:29 -0700 |
commit | 14a513e05866721f5ceba18cf425568d2f6af143 (patch) | |
tree | 4c31553a2c971adf579d2c5c287749ce45949c8c /src/util.c | |
parent | d1f331564da9d6110b80b538a501da0c66e59142 (diff) | |
download | libgit2-14a513e05866721f5ceba18cf425568d2f6af143.tar.gz |
Add support for pathspec to diff and status
This adds preliminary support for pathspecs to diff and status.
The implementation is not very optimized (it still looks at
every single file and evaluated the the pathspec match against
them), but it works.
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index d0ad47490..81ad10609 100644 --- a/src/util.c +++ b/src/util.c @@ -31,6 +31,35 @@ void git_strarray_free(git_strarray *array) git__free(array->strings); } +int git_strarray_copy(git_strarray *tgt, const git_strarray *src) +{ + size_t i; + + assert(tgt && src); + + memset(tgt, 0, sizeof(*tgt)); + + if (!src->count) + return 0; + + tgt->strings = git__calloc(src->count, sizeof(char *)); + GITERR_CHECK_ALLOC(tgt->strings); + + for (i = 0; i < src->count; ++i) { + tgt->strings[tgt->count] = git__strdup(src->strings[i]); + + if (!tgt->strings[tgt->count]) { + git_strarray_free(tgt); + memset(tgt, 0, sizeof(*tgt)); + return -1; + } + + tgt->count++; + } + + return 0; +} + int git__fnmatch(const char *pattern, const char *name, int flags) { int ret; |