Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/attr.c
diff options
context:
space:
mode:
Diffstat (limited to 'attr.c')
-rw-r--r--attr.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/attr.c b/attr.c
index 5362563088..d6d71901b2 100644
--- a/attr.c
+++ b/attr.c
@@ -321,7 +321,7 @@ static void free_attr_elem(struct attr_stack *e)
}
static const char *builtin_attr[] = {
- "[attr]binary -diff -text",
+ "[attr]binary -diff -merge -text",
NULL,
};
@@ -367,8 +367,11 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
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);
@@ -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;
@@ -530,6 +534,10 @@ static void bootstrap_attr_stack(void)
}
}
+ 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) {
@@ -556,17 +564,24 @@ static void bootstrap_attr_stack(void)
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
@@ -660,6 +675,10 @@ static int path_matches(const char *pathname, int pathlen,
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),
@@ -750,9 +769,7 @@ static void collect_all_attrs(const char *path)
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)