summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3086486)
raw | patch | inline | side by side (parent: 3086486)
author | Junio C Hamano <junkio@cox.net> | |
Wed, 18 Apr 2007 23:16:37 +0000 (16:16 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 18 Apr 2007 23:17:13 +0000 (16:17 -0700) |
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>
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>
attr.c | patch | blob | history | |
attr.h | patch | blob | history | |
builtin-check-attr.c | patch | blob | history | |
convert.c | patch | blob | history | |
diff.c | patch | blob | history | |
merge-recursive.c | patch | blob | history |
index b3496a6eb529c111ff0378a517b13ca89cb74d5a..285e689e5adff6237e179f5d64f11d3f3c09a09d 100644 (file)
--- a/attr.c
+++ b/attr.c
#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
/* What does a matched pattern decide? */
struct attr_state {
struct git_attr *attr;
- void *setto;
+ const char *setto;
};
struct match_attr {
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);
}
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);
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;
index 8ec2d3d35ce02d15adb0c3b4c72ce2d435d5a1ae..f1c2038b0923d3130937eef965667204a8634e6d 100644 (file)
--- a/attr.h
+++ b/attr.h
/* An attribute is a pointer to this opaque structure */
struct git_attr;
+/*
+ * Given a string, return the gitattribute object that
+ * corresponds to it.
+ */
struct git_attr *git_attr(const char *, int);
/* Internal use */
-#define ATTR__TRUE ((void *) 1)
-#define ATTR__FALSE ((void *) 0)
-#define ATTR__UNSET ((void *) -1)
+extern const char git_attr__true[];
+extern const char git_attr__false[];
/* For public to check git_attr_check results */
-#define ATTR_TRUE(v) ((v) == ATTR__TRUE)
-#define ATTR_FALSE(v) ((v) == ATTR__FALSE)
-#define ATTR_UNSET(v) ((v) == ATTR__UNSET)
+#define ATTR_TRUE(v) ((v) == git_attr__true)
+#define ATTR_FALSE(v) ((v) == git_attr__false)
+#define ATTR_UNSET(v) ((v) == NULL)
+/*
+ * Send one or more git_attr_check to git_checkattr(), and
+ * each 'value' member tells what its value is.
+ * Unset one is returned as NULL.
+ */
struct git_attr_check {
struct git_attr *attr;
- void *value;
+ const char *value;
};
int git_checkattr(const char *path, int, struct git_attr_check *);
diff --git a/builtin-check-attr.c b/builtin-check-attr.c
index 6983a73c1b387e5eb4a0c8dbc6b9e72b93735245..9d77f76ff1230df76278b528ef44d6837edb2741 100644 (file)
--- a/builtin-check-attr.c
+++ b/builtin-check-attr.c
if (git_checkattr(argv[i], cnt, check))
die("git_checkattr died");
for (j = 0; j < cnt; j++) {
- void *value = check[j].value;
+ const char *value = check[j].value;
if (ATTR_TRUE(value))
value = "set";
value = "unspecified";
write_name_quoted("", 0, argv[i], 1, stdout);
- printf(": %s: %s\n", argv[j+1], (char *) value);
+ printf(": %s: %s\n", argv[j+1], value);
}
}
return 0;
diff --git a/convert.c b/convert.c
index 68bb70f12ff49fede13bce01e2d8a2f0d64734d1..a5f60c7c6b729efbc7b98b1f5ac098cbf1bf9728 100644 (file)
--- a/convert.c
+++ b/convert.c
setup_crlf_check(&attr_crlf_check);
if (!git_checkattr(path, 1, &attr_crlf_check)) {
- void *value = attr_crlf_check.value;
+ const char *value = attr_crlf_check.value;
if (ATTR_TRUE(value))
return 1;
else if (ATTR_FALSE(value))
index a32078ea0177cb2a57e4a470bf6e50c81d6dd70d..5f501864e60899c7cdcaedeadaf996310a74be7b 100644 (file)
--- a/diff.c
+++ b/diff.c
setup_diff_attr_check(&attr_diff_check);
if (!git_checkattr(one->path, 1, &attr_diff_check)) {
- void *value = attr_diff_check.value;
+ const char *value = attr_diff_check.value;
if (ATTR_TRUE(value))
return 0;
else if (ATTR_FALSE(value))
;
else
die("unknown value %s given to 'diff' attribute",
- (char *)value);
+ value);
}
if (!one->data) {
diff --git a/merge-recursive.c b/merge-recursive.c
index 7b5ca8e717217011ffde95434e58d47e401c40e5..ec8438b463a5b096ceeca916126e440198ff4740 100644 (file)
--- a/merge-recursive.c
+++ b/merge-recursive.c
git_config(read_merge_config);
}
-static const struct ll_merge_driver *find_ll_merge_driver(void *merge_attr)
+static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr)
{
struct ll_merge_driver *fn;
const char *name;
return &ll_merge_drv[LL_TEXT_MERGE];
}
-static void *git_path_check_merge(const char *path)
+static const char *git_path_check_merge(const char *path)
{
static struct git_attr_check attr_merge_check;
attr_merge_check.attr = git_attr("merge", 5);
if (git_checkattr(path, 1, &attr_merge_check))
- return ATTR__UNSET;
+ return NULL;
return attr_merge_check.value;
}
mmfile_t orig, src1, src2;
char *name1, *name2;
int merge_status;
- void *merge_attr;
+ const char *ll_driver_name;
const struct ll_merge_driver *driver;
name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
fill_mm(a->sha1, &src1);
fill_mm(b->sha1, &src2);
- merge_attr = git_path_check_merge(a->path);
- driver = find_ll_merge_driver(merge_attr);
+ ll_driver_name = git_path_check_merge(a->path);
+ driver = find_ll_merge_driver(ll_driver_name);
if (index_only && driver->recursive) {
- merge_attr = git_attr(driver->recursive, strlen(driver->recursive));
+ void *merge_attr;
+
+ ll_driver_name = driver->recursive;
+ merge_attr = git_attr(ll_driver_name, strlen(ll_driver_name));
driver = find_ll_merge_driver(merge_attr);
}
merge_status = driver->fn(driver, a->path,