diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-01-30 10:06:08 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-02-01 13:46:52 -0800 |
commit | 7f8641112de8724a565a47b0f0b2a9b826b6baa9 (patch) | |
tree | a543fba28417ba7e054d11f812f53ce8c33cf60e /attr.c | |
parent | 37293768d0482f41c5aa7d34cf91b03fdfee9d4e (diff) | |
download | git-7f8641112de8724a565a47b0f0b2a9b826b6baa9.tar.gz |
attr: convert git_all_attrs() to use "struct attr_check"
This updates the other two ways the attribute check is done via an
array of "struct attr_check_item" elements. These two niches
appear only in "git check-attr".
* The caller does not know offhand what attributes it wants to ask
about and cannot use attr_check_initl() to prepare the
attr_check structure.
* The caller may not know what attributes it wants to ask at all,
and instead wants to learn everything that the given path has.
Such a caller can call attr_check_alloc() to allocate an empty
attr_check, and then call attr_check_append() to add attribute names
one by one.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'attr.c')
-rw-r--r-- | attr.c | 30 |
1 files changed, 10 insertions, 20 deletions
@@ -906,32 +906,22 @@ int git_check_attrs(const char *path, int num, struct attr_check_item *check) return 0; } -int git_all_attrs(const char *path, int *num, struct attr_check_item **check) +void git_all_attrs(const char *path, struct attr_check *check) { - int i, count, j; + int i; - collect_some_attrs(path, 0, NULL); + attr_check_reset(check); + collect_some_attrs(path, check->nr, check->items); - /* 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; - ALLOC_ARRAY(*check, count); - j = 0; for (i = 0; i < attr_nr; i++) { + const char *name = check_all_attr[i].attr->name; 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; - } + struct attr_check_item *item; + if (value == ATTR__UNSET || value == ATTR__UNKNOWN) + continue; + item = attr_check_append(check, git_attr(name)); + item->value = value; } - - return 0; } int git_check_attr(const char *path, struct attr_check *check) |