summaryrefslogtreecommitdiff
path: root/attr.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-01-29 11:18:54 -0800
committerJunio C Hamano <gitster@pobox.com>2013-01-29 11:20:10 -0800
commit025ea586e65bac27f7b15c4da8f1d3bd381c3a14 (patch)
treeb4cd96f76246fba1ddebfe930e7532fe01cfc875 /attr.c
parentda2987d4c3be50bb9d888d145ba42fe26c7045f3 (diff)
parent9db9eecfe5c2490d17c0d4bd5452e4cb1d0948c5 (diff)
downloadgit-025ea586e65bac27f7b15c4da8f1d3bd381c3a14.tar.gz
Merge branch 'nd/fix-directory-attrs-off-by-one' into maint
The attribute mechanism didn't allow limiting attributes to be applied to only a single directory itself with "path/" like the exclude mechanism does. The initial implementation of this that was merged to 'maint' and 1.8.1.1 had severe performance degradations. * nd/fix-directory-attrs-off-by-one: attr: avoid calling find_basename() twice per path attr: fix off-by-one directory component length calculation
Diffstat (limited to 'attr.c')
-rw-r--r--attr.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/attr.c b/attr.c
index b05110d586..8985c5c25b 100644
--- a/attr.c
+++ b/attr.c
@@ -564,25 +564,12 @@ 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)
+static void prepare_attr_stack(const char *path, int dirlen)
{
struct attr_stack *elem, *info;
- int dirlen, len;
+ int len;
const char *cp;
- dirlen = find_basename(path) - path;
-
/*
* At the bottom of the attribute stack is the built-in
* set of attribute definitions, followed by the contents
@@ -762,15 +749,26 @@ static int macroexpand_one(int attr_nr, int rem)
static void collect_all_attrs(const char *path)
{
struct attr_stack *stk;
- int i, pathlen, rem;
- const char *basename;
+ int i, pathlen, rem, dirlen;
+ const char *basename, *cp, *last_slash = NULL;
+
+ for (cp = path; *cp; cp++) {
+ if (*cp == '/' && cp[1])
+ last_slash = cp;
+ }
+ pathlen = cp - path;
+ if (last_slash) {
+ basename = last_slash + 1;
+ dirlen = last_slash - path;
+ } else {
+ basename = path;
+ dirlen = 0;
+ }
- prepare_attr_stack(path);
+ prepare_attr_stack(path, dirlen);
for (i = 0; i < attr_nr; i++)
check_all_attr[i].value = ATTR__UNKNOWN;
- basename = find_basename(path);
- pathlen = strlen(path);
rem = attr_nr;
for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
rem = fill(path, pathlen, basename, stk, rem);