summaryrefslogtreecommitdiff
path: root/attr.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-04-18 16:16:37 -0700
committerJunio C Hamano <junkio@cox.net>2007-04-18 16:17:13 -0700
commita5e92abde61d59a8612c5b87d0bae681e90f7fdb (patch)
treee53fefb050e87cb63d06d016ffec73e2a67f2bf2 /attr.c
parent3086486d326b00ce308208e62e0e0de831f3563b (diff)
downloadgit-a5e92abde61d59a8612c5b87d0bae681e90f7fdb.tar.gz
Fix funny types used in attribute value representation
It was bothering me a lot that I abused small integer values casted to (void *) to represent non string values in gitattributes. This corrects it by making the type of attribute values (const char *), and using the address of a few statically allocated character buffer to denote true/false. Unset attributes are represented as having NULLs as their values. Added in-header documentation to explain how git_checkattr() routine should be called. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'attr.c')
-rw-r--r--attr.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/attr.c b/attr.c
index b3496a6eb5..285e689e5a 100644
--- a/attr.c
+++ b/attr.c
@@ -1,7 +1,13 @@
#include "cache.h"
#include "attr.h"
-#define ATTR__UNKNOWN ((void *) -2)
+const char git_attr__true[] = "(builtin)true";
+const char git_attr__false[] = "\0(builtin)false";
+static const char git_attr__unknown[] = "(builtin)unknown";
+#define ATTR__TRUE git_attr__true
+#define ATTR__FALSE git_attr__false
+#define ATTR__UNSET NULL
+#define ATTR__UNKNOWN git_attr__unknown
/*
* The basic design decision here is that we are not going to have
@@ -102,7 +108,7 @@ struct git_attr *git_attr(const char *name, int len)
/* What does a matched pattern decide? */
struct attr_state {
struct git_attr *attr;
- void *setto;
+ const char *setto;
};
struct match_attr {
@@ -262,14 +268,14 @@ static void free_attr_elem(struct attr_stack *e)
struct match_attr *a = e->attrs[i];
int j;
for (j = 0; j < a->num_attr; j++) {
- void *setto = a->state[j].setto;
+ const char *setto = a->state[j].setto;
if (setto == ATTR__TRUE ||
setto == ATTR__FALSE ||
setto == ATTR__UNSET ||
setto == ATTR__UNKNOWN)
;
else
- free(setto);
+ free((char*) setto);
}
free(a);
}
@@ -478,8 +484,8 @@ static int fill_one(const char *what, struct match_attr *a, int rem)
for (i = 0; 0 < rem && i < a->num_attr; i++) {
struct git_attr *attr = a->state[i].attr;
- void **n = &(check[attr->attr_nr].value);
- void *v = a->state[i].setto;
+ const char **n = &(check[attr->attr_nr].value);
+ const char *v = a->state[i].setto;
if (*n == ATTR__UNKNOWN) {
debug_set(what, a->u.pattern, attr, v);
@@ -547,7 +553,7 @@ int git_checkattr(const char *path, int num, struct git_attr_check *check)
rem = macroexpand(stk, rem);
for (i = 0; i < num; i++) {
- void *value = check_all_attr[check[i].attr->attr_nr].value;
+ const char *value = check_all_attr[check[i].attr->attr_nr].value;
if (value == ATTR__UNKNOWN)
value = ATTR__UNSET;
check[i].value = value;