From c63793ee81ee6961b2430e88379d491fa8e91bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicent=20Mart=C3=AD?= Date: Fri, 2 Mar 2012 03:51:45 +0100 Subject: attr: Change the attribute check macros The point of having `GIT_ATTR_TRUE` and `GIT_ATTR_FALSE` macros is to be able to change the way that true and false values are stored inside of the returned gitattributes value pointer. However, if these macros are implemented as a simple rename for the `git_attr__true` pointer, they will always be used with the `==` operator, and hence we cannot really change the implementation to any other way that doesn't imply using special pointer values and comparing them! We need to do the same thing that core Git does, which is using a function macro. With `GIT_ATTR_TRUE(attr)`, we can change internally the way that these values are stored to anything we want. This commit does that, and rewrites a large chunk of the attributes test suite to remove duplicated code for expected attributes, and to properly test the function macro behavior instead of comparing pointers. --- src/attr_file.c | 6 +++--- src/crlf.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/attr_file.c b/src/attr_file.c index a1b69a5bb..3783b5ef3 100644 --- a/src/attr_file.c +++ b/src/attr_file.c @@ -458,12 +458,12 @@ int git_attr_assignment__parse( } assign->name_hash = 5381; - assign->value = GIT_ATTR_TRUE; + assign->value = git_attr__true; assign->is_allocated = 0; /* look for magic name prefixes */ if (*scan == '-') { - assign->value = GIT_ATTR_FALSE; + assign->value = git_attr__false; scan++; } else if (*scan == '!') { assign->value = NULL; /* explicit unspecified state */ @@ -510,7 +510,7 @@ int git_attr_assignment__parse( } /* expand macros (if given a repo with a macro cache) */ - if (repo != NULL && assign->value == GIT_ATTR_TRUE) { + if (repo != NULL && assign->value == git_attr__true) { git_attr_rule *macro = git_hashtable_lookup(repo->attrcache.macros, assign->name); diff --git a/src/crlf.c b/src/crlf.c index feaa687ee..e74f8e89b 100644 --- a/src/crlf.c +++ b/src/crlf.c @@ -25,13 +25,13 @@ struct crlf_filter { static int check_crlf(const char *value) { - if (value == git_attr__true) + if (GIT_ATTR_TRUE(value)) return GIT_CRLF_TEXT; - if (value == git_attr__false) + if (GIT_ATTR_FALSE(value)) return GIT_CRLF_BINARY; - if (value == NULL) + if (GIT_ATTR_UNSPECIFIED(value)) return GIT_CRLF_GUESS; if (strcmp(value, "input") == 0) @@ -45,7 +45,7 @@ static int check_crlf(const char *value) static int check_eol(const char *value) { - if (value == NULL) + if (GIT_ATTR_UNSPECIFIED(value)) return GIT_EOL_UNSET; if (strcmp(value, "lf") == 0) -- cgit v1.2.1