| 754 | }; |
| 755 | |
| 756 | static void batch_objects_command(struct batch_options *opt, |
| 757 | struct strbuf *output, |
| 758 | struct expand_data *data) |
| 759 | { |
| 760 | struct strbuf input = STRBUF_INIT; |
| 761 | struct queued_cmd *queued_cmd = NULL; |
| 762 | size_t alloc = 0, nr = 0; |
| 763 | |
| 764 | while (strbuf_getdelim_strip_crlf(&input, stdin, opt->input_delim) != EOF) { |
| 765 | int i; |
| 766 | const struct parse_cmd *cmd = NULL; |
| 767 | const char *p = NULL, *cmd_end; |
| 768 | struct queued_cmd call = {0}; |
| 769 | |
| 770 | if (!input.len) |
| 771 | die(_("empty command in input")); |
| 772 | if (isspace(*input.buf)) |
| 773 | die(_("whitespace before command: '%s'"), input.buf); |
| 774 | |
| 775 | for (i = 0; i < ARRAY_SIZE(commands); i++) { |
| 776 | if (!skip_prefix(input.buf, commands[i].name, &cmd_end)) |
| 777 | continue; |
| 778 | |
| 779 | cmd = &commands[i]; |
| 780 | if (cmd->takes_args) { |
| 781 | if (*cmd_end != ' ') |
| 782 | die(_("%s requires arguments"), |
| 783 | commands[i].name); |
| 784 | |
| 785 | p = cmd_end + 1; |
| 786 | } else if (*cmd_end) { |
| 787 | die(_("%s takes no arguments"), |
| 788 | commands[i].name); |
| 789 | } |
| 790 | |
| 791 | break; |
| 792 | } |
| 793 | |
| 794 | if (!cmd) |
| 795 | die(_("unknown command: '%s'"), input.buf); |
| 796 | |
| 797 | if (!strcmp(cmd->name, "flush")) { |
| 798 | dispatch_calls(opt, output, data, queued_cmd, nr); |
| 799 | free_cmds(queued_cmd, &nr); |
| 800 | } else if (!opt->buffer_output) { |
| 801 | cmd->fn(opt, p, output, data); |
| 802 | } else { |
| 803 | ALLOC_GROW(queued_cmd, nr + 1, alloc); |
| 804 | call.fn = cmd->fn; |
| 805 | call.line = xstrdup_or_null(p); |
| 806 | queued_cmd[nr++] = call; |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | if (opt->buffer_output && |
| 811 | nr && |
| 812 | !git_env_bool("GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT", 0)) { |
| 813 | dispatch_calls(opt, output, data, queued_cmd, nr); |
no test coverage detected