aboutsummaryrefslogtreecommitdiffstats
path: root/attr.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2011-08-04 06:36:23 +0200
committerJunio C Hamano <gitster@pobox.com>2011-08-04 15:53:18 -0700
commitee548df3005d976d4e6a78b3b4454fed812ea28c (patch)
tree8e961b3c8f30bdd1b89f4736902b755491d1ecad /attr.c
parent7373eab48e284a808cde766831172d3447f9e320 (diff)
downloadgit-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.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/attr.c b/attr.c
index ab30c81b41..658112eeb6 100644
--- a/attr.c
+++ b/attr.c
@@ -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;