diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2011-08-04 06:36:23 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-08-04 15:53:18 -0700 |
commit | ee548df3005d976d4e6a78b3b4454fed812ea28c (patch) | |
tree | 8e961b3c8f30bdd1b89f4736902b755491d1ecad /attr.c | |
parent | 7373eab48e284a808cde766831172d3447f9e320 (diff) | |
download | git-ee548df3005d976d4e6a78b3b4454fed812ea28c.tar.gz |
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>
Diffstat (limited to 'attr.c')
-rw-r--r-- | attr.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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; |