Merge branch 'cb/aix'
authorJunio C Hamano <gitster@pobox.com>
Thu, 3 Apr 2014 19:38:38 +0000 (12:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 3 Apr 2014 19:38:38 +0000 (12:38 -0700)
* cb/aix:
tests: don't rely on strerror text when testing rmdir failure
dir.c: make git_fnmatch() not inline

1  2 
dir.c
t/t7001-mv.sh
diff --combined dir.c
index 99f53033ba174301437c65b1dfa8f8cceb74f517,a1740a51c957ae2e86412b9e20c59a51880df53d..eb6f581270f81a2e844e3396f966e67d06d27f41
--- 1/dir.c
--- 2/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
   * 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;
         * 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
  
                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,
   * 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 |
                 */
                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 &&
        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,
                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 215d43d6a6c8ce7f2b30e32dce6dfe34adc98b15,e3290aafe7c244f6258c7925ad4a051b24aa8e2e..34fb1afbb32b67565d983d68ea78a969edf98e55
@@@ -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 &&
        ! 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