Allow querying all attributes on a file

Add a function, git_all_attrs(), that reports on all attributes that
are set on a path.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Michael Haggerty
2011-08-04 06:36:23 +02:00
committed by Junio C Hamano
parent 7373eab48e
commit ee548df300
3 changed files with 67 additions and 14 deletions

28
attr.c
View File

@ -747,6 +747,34 @@ int git_checkattr(const char *path, int num, struct git_attr_check *check)
return 0;
}
int git_all_attrs(const char *path, int *num, struct git_attr_check **check)
{
int i, count, j;
collect_all_attrs(path);
/* Count the number of attributes that are set. */
count = 0;
for (i = 0; i < attr_nr; i++) {
const char *value = check_all_attr[i].value;
if (value != ATTR__UNSET && value != ATTR__UNKNOWN)
++count;
}
*num = count;
*check = xmalloc(sizeof(**check) * count);
j = 0;
for (i = 0; i < attr_nr; i++) {
const char *value = check_all_attr[i].value;
if (value != ATTR__UNSET && value != ATTR__UNKNOWN) {
(*check)[j].attr = check_all_attr[i].attr;
(*check)[j].value = value;
++j;
}
}
return 0;
}
void git_attr_set_direction(enum git_attr_direction new, struct index_state *istate)
{
enum git_attr_direction old = direction;