From: Junio C Hamano Date: Thu, 3 Apr 2014 19:38:38 +0000 (-0700) Subject: Merge branch 'cb/aix' X-Git-Tag: v2.0.0-rc0~27 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/8ba87adad637b402fb309754e213ec40b74e4f18?hp=-c Merge branch 'cb/aix' * cb/aix: tests: don't rely on strerror text when testing rmdir failure dir.c: make git_fnmatch() not inline --- 8ba87adad637b402fb309754e213ec40b74e4f18 diff --combined dir.c index 99f53033ba,a1740a51c9..eb6f581270 --- a/dir.c +++ b/dir.c @@@ -49,18 -49,16 +49,18 @@@ int strncmp_icase(const char *a, const int fnmatch_icase(const char *pattern, const char *string, int flags) { - return fnmatch(pattern, string, flags | (ignore_case ? FNM_CASEFOLD : 0)); + return wildmatch(pattern, string, + flags | (ignore_case ? WM_CASEFOLD : 0), + NULL); } - inline int git_fnmatch(const struct pathspec_item *item, - const char *pattern, const char *string, - int prefix) + int git_fnmatch(const struct pathspec_item *item, + const char *pattern, const char *string, + int prefix) { if (prefix > 0) { if (ps_strncmp(item, pattern, string, prefix)) - return FNM_NOMATCH; + return WM_NOMATCH; pattern += prefix; string += prefix; } @@@ -78,9 -76,8 +78,9 @@@ NULL); else /* wildmatch has not learned no FNM_PATHNAME mode yet */ - return fnmatch(pattern, string, - item->magic & PATHSPEC_ICASE ? FNM_CASEFOLD : 0); + return wildmatch(pattern, string, + item->magic & PATHSPEC_ICASE ? WM_CASEFOLD : 0, + NULL); } static int fnmatch_icase_mem(const char *pattern, int patternlen, @@@ -198,9 -195,6 +198,9 @@@ int within_depth(const char *name, int return 1; } +#define DO_MATCH_EXCLUDE 1 +#define DO_MATCH_DIRECTORY 2 + /* * Does 'match' match the given name? * A match is found if @@@ -214,7 -208,7 +214,7 @@@ * It returns 0 when there is no match. */ static int match_pathspec_item(const struct pathspec_item *item, int prefix, - const char *name, int namelen) + const char *name, int namelen, unsigned flags) { /* name/namelen has prefix cut off by caller */ const char *match = item->match + prefix; @@@ -224,7 -218,7 +224,7 @@@ * The normal call pattern is: * 1. prefix = common_prefix_len(ps); * 2. prune something, or fill_directory - * 3. match_pathspec_depth() + * 3. match_pathspec() * * 'prefix' at #1 may be shorter than the command's prefix and * it's ok for #2 to match extra files. Those extras will be @@@ -263,11 -257,7 +263,11 @@@ if (match[matchlen-1] == '/' || name[matchlen] == '/') return MATCHED_RECURSIVELY; - } + } else if ((flags & DO_MATCH_DIRECTORY) && + match[matchlen - 1] == '/' && + namelen == matchlen - 1 && + !ps_strncmp(item, match, name, namelen)) + return MATCHED_EXACTLY; if (item->nowildcard_len < item->len && !git_fnmatch(item, match, name, @@@ -292,12 -282,12 +292,12 @@@ * pathspec did not match any names, which could indicate that the * user mistyped the nth pathspec. */ -static int match_pathspec_depth_1(const struct pathspec *ps, - const char *name, int namelen, - int prefix, char *seen, - int exclude) +static int do_match_pathspec(const struct pathspec *ps, + const char *name, int namelen, + int prefix, char *seen, + unsigned flags) { - int i, retval = 0; + int i, retval = 0, exclude = flags & DO_MATCH_EXCLUDE; GUARD_PATHSPEC(ps, PATHSPEC_FROMTOP | @@@ -337,8 -327,7 +337,8 @@@ */ if (seen && ps->items[i].magic & PATHSPEC_EXCLUDE) seen[i] = MATCHED_FNMATCH; - how = match_pathspec_item(ps->items+i, prefix, name, namelen); + how = match_pathspec_item(ps->items+i, prefix, name, + namelen, flags); if (ps->recursive && (ps->magic & PATHSPEC_MAXDEPTH) && ps->max_depth != -1 && @@@ -361,19 -350,15 +361,19 @@@ return retval; } -int match_pathspec_depth(const struct pathspec *ps, - const char *name, int namelen, - int prefix, char *seen) +int match_pathspec(const struct pathspec *ps, + const char *name, int namelen, + int prefix, char *seen, int is_dir) { int positive, negative; - positive = match_pathspec_depth_1(ps, name, namelen, prefix, seen, 0); + unsigned flags = is_dir ? DO_MATCH_DIRECTORY : 0; + positive = do_match_pathspec(ps, name, namelen, + prefix, seen, flags); if (!(ps->magic & PATHSPEC_EXCLUDE) || !positive) return positive; - negative = match_pathspec_depth_1(ps, name, namelen, prefix, seen, 1); + negative = do_match_pathspec(ps, name, namelen, + prefix, seen, + flags | DO_MATCH_EXCLUDE); return negative ? 0 : positive; } @@@ -506,25 -491,6 +506,25 @@@ void clear_exclude_list(struct exclude_ el->filebuf = NULL; } +static void trim_trailing_spaces(char *buf) +{ + int i, last_space = -1, nr_spaces, len = strlen(buf); + for (i = 0; i < len; i++) + if (buf[i] == '\\') + i++; + else if (buf[i] == ' ') { + if (last_space == -1) { + last_space = i; + nr_spaces = 1; + } else + nr_spaces++; + } else + last_space = -1; + + if (last_space != -1 && last_space + nr_spaces == len) + buf[last_space] = '\0'; +} + int add_excludes_from_file_to_list(const char *fname, const char *base, int baselen, @@@ -576,7 -542,6 +576,7 @@@ if (buf[i] == '\n') { if (entry != buf + i && entry[0] != '#') { buf[i - (i && buf[i-1] == '\r')] = 0; + trim_trailing_spaces(entry); add_exclude(entry, base, baselen, el, lineno); } lineno++; @@@ -1364,7 -1329,10 +1364,7 @@@ static struct path_simplify *create_sim for (nr = 0 ; ; nr++) { const char *match; - if (nr >= alloc) { - alloc = alloc_nr(alloc); - simplify = xrealloc(simplify, alloc * sizeof(*simplify)); - } + ALLOC_GROW(simplify, nr + 1, alloc); match = *pathspec++; if (!match) break; diff --combined t/t7001-mv.sh index 215d43d6a6,e3290aafe7..34fb1afbb3 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@@ -294,8 -294,7 +294,8 @@@ test_expect_success 'setup submodule' git submodule add ./. sub && echo content >file && git add file && - git commit -m "added sub and file" + git commit -m "added sub and file" && + git branch submodule ' test_expect_success 'git mv cannot move a submodule in a file' ' @@@ -447,8 -446,7 +447,7 @@@ test_expect_success 'checking out a com git mv sub sub2 && git commit -m "moved sub to sub2" && git checkout -q HEAD^ 2>actual && - echo "warning: unable to rmdir sub2: Directory not empty" >expected && - test_i18ncmp expected actual && + test_i18ngrep "^warning: unable to rmdir sub2:" actual && git status -s sub2 >actual && echo "?? sub2/" >expected && test_cmp expected actual && @@@ -464,14 -462,4 +463,14 @@@ ! test -s actual ' +test_expect_success 'mv -k does not accidentally destroy submodules' ' + git checkout submodule && + mkdir dummy dest && + git mv -k dummy sub dest && + git status --porcelain >actual && + grep "^R sub -> dest/sub" actual && + git reset --hard && + git checkout . +' + test_done