Skip to content

Commit 0db320d

Browse files
committed
Merge branch 'jc/check-x-z'
"git check-ignore -z" applied the NUL termination to both its input (with --stdin) and its output, but "git check-attr -z" ignored the option on the output side. This is potentially a backward incompatible fix. Let's see if anybody screams before deciding if we want to do anything to help existing users (there may be none). * jc/check-x-z: check-attr -z: a single -z should apply to both input and output check-ignore -z: a single -z should apply to both input and output check-attr: the name of the character is NUL, not NULL check-ignore: the name of the character is NUL, not NULL
2 parents 0a41de8 + f7cd8c5 commit 0db320d

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

Documentation/git-check-attr.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ OPTIONS
3131
Read file names from stdin instead of from the command-line.
3232

3333
-z::
34-
Only meaningful with `--stdin`; paths are separated with a
35-
NUL character instead of a linefeed character.
34+
The output format is modified to be machine-parseable.
35+
If `--stdin` is also given, input paths are separated
36+
with a NUL character instead of a linefeed character.
3637

3738
\--::
3839
Interpret all preceding arguments as attributes and all following
@@ -48,6 +49,10 @@ OUTPUT
4849
The output is of the form:
4950
<path> COLON SP <attribute> COLON SP <info> LF
5051

52+
unless `-z` is in effect, in which case NUL is used as delimiter:
53+
<path> NUL <attribute> NUL <info> NUL
54+
55+
5156
<path> is the path of a file being queried, <attribute> is an attribute
5257
being queried and <info> can be either:
5358

builtin/check-attr.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ N_("git check-attr --stdin [-z] [-a | --all | attr...] < <list-of-paths>"),
1313
NULL
1414
};
1515

16-
static int null_term_line;
16+
static int nul_term_line;
1717

1818
static const struct option check_attr_options[] = {
1919
OPT_BOOLEAN('a', "all", &all_attrs, N_("report all attributes set on file")),
2020
OPT_BOOLEAN(0, "cached", &cached_attrs, N_("use .gitattributes only from the index")),
2121
OPT_BOOLEAN(0 , "stdin", &stdin_paths, N_("read file names from stdin")),
22-
OPT_BOOLEAN('z', NULL, &null_term_line,
23-
N_("input paths are terminated by a null character")),
22+
OPT_BOOLEAN('z', NULL, &nul_term_line,
23+
N_("terminate input and output records by a NUL character")),
2424
OPT_END()
2525
};
2626

@@ -38,8 +38,16 @@ static void output_attr(int cnt, struct git_attr_check *check,
3838
else if (ATTR_UNSET(value))
3939
value = "unspecified";
4040

41-
quote_c_style(file, NULL, stdout, 0);
42-
printf(": %s: %s\n", git_attr_name(check[j].attr), value);
41+
if (nul_term_line) {
42+
printf("%s%c" /* path */
43+
"%s%c" /* attrname */
44+
"%s%c" /* attrvalue */,
45+
file, 0, git_attr_name(check[j].attr), 0, value, 0);
46+
} else {
47+
quote_c_style(file, NULL, stdout, 0);
48+
printf(": %s: %s\n", git_attr_name(check[j].attr), value);
49+
}
50+
4351
}
4452
}
4553

@@ -65,7 +73,7 @@ static void check_attr_stdin_paths(const char *prefix, int cnt,
6573
struct git_attr_check *check)
6674
{
6775
struct strbuf buf, nbuf;
68-
int line_termination = null_term_line ? 0 : '\n';
76+
int line_termination = nul_term_line ? 0 : '\n';
6977

7078
strbuf_init(&buf, 0);
7179
strbuf_init(&nbuf, 0);

builtin/check-ignore.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ static const char * const check_ignore_usage[] = {
1212
NULL
1313
};
1414

15-
static int null_term_line;
15+
static int nul_term_line;
1616

1717
static const struct option check_ignore_options[] = {
1818
OPT__QUIET(&quiet, N_("suppress progress reporting")),
1919
OPT__VERBOSE(&verbose, N_("be verbose")),
2020
OPT_GROUP(""),
2121
OPT_BOOLEAN(0, "stdin", &stdin_paths,
2222
N_("read file names from stdin")),
23-
OPT_BOOLEAN('z', NULL, &null_term_line,
24-
N_("input paths are terminated by a null character")),
23+
OPT_BOOLEAN('z', NULL, &nul_term_line,
24+
N_("terminate input and output records by a NUL character")),
2525
OPT_BOOLEAN('n', "non-matching", &show_non_matching,
2626
N_("show non-matching input paths")),
2727
OPT_END()
@@ -31,7 +31,7 @@ static void output_exclude(const char *path, struct exclude *exclude)
3131
{
3232
char *bang = (exclude && exclude->flags & EXC_FLAG_NEGATIVE) ? "!" : "";
3333
char *slash = (exclude && exclude->flags & EXC_FLAG_MUSTBEDIR) ? "/" : "";
34-
if (!null_term_line) {
34+
if (!nul_term_line) {
3535
if (!verbose) {
3636
write_name_quoted(path, stdout, '\n');
3737
} else {
@@ -107,7 +107,7 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix)
107107
{
108108
struct strbuf buf, nbuf;
109109
char *pathspec[2] = { NULL, NULL };
110-
int line_termination = null_term_line ? 0 : '\n';
110+
int line_termination = nul_term_line ? 0 : '\n';
111111
int num_ignored = 0;
112112

113113
strbuf_init(&buf, 0);
@@ -142,7 +142,7 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)
142142
if (argc > 0)
143143
die(_("cannot specify pathnames with --stdin"));
144144
} else {
145-
if (null_term_line)
145+
if (nul_term_line)
146146
die(_("-z only makes sense with --stdin"));
147147
if (argc == 0)
148148
die(_("no path specified"));

0 commit comments

Comments
 (0)