Skip to content

Commit 6a36e1e

Browse files
peffgitster
authored andcommitted
cat-file: default to --buffer when --batch-all-objects is used
Traditionally cat-file's batch-mode does not do any output buffering. The reason is that a caller may have pipes connected to its input and output, and would want to use cat-file interactively, getting output immediately for each input it sends. This may involve a lot of small write() calls, which can be slow. So we introduced --buffer to improve this, but we can't turn it on by default, as it would break the interactive case above. However, when --batch-all-objects is used, we do not read stdin at all. We generate the output ourselves as quickly as possible, and then exit. In this case buffering is a strict win, and it is simply a hassle for the user to have to remember to specify --buffer. This patch makes --buffer the default when --batch-all-objects is used. Specifying "--buffer" manually is still OK, and you can even override it with "--no-buffer" if you're a masochist (or debugging). For some real numbers, running: git cat-file --batch-all-objects --batch-check='%(objectname)' on torvalds/linux goes from: real 0m1.464s user 0m1.208s sys 0m0.252s to: real 0m1.230s user 0m1.172s sys 0m0.056s for a 16% speedup. Suggested-by: Charles Bailey <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 845de33 commit 6a36e1e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

builtin/cat-file.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
504504

505505
git_config(git_cat_file_config, NULL);
506506

507+
batch.buffer_output = -1;
507508
argc = parse_options(argc, argv, prefix, options, cat_file_usage, 0);
508509

509510
if (opt) {
@@ -527,6 +528,9 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
527528
usage_with_options(cat_file_usage, options);
528529
}
529530

531+
if (batch.buffer_output < 0)
532+
batch.buffer_output = batch.all_objects;
533+
530534
if (batch.enabled)
531535
return batch_objects(&batch);
532536

0 commit comments

Comments
 (0)