summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-06-08 15:10:36 -0700
committerJunio C Hamano <gitster@pobox.com>2016-06-09 14:51:11 -0700
commit22475d07afb1162350ad9b1b258915afa7f895d6 (patch)
treea640e8cf2a1c3b16c01e823838e9075236040be2
parentda374f83785462a2f239759dd81919629a3b8ec8 (diff)
downloadgit-22475d07afb1162350ad9b1b258915afa7f895d6.tar.gz
attr.c: correct ugly hack for git_all_attrs()
The collect_some_attrs() function has an ugly hack since 06a604e6 (attr: avoid heavy work when we know the specified attr is not defined, 2014-12-28) added an optimization that relies on the fact that the caller knows what attributes it is interested in, so that we can leave once we know the final answer for all the attributes the caller asked. git_all_attrs() that asks "what attributes are on this path?" however does not know what attributes it is interested in, other than the vague "we are interested in all of them", which is not a very useful thing to say. As a way to disable this optimization for this caller, the said commit added a code to skip it when the caller passes a NULL for the check structure. However, it skipped the optimization not when check is NULL, but when the number of attributes being checked is 0, which is unnecessarily pessimistic. Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--attr.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/attr.c b/attr.c
index abf23d8f7c..8d8df20669 100644
--- a/attr.c
+++ b/attr.c
@@ -748,8 +748,8 @@ static int attr_check_is_dynamic(const struct git_attr_check *check)
/*
* Collect attributes for path into the array pointed to by
- * check_all_attr. If num is non-zero, only attributes in check[] are
- * collected. Otherwise all attributes are collected.
+ * check_all_attr. If check is not NULL, only attributes in
+ * check[] are collected. Otherwise all attributes are collected.
*/
static void collect_some_attrs(const char *path, int pathlen,
struct git_attr_check *check)
@@ -759,17 +759,6 @@ static void collect_some_attrs(const char *path, int pathlen,
int i, rem, dirlen;
const char *cp, *last_slash = NULL;
int basename_offset;
- int num;
- struct git_attr_check_elem *celem;
-
- if (!check) {
- /* Yuck - ugly git_all_attrs() hack! */
- celem = NULL;
- num = 0;
- } else {
- celem = check->check;
- num = check->check_nr;
- }
for (cp = path; cp < path + pathlen; cp++) {
if (*cp == '/' && cp[1])
@@ -786,9 +775,12 @@ static void collect_some_attrs(const char *path, int pathlen,
prepare_attr_stack(path, dirlen);
for (i = 0; i < attr_nr; i++)
check_all_attr[i].value = ATTR__UNKNOWN;
- if (num && !cannot_trust_maybe_real) {
+
+ if (check && !cannot_trust_maybe_real) {
+ struct git_attr_check_elem *celem = check->check;
+
rem = 0;
- for (i = 0; i < num; i++) {
+ for (i = 0; i < check->check_nr; i++) {
if (!celem[i].attr->maybe_real) {
struct git_attr_check_elem *c;
c = check_all_attr + celem[i].attr->attr_nr;
@@ -796,7 +788,7 @@ static void collect_some_attrs(const char *path, int pathlen,
rem++;
}
}
- if (rem == num)
+ if (rem == check->check_nr)
return;
}