2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
10 #include "repository.h"
12 #include "attrcache.h"
14 #include "git2/blob.h"
15 #include "git2/tree.h"
18 #include "wildmatch.h"
21 static void attr_file_free(git_attr_file
*file
)
23 bool unlock
= !git_mutex_lock(&file
->lock
);
24 git_attr_file__clear_rules(file
, false);
25 git_pool_clear(&file
->pool
);
27 git_mutex_unlock(&file
->lock
);
28 git_mutex_free(&file
->lock
);
30 git__memzero(file
, sizeof(*file
));
34 int git_attr_file__new(
36 git_attr_file_entry
*entry
,
37 git_attr_file_source source
)
39 git_attr_file
*attrs
= git__calloc(1, sizeof(git_attr_file
));
40 GIT_ERROR_CHECK_ALLOC(attrs
);
42 if (git_mutex_init(&attrs
->lock
) < 0) {
43 git_error_set(GIT_ERROR_OS
, "failed to initialize lock");
48 git_pool_init(&attrs
->pool
, 1);
49 GIT_REFCOUNT_INC(attrs
);
51 attrs
->source
= source
;
56 int git_attr_file__clear_rules(git_attr_file
*file
, bool need_lock
)
61 if (need_lock
&& git_mutex_lock(&file
->lock
) < 0) {
62 git_error_set(GIT_ERROR_OS
, "failed to lock attribute file");
66 git_vector_foreach(&file
->rules
, i
, rule
)
67 git_attr_rule__free(rule
);
68 git_vector_free(&file
->rules
);
71 git_mutex_unlock(&file
->lock
);
76 void git_attr_file__free(git_attr_file
*file
)
80 GIT_REFCOUNT_DEC(file
, attr_file_free
);
83 static int attr_file_oid_from_index(
84 git_oid
*oid
, git_repository
*repo
, const char *path
)
89 const git_index_entry
*entry
;
91 if ((error
= git_repository_index__weakptr(&idx
, repo
)) < 0 ||
92 (error
= git_index__find_pos(&pos
, idx
, path
, 0, 0)) < 0)
95 if (!(entry
= git_index_get_byindex(idx
, pos
)))
102 int git_attr_file__load(
104 git_repository
*repo
,
105 git_attr_session
*attr_session
,
106 git_attr_file_entry
*entry
,
107 git_attr_file_source source
,
108 git_attr_file_parser parser
,
112 git_tree
*tree
= NULL
;
113 git_tree_entry
*tree_entry
= NULL
;
114 git_blob
*blob
= NULL
;
115 git_buf content
= GIT_BUF_INIT
;
116 const char *content_str
;
119 bool nonexistent
= false;
123 git_object_size_t blobsize
;
128 case GIT_ATTR_FILE__IN_MEMORY
:
129 /* in-memory attribute file doesn't need data */
131 case GIT_ATTR_FILE__FROM_INDEX
: {
132 if ((error
= attr_file_oid_from_index(&id
, repo
, entry
->path
)) < 0 ||
133 (error
= git_blob_lookup(&blob
, repo
, &id
)) < 0)
136 /* Do not assume that data straight from the ODB is NULL-terminated;
137 * copy the contents of a file to a buffer to work on */
138 blobsize
= git_blob_rawsize(blob
);
140 GIT_ERROR_CHECK_BLOBSIZE(blobsize
);
141 git_buf_put(&content
, git_blob_rawcontent(blob
), (size_t)blobsize
);
144 case GIT_ATTR_FILE__FROM_FILE
: {
147 /* For open or read errors, pretend that we got ENOTFOUND. */
148 /* TODO: issue warning when warning API is available */
150 if (p_stat(entry
->fullpath
, &st
) < 0 ||
151 S_ISDIR(st
.st_mode
) ||
152 (fd
= git_futils_open_ro(entry
->fullpath
)) < 0 ||
153 (error
= git_futils_readbuffer_fd(&content
, fd
, (size_t)st
.st_size
)) < 0)
161 case GIT_ATTR_FILE__FROM_HEAD
: {
162 if ((error
= git_repository_head_tree(&tree
, repo
)) < 0 ||
163 (error
= git_tree_entry_bypath(&tree_entry
, tree
, entry
->path
)) < 0 ||
164 (error
= git_blob_lookup(&blob
, repo
, git_tree_entry_id(tree_entry
))) < 0)
168 * Do not assume that data straight from the ODB is NULL-terminated;
169 * copy the contents of a file to a buffer to work on.
171 blobsize
= git_blob_rawsize(blob
);
173 GIT_ERROR_CHECK_BLOBSIZE(blobsize
);
174 if ((error
= git_buf_put(&content
,
175 git_blob_rawcontent(blob
), (size_t)blobsize
)) < 0)
181 git_error_set(GIT_ERROR_INVALID
, "unknown file source %d", source
);
185 if ((error
= git_attr_file__new(&file
, entry
, source
)) < 0)
188 /* advance over a UTF8 BOM */
189 content_str
= git_buf_cstr(&content
);
190 bom_offset
= git_buf_text_detect_bom(&bom
, &content
);
192 if (bom
== GIT_BOM_UTF8
)
193 content_str
+= bom_offset
;
195 /* store the key of the attr_reader; don't bother with cache
196 * invalidation during the same attr reader session.
199 file
->session_key
= attr_session
->key
;
201 if (parser
&& (error
= parser(repo
, file
, content_str
, allow_macros
)) < 0) {
202 git_attr_file__free(file
);
206 /* write cache breakers */
208 file
->nonexistent
= 1;
209 else if (source
== GIT_ATTR_FILE__FROM_INDEX
)
210 git_oid_cpy(&file
->cache_data
.oid
, git_blob_id(blob
));
211 else if (source
== GIT_ATTR_FILE__FROM_HEAD
)
212 git_oid_cpy(&file
->cache_data
.oid
, git_tree_id(tree
));
213 else if (source
== GIT_ATTR_FILE__FROM_FILE
)
214 git_futils_filestamp_set_from_stat(&file
->cache_data
.stamp
, &st
);
215 /* else always cacheable */
221 git_tree_entry_free(tree_entry
);
223 git_buf_dispose(&content
);
228 int git_attr_file__out_of_date(
229 git_repository
*repo
,
230 git_attr_session
*attr_session
,
236 /* we are never out of date if we just created this data in the same
237 * attr_session; otherwise, nonexistent files must be invalidated
239 if (attr_session
&& attr_session
->key
== file
->session_key
)
241 else if (file
->nonexistent
)
244 switch (file
->source
) {
245 case GIT_ATTR_FILE__IN_MEMORY
:
248 case GIT_ATTR_FILE__FROM_FILE
:
249 return git_futils_filestamp_check(
250 &file
->cache_data
.stamp
, file
->entry
->fullpath
);
252 case GIT_ATTR_FILE__FROM_INDEX
: {
256 if ((error
= attr_file_oid_from_index(
257 &id
, repo
, file
->entry
->path
)) < 0)
260 return (git_oid__cmp(&file
->cache_data
.oid
, &id
) != 0);
263 case GIT_ATTR_FILE__FROM_HEAD
: {
267 if ((error
= git_repository_head_tree(&tree
, repo
)) < 0)
270 error
= git_oid__cmp(&file
->cache_data
.oid
, git_tree_id(tree
));
277 git_error_set(GIT_ERROR_INVALID
, "invalid file type %d", file
->source
);
282 static int sort_by_hash_and_name(const void *a_raw
, const void *b_raw
);
283 static void git_attr_rule__clear(git_attr_rule
*rule
);
284 static bool parse_optimized_patterns(
285 git_attr_fnmatch
*spec
,
287 const char *pattern
);
289 int git_attr_file__parse_buffer(
290 git_repository
*repo
, git_attr_file
*attrs
, const char *data
, bool allow_macros
)
292 const char *scan
= data
, *context
= NULL
;
293 git_attr_rule
*rule
= NULL
;
296 /* If subdir file path, convert context for file paths */
297 if (attrs
->entry
&& git_path_root(attrs
->entry
->path
) < 0 &&
298 !git__suffixcmp(attrs
->entry
->path
, "/" GIT_ATTR_FILE
))
299 context
= attrs
->entry
->path
;
301 if (git_mutex_lock(&attrs
->lock
) < 0) {
302 git_error_set(GIT_ERROR_OS
, "failed to lock attribute file");
306 while (!error
&& *scan
) {
307 /* Allocate rule if needed, otherwise re-use previous rule */
309 rule
= git__calloc(1, sizeof(*rule
));
310 GIT_ERROR_CHECK_ALLOC(rule
);
312 git_attr_rule__clear(rule
);
314 rule
->match
.flags
= GIT_ATTR_FNMATCH_ALLOWNEG
| GIT_ATTR_FNMATCH_ALLOWMACRO
;
316 /* Parse the next "pattern attr attr attr" line */
317 if ((error
= git_attr_fnmatch__parse(&rule
->match
, &attrs
->pool
, context
, &scan
)) < 0 ||
318 (error
= git_attr_assignment__parse(repo
, &attrs
->pool
, &rule
->assigns
, &scan
)) < 0)
320 if (error
!= GIT_ENOTFOUND
)
326 if (rule
->match
.flags
& GIT_ATTR_FNMATCH_MACRO
) {
327 /* TODO: warning if macro found in file below repo root */
330 if ((error
= git_attr_cache__insert_macro(repo
, rule
)) < 0)
332 } else if ((error
= git_vector_insert(&attrs
->rules
, rule
)) < 0)
339 git_mutex_unlock(&attrs
->lock
);
340 git_attr_rule__free(rule
);
345 uint32_t git_attr_file__name_hash(const char *name
)
350 while ((c
= (int)*name
++) != 0)
351 h
= ((h
<< 5) + h
) + c
;
355 int git_attr_file__lookup_one(
368 name
.name_hash
= git_attr_file__name_hash(attr
);
370 git_attr_file__foreach_matching_rule(file
, path
, i
, rule
) {
373 if (!git_vector_bsearch(&pos
, &rule
->assigns
, &name
)) {
374 *value
= ((git_attr_assignment
*)
375 git_vector_get(&rule
->assigns
, pos
))->value
;
383 int git_attr_file__load_standalone(git_attr_file
**out
, const char *path
)
385 git_buf content
= GIT_BUF_INIT
;
386 git_attr_file
*file
= NULL
;
389 if ((error
= git_futils_readbuffer(&content
, path
)) < 0)
393 * Because the cache entry is allocated from the file's own pool, we
394 * don't have to free it - freeing file+pool will free cache entry, too.
397 if ((error
= git_attr_file__new(&file
, NULL
, GIT_ATTR_FILE__FROM_FILE
)) < 0 ||
398 (error
= git_attr_file__parse_buffer(NULL
, file
, content
.ptr
, true)) < 0 ||
399 (error
= git_attr_cache__alloc_file_entry(&file
->entry
, NULL
, path
, &file
->pool
)) < 0)
405 git_attr_file__free(file
);
406 git_buf_dispose(&content
);
411 bool git_attr_fnmatch__match(
412 git_attr_fnmatch
*match
,
415 const char *relpath
= path
->path
;
416 const char *filename
;
420 * If the rule was generated in a subdirectory, we must only
421 * use it for paths inside that directory. We can thus return
422 * a non-match if the prefixes don't match.
424 if (match
->containing_dir
) {
425 if (match
->flags
& GIT_ATTR_FNMATCH_ICASE
) {
426 if (git__strncasecmp(path
->path
, match
->containing_dir
, match
->containing_dir_length
))
429 if (git__prefixcmp(path
->path
, match
->containing_dir
))
433 relpath
+= match
->containing_dir_length
;
436 if (match
->flags
& GIT_ATTR_FNMATCH_ICASE
)
437 flags
|= WM_CASEFOLD
;
439 if (match
->flags
& GIT_ATTR_FNMATCH_FULLPATH
) {
441 flags
|= WM_PATHNAME
;
443 filename
= path
->basename
;
446 if ((match
->flags
& GIT_ATTR_FNMATCH_DIRECTORY
) && !path
->is_dir
) {
450 * for attribute checks or checks at the root of this match's
451 * containing_dir (or root of the repository if no containing_dir),
454 if (!(match
->flags
& GIT_ATTR_FNMATCH_IGNORE
) ||
455 path
->basename
== relpath
)
458 /* fail match if this is a file with same name as ignored folder */
459 samename
= (match
->flags
& GIT_ATTR_FNMATCH_ICASE
) ?
460 !strcasecmp(match
->pattern
, relpath
) :
461 !strcmp(match
->pattern
, relpath
);
466 return (wildmatch(match
->pattern
, relpath
, flags
) == WM_MATCH
);
469 return (wildmatch(match
->pattern
, filename
, flags
) == WM_MATCH
);
472 bool git_attr_rule__match(
476 bool matched
= git_attr_fnmatch__match(&rule
->match
, path
);
478 if (rule
->match
.flags
& GIT_ATTR_FNMATCH_NEGATIVE
)
484 git_attr_assignment
*git_attr_rule__lookup_assignment(
485 git_attr_rule
*rule
, const char *name
)
490 key
.name_hash
= git_attr_file__name_hash(name
);
492 if (git_vector_bsearch(&pos
, &rule
->assigns
, &key
))
495 return git_vector_get(&rule
->assigns
, pos
);
498 int git_attr_path__init(
499 git_attr_path
*info
, const char *path
, const char *base
, git_dir_flag dir_flag
)
503 /* build full path as best we can */
504 git_buf_init(&info
->full
, 0);
506 if (git_path_join_unrooted(&info
->full
, path
, base
, &root
) < 0)
509 info
->path
= info
->full
.ptr
+ root
;
511 /* remove trailing slashes */
512 while (info
->full
.size
> 0) {
513 if (info
->full
.ptr
[info
->full
.size
- 1] != '/')
517 info
->full
.ptr
[info
->full
.size
] = '\0';
519 /* skip leading slashes in path */
520 while (*info
->path
== '/')
523 /* find trailing basename component */
524 info
->basename
= strrchr(info
->path
, '/');
527 if (!info
->basename
|| !*info
->basename
)
528 info
->basename
= info
->path
;
532 case GIT_DIR_FLAG_FALSE
:
536 case GIT_DIR_FLAG_TRUE
:
540 case GIT_DIR_FLAG_UNKNOWN
:
542 info
->is_dir
= (int)git_path_isdir(info
->full
.ptr
);
549 void git_attr_path__free(git_attr_path
*info
)
551 git_buf_dispose(&info
->full
);
553 info
->basename
= NULL
;
557 * From gitattributes(5):
559 * Patterns have the following format:
561 * - A blank line matches no files, so it can serve as a separator for
564 * - A line starting with # serves as a comment.
566 * - An optional prefix ! which negates the pattern; any matching file
567 * excluded by a previous pattern will become included again. If a negated
568 * pattern matches, this will override lower precedence patterns sources.
570 * - If the pattern ends with a slash, it is removed for the purpose of the
571 * following description, but it would only find a match with a directory. In
572 * other words, foo/ will match a directory foo and paths underneath it, but
573 * will not match a regular file or a symbolic link foo (this is consistent
574 * with the way how pathspec works in general in git).
576 * - If the pattern does not contain a slash /, git treats it as a shell glob
577 * pattern and checks for a match against the pathname without leading
580 * - Otherwise, git treats the pattern as a shell glob suitable for consumption
581 * by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will
582 * not match a / in the pathname. For example, "Documentation/\*.html" matches
583 * "Documentation/git.html" but not "Documentation/ppc/ppc.html". A leading
584 * slash matches the beginning of the pathname; for example, "/\*.c" matches
585 * "cat-file.c" but not "mozilla-sha1/sha1.c".
589 * Determine the length of trailing spaces. Escaped spaces do not count as
590 * trailing whitespace.
592 static size_t trailing_space_length(const char *p
, size_t len
)
595 for (n
= len
; n
; n
--) {
596 if (p
[n
-1] != ' ' && p
[n
-1] != '\t')
600 * Count escape-characters before space. In case where it's an
601 * even number of escape characters, then the escape char itself
602 * is escaped and the whitespace is an unescaped whitespace.
603 * Otherwise, the last escape char is not escaped and the
604 * whitespace in an escaped whitespace.
607 while (i
> 1 && p
[i
-2] == '\\')
615 static size_t unescape_spaces(char *str
)
617 char *scan
, *pos
= str
;
618 bool escaped
= false;
623 for (scan
= str
; *scan
; scan
++) {
624 if (!escaped
&& *scan
== '\\') {
629 /* Only insert the escape character for escaped non-spaces */
630 if (escaped
&& !git__isspace(*scan
))
644 * This will return 0 if the spec was filled out,
645 * GIT_ENOTFOUND if the fnmatch does not require matching, or
646 * another error code there was an actual problem.
648 int git_attr_fnmatch__parse(
649 git_attr_fnmatch
*spec
,
654 const char *pattern
, *scan
;
655 int slash_count
, allow_space
;
658 assert(spec
&& base
&& *base
);
660 if (parse_optimized_patterns(spec
, pool
, *base
))
663 spec
->flags
= (spec
->flags
& GIT_ATTR_FNMATCH__INCOMING
);
664 allow_space
= ((spec
->flags
& GIT_ATTR_FNMATCH_ALLOWSPACE
) != 0);
668 while (!allow_space
&& git__isspace(*pattern
))
671 if (!*pattern
|| *pattern
== '#' || *pattern
== '\n' ||
672 (*pattern
== '\r' && *(pattern
+ 1) == '\n')) {
673 *base
= git__next_line(pattern
);
674 return GIT_ENOTFOUND
;
677 if (*pattern
== '[' && (spec
->flags
& GIT_ATTR_FNMATCH_ALLOWMACRO
) != 0) {
678 if (strncmp(pattern
, "[attr]", 6) == 0) {
679 spec
->flags
= spec
->flags
| GIT_ATTR_FNMATCH_MACRO
;
682 /* else a character range like [a-e]* which is accepted */
685 if (*pattern
== '!' && (spec
->flags
& GIT_ATTR_FNMATCH_ALLOWNEG
) != 0) {
686 spec
->flags
= spec
->flags
| GIT_ATTR_FNMATCH_NEGATIVE
;
692 /* Scan until a non-escaped whitespace. */
693 for (scan
= pattern
; *scan
!= '\0'; ++scan
) {
696 if (c
== '\\' && !escaped
) {
699 } else if (git__isspace(c
) && !escaped
) {
700 if (!allow_space
|| (c
!= ' ' && c
!= '\t' && c
!= '\r'))
702 } else if (c
== '/') {
703 spec
->flags
= spec
->flags
| GIT_ATTR_FNMATCH_FULLPATH
;
706 if (slash_count
== 1 && pattern
== scan
)
708 } else if (git__iswildcard(c
) && !escaped
) {
709 /* remember if we see an unescaped wildcard in pattern */
710 spec
->flags
= spec
->flags
| GIT_ATTR_FNMATCH_HASWILD
;
718 if ((spec
->length
= scan
- pattern
) == 0)
719 return GIT_ENOTFOUND
;
722 * Remove one trailing \r in case this is a CRLF delimited
723 * file, in the case of Icon\r\r\n, we still leave the first
724 * \r there to match against.
726 if (pattern
[spec
->length
- 1] == '\r')
727 if (--spec
->length
== 0)
728 return GIT_ENOTFOUND
;
730 /* Remove trailing spaces. */
731 spec
->length
-= trailing_space_length(pattern
, spec
->length
);
733 if (spec
->length
== 0)
734 return GIT_ENOTFOUND
;
736 if (pattern
[spec
->length
- 1] == '/') {
738 spec
->flags
= spec
->flags
| GIT_ATTR_FNMATCH_DIRECTORY
;
739 if (--slash_count
<= 0)
740 spec
->flags
= spec
->flags
& ~GIT_ATTR_FNMATCH_FULLPATH
;
744 char *slash
= strrchr(context
, '/');
747 /* include the slash for easier matching */
748 len
= slash
- context
+ 1;
749 spec
->containing_dir
= git_pool_strndup(pool
, context
, len
);
750 spec
->containing_dir_length
= len
;
754 spec
->pattern
= git_pool_strndup(pool
, pattern
, spec
->length
);
756 if (!spec
->pattern
) {
757 *base
= git__next_line(pattern
);
760 /* strip '\' that might have been used for internal whitespace */
761 spec
->length
= unescape_spaces(spec
->pattern
);
767 static bool parse_optimized_patterns(
768 git_attr_fnmatch
*spec
,
772 if (!pattern
[1] && (pattern
[0] == '*' || pattern
[0] == '.')) {
773 spec
->flags
= GIT_ATTR_FNMATCH_MATCH_ALL
;
774 spec
->pattern
= git_pool_strndup(pool
, pattern
, 1);
783 static int sort_by_hash_and_name(const void *a_raw
, const void *b_raw
)
785 const git_attr_name
*a
= a_raw
;
786 const git_attr_name
*b
= b_raw
;
788 if (b
->name_hash
< a
->name_hash
)
790 else if (b
->name_hash
> a
->name_hash
)
793 return strcmp(b
->name
, a
->name
);
796 static void git_attr_assignment__free(git_attr_assignment
*assign
)
798 /* name and value are stored in a git_pool associated with the
799 * git_attr_file, so they do not need to be freed here
802 assign
->value
= NULL
;
806 static int merge_assignments(void **old_raw
, void *new_raw
)
808 git_attr_assignment
**old
= (git_attr_assignment
**)old_raw
;
809 git_attr_assignment
*new = (git_attr_assignment
*)new_raw
;
811 GIT_REFCOUNT_DEC(*old
, git_attr_assignment__free
);
816 int git_attr_assignment__parse(
817 git_repository
*repo
,
823 const char *scan
= *base
;
824 git_attr_assignment
*assign
= NULL
;
826 assert(assigns
&& !assigns
->length
);
828 git_vector_set_cmp(assigns
, sort_by_hash_and_name
);
830 while (*scan
&& *scan
!= '\n') {
831 const char *name_start
, *value_start
;
833 /* skip leading blanks */
834 while (git__isspace(*scan
) && *scan
!= '\n') scan
++;
836 /* allocate assign if needed */
838 assign
= git__calloc(1, sizeof(git_attr_assignment
));
839 GIT_ERROR_CHECK_ALLOC(assign
);
840 GIT_REFCOUNT_INC(assign
);
843 assign
->name_hash
= 5381;
844 assign
->value
= git_attr__true
;
846 /* look for magic name prefixes */
848 assign
->value
= git_attr__false
;
850 } else if (*scan
== '!') {
851 assign
->value
= git_attr__unset
; /* explicit unspecified state */
853 } else if (*scan
== '#') /* comment rest of line */
858 while (*scan
&& !git__isspace(*scan
) && *scan
!= '=') {
860 ((assign
->name_hash
<< 5) + assign
->name_hash
) + *scan
;
863 if (scan
== name_start
) {
864 /* must have found lone prefix (" - ") or leading = ("=foo")
865 * or end of buffer -- advance until whitespace and continue
867 while (*scan
&& !git__isspace(*scan
)) scan
++;
871 /* allocate permanent storage for name */
872 assign
->name
= git_pool_strndup(pool
, name_start
, scan
- name_start
);
873 GIT_ERROR_CHECK_ALLOC(assign
->name
);
875 /* if there is an equals sign, find the value */
877 for (value_start
= ++scan
; *scan
&& !git__isspace(*scan
); ++scan
);
879 /* if we found a value, allocate permanent storage for it */
880 if (scan
> value_start
) {
881 assign
->value
= git_pool_strndup(pool
, value_start
, scan
- value_start
);
882 GIT_ERROR_CHECK_ALLOC(assign
->value
);
886 /* expand macros (if given a repo with a macro cache) */
887 if (repo
!= NULL
&& assign
->value
== git_attr__true
) {
888 git_attr_rule
*macro
=
889 git_attr_cache__lookup_macro(repo
, assign
->name
);
893 git_attr_assignment
*massign
;
895 git_vector_foreach(¯o
->assigns
, i
, massign
) {
896 GIT_REFCOUNT_INC(massign
);
898 error
= git_vector_insert_sorted(
899 assigns
, massign
, &merge_assignments
);
900 if (error
< 0 && error
!= GIT_EEXISTS
) {
901 git_attr_assignment__free(assign
);
908 /* insert allocated assign into vector */
909 error
= git_vector_insert_sorted(assigns
, assign
, &merge_assignments
);
910 if (error
< 0 && error
!= GIT_EEXISTS
)
913 /* clear assign since it is now "owned" by the vector */
918 git_attr_assignment__free(assign
);
920 *base
= git__next_line(scan
);
922 return (assigns
->length
== 0) ? GIT_ENOTFOUND
: 0;
925 static void git_attr_rule__clear(git_attr_rule
*rule
)
928 git_attr_assignment
*assign
;
933 if (!(rule
->match
.flags
& GIT_ATTR_FNMATCH_IGNORE
)) {
934 git_vector_foreach(&rule
->assigns
, i
, assign
)
935 GIT_REFCOUNT_DEC(assign
, git_attr_assignment__free
);
936 git_vector_free(&rule
->assigns
);
939 /* match.pattern is stored in a git_pool, so no need to free */
940 rule
->match
.pattern
= NULL
;
941 rule
->match
.length
= 0;
944 void git_attr_rule__free(git_attr_rule
*rule
)
946 git_attr_rule__clear(rule
);
950 int git_attr_session__init(git_attr_session
*session
, git_repository
*repo
)
954 memset(session
, 0, sizeof(*session
));
955 session
->key
= git_atomic_inc(&repo
->attr_session_key
);
960 void git_attr_session__free(git_attr_session
*session
)
965 git_buf_dispose(&session
->sysdir
);
966 git_buf_dispose(&session
->tmp
);
968 memset(session
, 0, sizeof(git_attr_session
));