Skip to content

Commit 6289913

Browse files
committed
Merge branch 'jk/cat-file-buffered-batch-all'
"git cat-file --batch-all" has been sped up, by taking advantage of the fact that it does not have to read a list of objects, in two ways. * jk/cat-file-buffered-batch-all: cat-file: default to --buffer when --batch-all-objects is used cat-file: avoid noop calls to sha1_object_info_extended
2 parents bc4b924 + 6a36e1e commit 6289913

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

builtin/cat-file.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ struct expand_data {
154154
* elements above, so you can retrieve the response from there.
155155
*/
156156
struct object_info info;
157+
158+
/*
159+
* This flag will be true if the requested batch format and options
160+
* don't require us to call sha1_object_info, which can then be
161+
* optimized out.
162+
*/
163+
unsigned skip_object_info : 1;
157164
};
158165

159166
static int is_atom(const char *atom, const char *s, int slen)
@@ -258,7 +265,8 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
258265
{
259266
struct strbuf buf = STRBUF_INIT;
260267

261-
if (sha1_object_info_extended(data->sha1, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {
268+
if (!data->skip_object_info &&
269+
sha1_object_info_extended(data->sha1, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {
262270
printf("%s missing\n", obj_name ? obj_name : sha1_to_hex(data->sha1));
263271
fflush(stdout);
264272
return;
@@ -369,6 +377,13 @@ static int batch_objects(struct batch_options *opt)
369377
strbuf_expand(&buf, opt->format, expand_format, &data);
370378
data.mark_query = 0;
371379

380+
if (opt->all_objects) {
381+
struct object_info empty;
382+
memset(&empty, 0, sizeof(empty));
383+
if (!memcmp(&data.info, &empty, sizeof(empty)))
384+
data.skip_object_info = 1;
385+
}
386+
372387
/*
373388
* If we are printing out the object, then always fill in the type,
374389
* since we will want to decide whether or not to stream.
@@ -489,6 +504,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
489504

490505
git_config(git_cat_file_config, NULL);
491506

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

494510
if (opt) {
@@ -512,6 +528,9 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
512528
usage_with_options(cat_file_usage, options);
513529
}
514530

531+
if (batch.buffer_output < 0)
532+
batch.buffer_output = batch.all_objects;
533+
515534
if (batch.enabled)
516535
return batch_objects(&batch);
517536

0 commit comments

Comments
 (0)