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>
2007-04-12 10:07:32 +02:00
|
|
|
#include "builtin.h"
|
2007-08-14 15:18:38 +02:00
|
|
|
#include "cache.h"
|
2017-06-14 20:07:36 +02:00
|
|
|
#include "config.h"
|
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>
2007-04-12 10:07:32 +02:00
|
|
|
#include "attr.h"
|
|
|
|
#include "quote.h"
|
2008-10-07 02:16:52 +02:00
|
|
|
#include "parse-options.h"
|
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>
2007-04-12 10:07:32 +02:00
|
|
|
|
2011-08-04 06:36:30 +02:00
|
|
|
static int all_attrs;
|
2011-09-22 23:44:20 +02:00
|
|
|
static int cached_attrs;
|
2008-10-07 02:16:52 +02:00
|
|
|
static int stdin_paths;
|
|
|
|
static const char * const check_attr_usage[] = {
|
2015-01-13 08:44:47 +01:00
|
|
|
N_("git check-attr [-a | --all | <attr>...] [--] <pathname>..."),
|
usage: do not insist that standard input must come from a file
The synopsys text and the usage string of subcommands that read list
of things from the standard input are often shown like this:
git gostak [--distim] < <list-of-doshes>
This is problematic in a number of ways:
* The way to use these commands is more often to feed them the
output from another command, not feed them from a file.
* Manual pages outside Git, commands that operate on the data read
from the standard input, e.g "sort", "grep", "sed", etc., are not
described with such a "< redirection-from-file" in their synopsys
text. Our doing so introduces inconsistency.
* We do not insist on where the output should go, by saying
git gostak [--distim] < <list-of-doshes> > <output>
* As it is our convention to enclose placeholders inside <braket>,
the redirection operator followed by a placeholder filename
becomes very hard to read, both in the documentation and in the
help text.
Let's clean them all up, after making sure that the documentation
clearly describes the modes that take information from the standard
input and what kind of things are expected on the input.
[jc: stole example for fmt-merge-msg from Jonathan]
Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-10-16 20:27:42 +02:00
|
|
|
N_("git check-attr --stdin [-z] [-a | --all | <attr>...]"),
|
2008-10-07 02:16:52 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-07-12 07:56:24 +02:00
|
|
|
static int nul_term_line;
|
2008-10-07 02:16:52 +02:00
|
|
|
|
|
|
|
static const struct option check_attr_options[] = {
|
2013-08-03 13:51:19 +02:00
|
|
|
OPT_BOOL('a', "all", &all_attrs, N_("report all attributes set on file")),
|
|
|
|
OPT_BOOL(0, "cached", &cached_attrs, N_("use .gitattributes only from the index")),
|
|
|
|
OPT_BOOL(0 , "stdin", &stdin_paths, N_("read file names from stdin")),
|
2013-09-04 21:39:02 +02:00
|
|
|
OPT_BOOL('z', NULL, &nul_term_line,
|
|
|
|
N_("terminate input and output records by a NUL character")),
|
2008-10-07 02:16:52 +02:00
|
|
|
OPT_END()
|
|
|
|
};
|
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>
2007-04-12 10:07:32 +02:00
|
|
|
|
2017-01-30 19:06:08 +01:00
|
|
|
static void output_attr(struct attr_check *check, const char *file)
|
2008-10-07 02:14:18 +02:00
|
|
|
{
|
|
|
|
int j;
|
2017-01-30 19:06:08 +01:00
|
|
|
int cnt = check->nr;
|
|
|
|
|
2008-10-07 02:14:18 +02:00
|
|
|
for (j = 0; j < cnt; j++) {
|
2017-01-30 19:06:08 +01:00
|
|
|
const char *value = check->items[j].value;
|
2008-10-07 02:14:18 +02:00
|
|
|
|
|
|
|
if (ATTR_TRUE(value))
|
|
|
|
value = "set";
|
|
|
|
else if (ATTR_FALSE(value))
|
|
|
|
value = "unset";
|
|
|
|
else if (ATTR_UNSET(value))
|
|
|
|
value = "unspecified";
|
|
|
|
|
2013-07-12 08:02:40 +02:00
|
|
|
if (nul_term_line) {
|
|
|
|
printf("%s%c" /* path */
|
|
|
|
"%s%c" /* attrname */
|
|
|
|
"%s%c" /* attrvalue */,
|
2017-01-30 19:06:08 +01:00
|
|
|
file, 0,
|
|
|
|
git_attr_name(check->items[j].attr), 0, value, 0);
|
2013-07-12 08:02:40 +02:00
|
|
|
} else {
|
|
|
|
quote_c_style(file, NULL, stdout, 0);
|
2017-01-30 19:06:08 +01:00
|
|
|
printf(": %s: %s\n",
|
|
|
|
git_attr_name(check->items[j].attr), value);
|
2013-07-12 08:02:40 +02:00
|
|
|
}
|
2008-10-07 02:14:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-28 03:01:54 +01:00
|
|
|
static void check_attr(const char *prefix,
|
2017-01-30 19:06:08 +01:00
|
|
|
struct attr_check *check,
|
|
|
|
int collect_all,
|
2017-01-28 03:01:54 +01:00
|
|
|
const char *file)
|
2011-08-04 06:36:24 +02:00
|
|
|
{
|
2011-08-04 06:47:46 +02:00
|
|
|
char *full_path =
|
|
|
|
prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
|
2017-01-30 19:06:08 +01:00
|
|
|
|
|
|
|
if (collect_all) {
|
2018-08-13 18:14:20 +02:00
|
|
|
git_all_attrs(&the_index, full_path, check);
|
2011-08-04 06:36:30 +02:00
|
|
|
} else {
|
2018-08-13 18:14:20 +02:00
|
|
|
if (git_check_attr(&the_index, full_path, check))
|
2017-01-30 19:06:08 +01:00
|
|
|
die("git_check_attr died");
|
2011-08-04 06:36:30 +02:00
|
|
|
}
|
2017-01-30 19:06:08 +01:00
|
|
|
output_attr(check, file);
|
|
|
|
|
2011-08-04 06:47:46 +02:00
|
|
|
free(full_path);
|
2011-08-04 06:36:24 +02:00
|
|
|
}
|
|
|
|
|
2017-01-28 03:01:54 +01:00
|
|
|
static void check_attr_stdin_paths(const char *prefix,
|
2017-01-30 19:06:08 +01:00
|
|
|
struct attr_check *check,
|
|
|
|
int collect_all)
|
2008-10-07 02:16:52 +02:00
|
|
|
{
|
2016-01-31 12:25:26 +01:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
struct strbuf unquoted = STRBUF_INIT;
|
2016-01-14 22:26:20 +01:00
|
|
|
strbuf_getline_fn getline_fn;
|
2008-10-07 02:16:52 +02:00
|
|
|
|
2016-01-14 22:26:20 +01:00
|
|
|
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
|
|
|
|
while (getline_fn(&buf, stdin) != EOF) {
|
|
|
|
if (!nul_term_line && buf.buf[0] == '"') {
|
2016-01-31 12:25:26 +01:00
|
|
|
strbuf_reset(&unquoted);
|
|
|
|
if (unquote_c_style(&unquoted, buf.buf, NULL))
|
2008-10-07 02:16:52 +02:00
|
|
|
die("line is badly quoted");
|
2016-01-31 12:25:26 +01:00
|
|
|
strbuf_swap(&buf, &unquoted);
|
2008-10-07 02:16:52 +02:00
|
|
|
}
|
2017-01-30 19:06:08 +01:00
|
|
|
check_attr(prefix, check, collect_all, buf.buf);
|
2008-10-07 02:16:52 +02:00
|
|
|
maybe_flush_or_die(stdout, "attribute to stdout");
|
|
|
|
}
|
|
|
|
strbuf_release(&buf);
|
2016-01-31 12:25:26 +01:00
|
|
|
strbuf_release(&unquoted);
|
2008-10-07 02:16:52 +02:00
|
|
|
}
|
|
|
|
|
2011-08-04 06:36:26 +02:00
|
|
|
static NORETURN void error_with_usage(const char *msg)
|
|
|
|
{
|
|
|
|
error("%s", msg);
|
|
|
|
usage_with_options(check_attr_usage, check_attr_options);
|
|
|
|
}
|
|
|
|
|
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>
2007-04-12 10:07:32 +02:00
|
|
|
int cmd_check_attr(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2017-01-30 19:06:08 +01:00
|
|
|
struct attr_check *check;
|
2011-08-04 06:36:25 +02:00
|
|
|
int cnt, i, doubledash, filei;
|
2008-10-07 02:16:52 +02:00
|
|
|
|
2014-02-06 19:19:33 +01:00
|
|
|
if (!is_bare_repository())
|
|
|
|
setup_work_tree();
|
|
|
|
|
2011-10-06 20:22:24 +02:00
|
|
|
git_config(git_default_config, NULL);
|
|
|
|
|
2009-05-23 20:53:12 +02:00
|
|
|
argc = parse_options(argc, argv, prefix, check_attr_options,
|
|
|
|
check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
|
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>
2007-04-12 10:07:32 +02:00
|
|
|
|
2007-08-14 15:18:38 +02:00
|
|
|
if (read_cache() < 0) {
|
|
|
|
die("invalid cache");
|
|
|
|
}
|
|
|
|
|
2011-09-22 23:44:20 +02:00
|
|
|
if (cached_attrs)
|
2018-08-13 18:14:33 +02:00
|
|
|
git_attr_set_direction(GIT_ATTR_INDEX);
|
2011-09-22 23:44:20 +02:00
|
|
|
|
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>
2007-04-12 10:07:32 +02:00
|
|
|
doubledash = -1;
|
2008-10-07 02:16:52 +02:00
|
|
|
for (i = 0; doubledash < 0 && i < argc; i++) {
|
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>
2007-04-12 10:07:32 +02:00
|
|
|
if (!strcmp(argv[i], "--"))
|
|
|
|
doubledash = i;
|
|
|
|
}
|
|
|
|
|
2011-08-04 06:36:30 +02:00
|
|
|
/* Process --all and/or attribute arguments: */
|
|
|
|
if (all_attrs) {
|
|
|
|
if (doubledash >= 1)
|
|
|
|
error_with_usage("Attributes and --all both specified");
|
|
|
|
|
|
|
|
cnt = 0;
|
|
|
|
filei = doubledash + 1;
|
|
|
|
} else if (doubledash == 0) {
|
2011-08-04 06:36:28 +02:00
|
|
|
error_with_usage("No attribute specified");
|
|
|
|
} else if (doubledash < 0) {
|
|
|
|
if (!argc)
|
|
|
|
error_with_usage("No attribute specified");
|
|
|
|
|
2011-08-04 06:36:32 +02:00
|
|
|
if (stdin_paths) {
|
|
|
|
/* Treat all arguments as attribute names. */
|
|
|
|
cnt = argc;
|
|
|
|
filei = argc;
|
|
|
|
} else {
|
|
|
|
/* Treat exactly one argument as an attribute name. */
|
|
|
|
cnt = 1;
|
|
|
|
filei = 1;
|
|
|
|
}
|
2011-08-04 06:36:25 +02:00
|
|
|
} else {
|
2008-10-07 02:16:52 +02:00
|
|
|
cnt = doubledash;
|
2011-08-04 06:36:25 +02:00
|
|
|
filei = doubledash + 1;
|
|
|
|
}
|
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>
2007-04-12 10:07:32 +02:00
|
|
|
|
2011-08-04 06:36:28 +02:00
|
|
|
/* Check file argument(s): */
|
2011-08-04 06:36:29 +02:00
|
|
|
if (stdin_paths) {
|
|
|
|
if (filei < argc)
|
|
|
|
error_with_usage("Can't specify files with --stdin");
|
|
|
|
} else {
|
|
|
|
if (filei >= argc)
|
|
|
|
error_with_usage("No file specified");
|
|
|
|
}
|
2008-10-07 02:16:52 +02:00
|
|
|
|
2017-01-30 19:06:08 +01:00
|
|
|
check = attr_check_alloc();
|
|
|
|
if (!all_attrs) {
|
2011-08-04 06:36:30 +02:00
|
|
|
for (i = 0; i < cnt; i++) {
|
2017-01-28 03:02:04 +01:00
|
|
|
const struct git_attr *a = git_attr(argv[i]);
|
|
|
|
|
2011-08-04 06:36:30 +02:00
|
|
|
if (!a)
|
|
|
|
return error("%s: not a valid attribute name",
|
2017-01-30 19:06:08 +01:00
|
|
|
argv[i]);
|
|
|
|
attr_check_append(check, a);
|
2011-08-04 06:36:30 +02:00
|
|
|
}
|
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>
2007-04-12 10:07:32 +02:00
|
|
|
}
|
|
|
|
|
2008-10-07 02:16:52 +02:00
|
|
|
if (stdin_paths)
|
2017-01-30 19:06:08 +01:00
|
|
|
check_attr_stdin_paths(prefix, check, all_attrs);
|
2008-10-07 02:16:52 +02:00
|
|
|
else {
|
2011-08-04 06:36:25 +02:00
|
|
|
for (i = filei; i < argc; i++)
|
2017-01-30 19:06:08 +01:00
|
|
|
check_attr(prefix, check, all_attrs, argv[i]);
|
2008-10-07 02:16:52 +02:00
|
|
|
maybe_flush_or_die(stdout, "attribute to stdout");
|
|
|
|
}
|
2017-01-30 19:06:08 +01:00
|
|
|
|
|
|
|
attr_check_free(check);
|
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>
2007-04-12 10:07:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|