summaryrefslogtreecommitdiff
path: root/builtin-check-attr.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-04-12 08:07:32 (GMT)
committerJunio C Hamano <junkio@cox.net>2007-04-14 15:57:06 (GMT)
commitd0bfd026a8241d544c339944976927b388d61a5e (patch)
tree391d50183538ddeb314ffc27c62a52527fe6182e /builtin-check-attr.c
parentedb4fd79ec34254fc4a1c35e8834df4c92cb3bfd (diff)
downloadgit-d0bfd026a8241d544c339944976927b388d61a5e.zip
git-d0bfd026a8241d544c339944976927b388d61a5e.tar.gz
git-d0bfd026a8241d544c339944976927b388d61a5e.tar.bz2
Add basic infrastructure to assign attributes to paths
This adds the basic infrastructure to assign attributes to paths, in a way similar to what the exclusion mechanism does based on $GIT_DIR/info/exclude and .gitignore files. An attribute is just a simple string that does not contain any whitespace. They can be specified in $GIT_DIR/info/attributes file, and .gitattributes file in each directory. Each line in these files defines a pattern matching rule. Similar to the exclusion mechanism, a later match overrides an earlier match in the same file, and entries from .gitattributes file in the same directory takes precedence over the ones from parent directories. Lines in $GIT_DIR/info/attributes file are used as the lowest precedence default rules. A line is either a comment (an empty line, or a line that begins with a '#'), or a rule, which is a whitespace separated list of tokens. The first token on the line is a shell glob pattern. The rest are names of attributes, each of which can optionally be prefixed with '!'. Such a line means "if a path matches this glob, this attribute is set (or unset -- if the attribute name is prefixed with '!'). For glob matching, the same "if the pattern does not have a slash in it, the basename of the path is matched with fnmatch(3) against the pattern, otherwise, the path is matched with the pattern with FNM_PATHNAME" rule as the exclusion mechanism is used. This does not define what an attribute means. Tying an attribute to various effects it has on git operation for paths that have it will be specified separately. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-check-attr.c')
-rw-r--r--builtin-check-attr.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/builtin-check-attr.c b/builtin-check-attr.c
new file mode 100644
index 0000000..47b0721
--- /dev/null
+++ b/builtin-check-attr.c
@@ -0,0 +1,49 @@
+#include "builtin.h"
+#include "attr.h"
+#include "quote.h"
+
+static const char check_attr_usage[] =
+"git-check-attr attr... [--] pathname...";
+
+int cmd_check_attr(int argc, const char **argv, const char *prefix)
+{
+ struct git_attr_check *check;
+ int cnt, i, doubledash;
+
+ doubledash = -1;
+ for (i = 1; doubledash < 0 && i < argc; i++) {
+ if (!strcmp(argv[i], "--"))
+ doubledash = i;
+ }
+
+ /* If there is no double dash, we handle only one attribute */
+ if (doubledash < 0) {
+ cnt = 1;
+ doubledash = 1;
+ } else
+ cnt = doubledash - 1;
+ doubledash++;
+
+ if (cnt <= 0 || argc < doubledash)
+ usage(check_attr_usage);
+ check = xcalloc(cnt, sizeof(*check));
+ for (i = 0; i < cnt; i++) {
+ const char *name;
+ name = argv[i + 1];
+ check[i].attr = git_attr(name, strlen(name));
+ }
+
+ for (i = doubledash; i < argc; i++) {
+ int j;
+ if (git_checkattr(argv[i], cnt, check))
+ die("git_checkattr died");
+ for (j = 0; j < cnt; j++) {
+ write_name_quoted("", 0, argv[i], 1, stdout);
+ printf(": %s: %s\n", argv[j+1],
+ (check[j].isset < 0) ? "unspecified" :
+ (check[j].isset == 0) ? "unset" :
+ "set");
+ }
+ }
+ return 0;
+}