From: Junio C Hamano Date: Mon, 28 Jan 2013 19:13:07 +0000 (-0800) Subject: Merge branch 'nd/attr-debug-fix' into maint X-Git-Tag: v1.8.1.2~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/6d7c1c88940320c2ccde9d996181826a38ff7a81?ds=inline;hp=-c Merge branch 'nd/attr-debug-fix' into maint * nd/attr-debug-fix: attr: make it build with DEBUG_ATTR again --- 6d7c1c88940320c2ccde9d996181826a38ff7a81 diff --combined attr.c index 466c93fa50,dc2c63e3ec..b05110d586 --- a/attr.c +++ b/attr.c @@@ -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; @@@ -534,10 -530,6 +534,10 @@@ } } + 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) { @@@ -564,24 -556,17 +564,24 @@@ 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)