Merge branch 'nd/attr-debug-fix'
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2013 19:20:11 +0000 (11:20 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2013 19:20:12 +0000 (11:20 -0800)
Fix debugging support that was broken in earlier change.

* nd/attr-debug-fix:
attr: make it build with DEBUG_ATTR again

1  2 
attr.c
diff --combined attr.c
index d6d71901b24855a1d33ef2edeb8fbc6ce8e969dc,dc2c63e3ecb2b02d3c0ebdd9d76005362f6f16d7..233539969af6dc17e8953e4a553cae76fd9601da
--- 1/attr.c
--- 2/attr.c
+++ b/attr.c
@@@ -284,7 -284,7 +284,7 @@@ static struct match_attr *parse_attr_li
   * (reading the file from top to bottom), .gitattribute of the root
   * directory (again, reading the file from top to bottom) down to the
   * current directory, and then scan the list backwards to find the first match.
 - * This is exactly the same as what excluded() does in dir.c to deal with
 + * This is exactly the same as what is_excluded() does in dir.c to deal with
   * .gitignore
   */
  
@@@ -321,7 -321,7 +321,7 @@@ static void free_attr_elem(struct attr_
  }
  
  static const char *builtin_attr[] = {
 -      "[attr]binary -diff -text",
 +      "[attr]binary -diff -merge -text",
        NULL,
  };
  
@@@ -367,11 -367,8 +367,11 @@@ static struct attr_stack *read_attr_fro
        char buf[2048];
        int lineno = 0;
  
 -      if (!fp)
 +      if (!fp) {
 +              if (errno != ENOENT && errno != ENOTDIR)
 +                      warn_on_inaccessible(path);
                return NULL;
 +      }
        res = xcalloc(1, sizeof(*res));
        while (fgets(buf, sizeof(buf), fp))
                handle_attr_line(res, buf, path, ++lineno, macro_ok);
@@@ -515,7 -512,6 +515,7 @@@ static int git_attr_system(void
  static void bootstrap_attr_stack(void)
  {
        struct attr_stack *elem;
 +      char *xdg_attributes_file;
  
        if (attr_stack)
                return;
                }
        }
  
 +      if (!git_attributes_file) {
 +              home_config_paths(NULL, &xdg_attributes_file, "attributes");
 +              git_attributes_file = xdg_attributes_file;
 +      }
        if (git_attributes_file) {
                elem = read_attr_from_file(git_attributes_file, 1);
                if (elem) {
        attr_stack = elem;
  }
  
 +static const char *find_basename(const char *path)
 +{
 +      const char *cp, *last_slash = NULL;
 +
 +      for (cp = path; *cp; cp++) {
 +              if (*cp == '/' && cp[1])
 +                      last_slash = cp;
 +      }
 +      return last_slash ? last_slash + 1 : path;
 +}
 +
  static void prepare_attr_stack(const char *path)
  {
        struct attr_stack *elem, *info;
        int dirlen, len;
        const char *cp;
  
 -      cp = strrchr(path, '/');
 -      if (!cp)
 -              dirlen = 0;
 -      else
 -              dirlen = cp - path;
 +      dirlen = find_basename(path) - path;
  
        /*
         * At the bottom of the attribute stack is the built-in
@@@ -675,10 -660,6 +675,10 @@@ static int path_matches(const char *pat
        const char *pattern = pat->pattern;
        int prefix = pat->nowildcardlen;
  
 +      if ((pat->flags & EXC_FLAG_MUSTBEDIR) &&
 +          ((!pathlen) || (pathname[pathlen-1] != '/')))
 +              return 0;
 +
        if (pat->flags & EXC_FLAG_NODIR) {
                return match_basename(basename,
                                      pathlen - (basename - pathname),
@@@ -704,7 -685,7 +704,7 @@@ static int fill_one(const char *what, s
  
                if (*n == ATTR__UNKNOWN) {
                        debug_set(what,
-                                 a->is_macro ? a->u.attr->name : a->u.pattern,
+                                 a->is_macro ? a->u.attr->name : a->u.pat.pattern,
                                  attr, v);
                        *n = v;
                        rem--;
@@@ -769,7 -750,9 +769,7 @@@ static void collect_all_attrs(const cha
        for (i = 0; i < attr_nr; i++)
                check_all_attr[i].value = ATTR__UNKNOWN;
  
 -      basename = strrchr(path, '/');
 -      basename = basename ? basename + 1 : path;
 -
 +      basename = find_basename(path);
        pathlen = strlen(path);
        rem = attr_nr;
        for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)