/* what is the common non-wildcard prefix for all items in the pathspec */ char *git_pathspec_prefix(const git_strarray *pathspec) { git_buf prefix = GIT_BUF_INIT; const char *scan; if (!pathspec || !pathspec->count || git_buf_text_common_prefix(&prefix, pathspec) < 0) return NULL; /* diff prefix will only be leading non-wildcards */ for (scan = prefix.ptr; *scan; ++scan) { if (git__iswildcard(*scan) && (scan == prefix.ptr || (*(scan - 1) != '\\'))) break; } git_buf_truncate(&prefix, scan - prefix.ptr); if (prefix.size <= 0) { git_buf_free(&prefix); return NULL; } git_buf_text_unescape(&prefix); return git_buf_detach(&prefix); }
static void assert_unescape(char *expected, char *to_unescape) { git_buf buf = GIT_BUF_INIT; cl_git_pass(git_buf_sets(&buf, to_unescape)); git_buf_text_unescape(&buf); cl_assert_equal_s(expected, buf.ptr); cl_assert_equal_sz(strlen(expected), buf.size); git_buf_free(&buf); }