42
int all_objects;
43
int unordered;
44
int transform_mode; /* may be 'w' or 'c' for --filters or --textconv */
45
- int nul_terminated;
45
+ char input_delim;
46
const char *format;
47
};
48
694
struct queued_cmd *queued_cmd = NULL;
695
size_t alloc = 0, nr = 0;
696
697
- while (1) {
698
- int i, ret;
697
+ while (strbuf_getdelim_strip_crlf(&input, stdin, opt->input_delim) != EOF) {
698
+ int i;
699
const struct parse_cmd *cmd = NULL;
700
const char *p = NULL, *cmd_end;
701
struct queued_cmd call = {0};
702
703
- if (opt->nul_terminated)
704
- ret = strbuf_getline_nul(&input, stdin);
705
- else
706
- ret = strbuf_getline(&input, stdin);
707
-
708
- if (ret)
709
- break;
710
-
703
if (!input.len)
704
die(_("empty command in input"));
705
if (isspace(*input.buf))
843
goto cleanup;
844
}
845
854
- while (1) {
855
- int ret;
856
- if (opt->nul_terminated)
857
- ret = strbuf_getline_nul(&input, stdin);
858
- else
859
- ret = strbuf_getline(&input, stdin);
860
-
861
- if (ret == EOF)
862
- break;
863
-
846
+ while (strbuf_getdelim_strip_crlf(&input, stdin, opt->input_delim) != EOF) {
847
if (data.split_on_whitespace) {
848
/*
849
* Split at first whitespace, tying off the beginning
912
const char *exp_type = NULL, *obj_name = NULL;
913
struct batch_options batch = {0};
914
int unknown_type = 0;
915
+ int input_nul_terminated = 0;
916
917
const char * const usage[] = {
918
N_("git cat-file <type> <object>"),
949
N_("like --batch, but don't emit <contents>"),
950
PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
951
batch_option_callback),
968
- OPT_BOOL('z', NULL, &batch.nul_terminated, N_("stdin is NUL-terminated")),
952
+ OPT_BOOL('z', NULL, &input_nul_terminated, N_("stdin is NUL-terminated")),
953
OPT_CALLBACK_F(0, "batch-command", &batch, N_("format"),
954
N_("read commands from stdin"),
955
PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
1008
else if (batch.all_objects)
1009
usage_msg_optf(_("'%s' requires a batch mode"), usage, options,
1010
"--batch-all-objects");
1027
- else if (batch.nul_terminated)
1011
+ else if (input_nul_terminated)
1012
usage_msg_optf(_("'%s' requires a batch mode"), usage, options,
1013
"-z");
1014
1015
+ batch.input_delim = input_nul_terminated ? '\0' : '\n';
1016
+
1017
/* Batch defaults */
1018
if (batch.buffer_output < 0)
1019
batch.buffer_output = batch.all_objects;