4
4
#include "quote.h"
5
5
#include "parse-options.h"
6
6
7
+ static int all_attrs ;
7
8
static int stdin_paths ;
8
9
static const char * const check_attr_usage [] = {
9
- "git check-attr attr... [--] pathname..." ,
10
- "git check-attr --stdin attr... < <list-of-paths>" ,
10
+ "git check-attr [-a | --all | attr...] [--] pathname..." ,
11
+ "git check-attr --stdin [-a | --all | attr...] < <list-of-paths>" ,
11
12
NULL
12
13
};
13
14
14
15
static int null_term_line ;
15
16
16
17
static const struct option check_attr_options [] = {
18
+ OPT_BOOLEAN ('a' , "all" , & all_attrs , "report all attributes set on file" ),
17
19
OPT_BOOLEAN (0 , "stdin" , & stdin_paths , "read file names from stdin" ),
18
20
OPT_BOOLEAN ('z' , NULL , & null_term_line ,
19
21
"input paths are terminated by a null character" ),
@@ -42,9 +44,16 @@ static void output_attr(int cnt, struct git_attr_check *check,
42
44
static void check_attr (int cnt , struct git_attr_check * check ,
43
45
const char * file )
44
46
{
45
- if (git_checkattr (file , cnt , check ))
46
- die ("git_checkattr died" );
47
- output_attr (cnt , check , file );
47
+ if (check != NULL ) {
48
+ if (git_checkattr (file , cnt , check ))
49
+ die ("git_checkattr died" );
50
+ output_attr (cnt , check , file );
51
+ } else {
52
+ if (git_all_attrs (file , & cnt , & check ))
53
+ die ("git_all_attrs died" );
54
+ output_attr (cnt , check , file );
55
+ free (check );
56
+ }
48
57
}
49
58
50
59
static void check_attr_stdin_paths (int cnt , struct git_attr_check * check )
@@ -92,8 +101,14 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
92
101
doubledash = i ;
93
102
}
94
103
95
- /* Check attribute argument(s): */
96
- if (doubledash == 0 ) {
104
+ /* Process --all and/or attribute arguments: */
105
+ if (all_attrs ) {
106
+ if (doubledash >= 1 )
107
+ error_with_usage ("Attributes and --all both specified" );
108
+
109
+ cnt = 0 ;
110
+ filei = doubledash + 1 ;
111
+ } else if (doubledash == 0 ) {
97
112
error_with_usage ("No attribute specified" );
98
113
} else if (doubledash < 0 ) {
99
114
/*
@@ -119,15 +134,20 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
119
134
error_with_usage ("No file specified" );
120
135
}
121
136
122
- check = xcalloc (cnt , sizeof (* check ));
123
- for (i = 0 ; i < cnt ; i ++ ) {
124
- const char * name ;
125
- struct git_attr * a ;
126
- name = argv [i ];
127
- a = git_attr (name );
128
- if (!a )
129
- return error ("%s: not a valid attribute name" , name );
130
- check [i ].attr = a ;
137
+ if (all_attrs ) {
138
+ check = NULL ;
139
+ } else {
140
+ check = xcalloc (cnt , sizeof (* check ));
141
+ for (i = 0 ; i < cnt ; i ++ ) {
142
+ const char * name ;
143
+ struct git_attr * a ;
144
+ name = argv [i ];
145
+ a = git_attr (name );
146
+ if (!a )
147
+ return error ("%s: not a valid attribute name" ,
148
+ name );
149
+ check [i ].attr = a ;
150
+ }
131
151
}
132
152
133
153
if (stdin_paths )
0 commit comments