Allow more than true/false to attributes.

This allows you to define three values (and possibly more) to
each attribute: true, false, and unset.

Typically the handlers that notice and act on attribute values
treat "unset" attribute to mean "do your default thing"
(e.g. crlf that is unset would trigger "guess from contents"),
so being able to override a setting to an unset state is
actually useful.

 - If you want to set the attribute value to true, have an entry
   in .gitattributes file that mentions the attribute name; e.g.

	*.o	binary

 - If you want to set the attribute value explicitly to false,
   use '-'; e.g.

	*.a	-diff

 - If you want to make the attribute value _unset_, perhaps to
   override an earlier entry, use '!'; e.g.

	*.a	-diff
	c.i.a	!diff

This also allows string values to attributes, with the natural
syntax:

	attrname=attrvalue

but you cannot use it, as nobody takes notice and acts on
it yet.

Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Junio C Hamano
2007-04-16 21:33:31 -07:00
parent b568a503de
commit 515106fa13
5 changed files with 169 additions and 82 deletions

15
diff.c
View File

@ -1068,9 +1068,18 @@ static int file_is_binary(struct diff_filespec *one)
struct git_attr_check attr_diff_check;
setup_diff_attr_check(&attr_diff_check);
if (!git_checkattr(one->path, 1, &attr_diff_check) &&
(0 <= attr_diff_check.isset))
return !attr_diff_check.isset;
if (!git_checkattr(one->path, 1, &attr_diff_check)) {
void *value = attr_diff_check.value;
if (ATTR_TRUE(value))
return 0;
else if (ATTR_FALSE(value))
return 1;
else if (ATTR_UNSET(value))
;
else
die("unknown value %s given to 'diff' attribute",
(char *)value);
}
if (!one->data) {
if (!DIFF_FILE_VALID(one))