summaryrefslogtreecommitdiff
path: root/src/attr_file.h
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2011-12-28 23:28:50 -0800
committerRussell Belfer <arrbee@arrbee.com>2011-12-29 00:01:10 -0800
commit73b51450a3194ddaa2ac180a1fea25fdf66971bb (patch)
tree4a6f4f0cfc90ded7f7734da2b6a9353d9bb0890b /src/attr_file.h
parentee1f0b1aed7798908d9e038b006b66f868613fc3 (diff)
downloadlibgit2-73b51450a3194ddaa2ac180a1fea25fdf66971bb.tar.gz
Add support for macros and cache flush API.
Add support for git attribute macro definitions. Also, add support for cache flush API to clear the attribute file content cache when needed. Additionally, improved the handling of global and system files, making common utility functions in fileops and converting config and attr to both use the common functions. Adds a bunch more tests and fixed some memory leaks. Note that adding macros required me to use refcounted attribute assignment definitions, which complicated, but probably improved memory usage.
Diffstat (limited to 'src/attr_file.h')
-rw-r--r--src/attr_file.h43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/attr_file.h b/src/attr_file.h
index 4774f148c..bed440d61 100644
--- a/src/attr_file.h
+++ b/src/attr_file.h
@@ -9,36 +9,41 @@
#include "git2/attr.h"
#include "vector.h"
+#include "hashtable.h"
+
+#define GIT_ATTR_FNMATCH_NEGATIVE (1U << 0)
+#define GIT_ATTR_FNMATCH_DIRECTORY (1U << 1)
+#define GIT_ATTR_FNMATCH_FULLPATH (1U << 2)
+#define GIT_ATTR_FNMATCH_MACRO (1U << 3)
typedef struct {
char *pattern;
size_t length;
- int negative;
- int directory;
- int fullpath;
+ unsigned int flags;
} git_attr_fnmatch;
typedef struct {
+ git_refcount unused;
const char *name;
- unsigned long name_hash;
+ unsigned long name_hash;
} git_attr_name;
typedef struct {
+ git_refcount rc; /* for macros */
char *name;
unsigned long name_hash;
- size_t name_len;
const char *value;
int is_allocated;
} git_attr_assignment;
typedef struct {
git_attr_fnmatch match;
- git_vector assigns; /* <git_attr_assignment*> */
+ git_vector assigns; /* vector of <git_attr_assignment*> */
} git_attr_rule;
typedef struct {
- char *path;
- git_vector rules; /* <git_attr_rule*> */
+ char *path; /* cache the path this was loaded from */
+ git_vector rules; /* vector of <git_attr_rule*> */
} git_attr_file;
typedef struct {
@@ -47,12 +52,20 @@ typedef struct {
int is_dir;
} git_attr_path;
+typedef struct {
+ int initialized;
+ git_hashtable *files; /* hash path to git_attr_file */
+ git_hashtable *macros; /* hash name to vector<git_attr_assignment> */
+} git_attr_cache;
+
/*
* git_attr_file API
*/
-extern int git_attr_file__from_buffer(git_attr_file **out, const char *buf);
-extern int git_attr_file__from_file(git_attr_file **out, const char *path);
+extern int git_attr_file__from_buffer(
+ git_repository *repo, const char *buf, git_attr_file **out);
+extern int git_attr_file__from_file(
+ git_repository *repo, const char *path, git_attr_file **out);
extern void git_attr_file__free(git_attr_file *file);
@@ -74,6 +87,8 @@ extern unsigned long git_attr_file__name_hash(const char *name);
* other utilities
*/
+extern void git_attr_rule__free(git_attr_rule *rule);
+
extern int git_attr_rule__match_path(
git_attr_rule *rule,
const git_attr_path *path);
@@ -84,4 +99,12 @@ extern git_attr_assignment *git_attr_rule__lookup_assignment(
extern int git_attr_path__init(
git_attr_path *info, const char *path);
+extern int git_attr_assignment__parse(
+ git_repository *repo, /* needed to expand macros */
+ git_vector *assigns,
+ const char **scan);
+
+extern int git_attr_cache__insert_macro(
+ git_repository *repo, git_attr_rule *macro);
+
#endif