vendor/libgit2/src/refspec.c in rugged-0.28.4 vs vendor/libgit2/src/refspec.c in rugged-0.28.4.1

- old
+ new

@@ -7,14 +7,14 @@ #include "refspec.h" #include "git2/errors.h" -#include "refs.h" #include "util.h" +#include "posix.h" +#include "refs.h" #include "vector.h" -#include "wildmatch.h" int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch) { /* Ported from https://github.com/git/git/blob/f06d47e7e0d9db709ee204ed13a8a7486149f494/remote.c#L518-636 */ @@ -211,25 +211,26 @@ int git_refspec_src_matches(const git_refspec *refspec, const char *refname) { if (refspec == NULL || refspec->src == NULL) return false; - return (wildmatch(refspec->src, refname, 0) == 0); + return (p_fnmatch(refspec->src, refname, 0) == 0); } int git_refspec_dst_matches(const git_refspec *refspec, const char *refname) { if (refspec == NULL || refspec->dst == NULL) return false; - return (wildmatch(refspec->dst, refname, 0) == 0); + return (p_fnmatch(refspec->dst, refname, 0) == 0); } static int refspec_transform( git_buf *out, const char *from, const char *to, const char *name) { const char *from_star, *to_star; + const char *name_slash, *from_slash; size_t replacement_len, star_offset; git_buf_sanitize(out); git_buf_clear(out); @@ -248,14 +249,20 @@ star_offset = from_star - from; /* the first half is copied over */ git_buf_put(out, to, to_star - to); - /* - * Copy over the name, but exclude the trailing part in "from" starting - * after the glob - */ - replacement_len = strlen(name + star_offset) - strlen(from_star + 1); + /* then we copy over the replacement, from the star's offset to the next slash in 'name' */ + name_slash = strchr(name + star_offset, '/'); + if (!name_slash) + name_slash = strrchr(name, '\0'); + + /* if there is no slash after the star in 'from', we want to copy everything over */ + from_slash = strchr(from + star_offset, '/'); + if (!from_slash) + name_slash = strrchr(name, '\0'); + + replacement_len = (name_slash - name) - star_offset; git_buf_put(out, name + star_offset, replacement_len); return git_buf_puts(out, to_star + 1); }