Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2011-12-16 22:56:43 +0400
committerRussell Belfer <arrbee@arrbee.com>2011-12-21 04:32:58 +0400
commitee1f0b1aed7798908d9e038b006b66f868613fc3 (patch)
treec60350029b9e4bb14811ac13caf59ad86424f33e /src/attr_file.h
parentbe00b00dd1468f1c625ca3fadc61f2a16edfb8d5 (diff)
Add APIs for git attributes
This adds APIs for querying git attributes. In addition to the new API in include/git2/attr.h, most of the action is in src/attr_file.[hc] which contains utilities for dealing with a single attributes file, and src/attr.[hc] which contains the implementation of the APIs that merge all applicable attributes files.
Diffstat (limited to 'src/attr_file.h')
-rw-r--r--src/attr_file.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/attr_file.h b/src/attr_file.h
new file mode 100644
index 000000000..4774f148c
--- /dev/null
+++ b/src/attr_file.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_attr_file_h__
+#define INCLUDE_attr_file_h__
+
+#include "git2/attr.h"
+#include "vector.h"
+
+typedef struct {
+ char *pattern;
+ size_t length;
+ int negative;
+ int directory;
+ int fullpath;
+} git_attr_fnmatch;
+
+typedef struct {
+ const char *name;
+ unsigned long name_hash;
+} git_attr_name;
+
+typedef struct {
+ 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_attr_rule;
+
+typedef struct {
+ char *path;
+ git_vector rules; /* <git_attr_rule*> */
+} git_attr_file;
+
+typedef struct {
+ const char *path;
+ const char *basename;
+ int is_dir;
+} git_attr_path;
+
+/*
+ * 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 void git_attr_file__free(git_attr_file *file);
+
+extern int git_attr_file__lookup_one(
+ git_attr_file *file,
+ const git_attr_path *path,
+ const char *attr,
+ const char **value);
+
+/* loop over rules in file from bottom to top */
+#define git_attr_file__foreach_matching_rule(file, path, iter, rule) \
+ git_vector_rforeach(&(file)->rules, (iter), (rule)) \
+ if (git_attr_rule__match_path((rule), (path)) == GIT_SUCCESS)
+
+extern unsigned long git_attr_file__name_hash(const char *name);
+
+
+/*
+ * other utilities
+ */
+
+extern int git_attr_rule__match_path(
+ git_attr_rule *rule,
+ const git_attr_path *path);
+
+extern git_attr_assignment *git_attr_rule__lookup_assignment(
+ git_attr_rule *rule, const char *name);
+
+extern int git_attr_path__init(
+ git_attr_path *info, const char *path);
+
+#endif