Skip to content

Commit 489810f

Browse files
Eric Wonggitster
authored andcommitted
cat-file: batch-command uses content_limit
As with the normal `--batch' mode, we can use the content_limit round trip optimization to avoid a redundant lookup. The only tricky thing here is we need to enable/disable setting the object_info.contentp field depending on whether we hit an `info' or `contents' command. t1006 is updated to ensure we can switch back and forth between `info' and `contents' commands without problems. Signed-off-by: Eric Wong <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d4e4d5 commit 489810f

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

builtin/cat-file.c

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
417417
case OI_DBCACHED:
418418
unlock_delta_base_cache();
419419
}
420-
} else if (data->type == OBJ_BLOB) {
420+
} else {
421+
assert(data->type == OBJ_BLOB);
421422
if (opt->buffer_output)
422423
fflush(stdout);
423424
if (opt->transform_mode) {
@@ -452,30 +453,6 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
452453
stream_blob(oid);
453454
}
454455
}
455-
else {
456-
enum object_type type;
457-
unsigned long size;
458-
void *contents;
459-
460-
contents = repo_read_object_file(the_repository, oid, &type,
461-
&size);
462-
if (!contents)
463-
die("object %s disappeared", oid_to_hex(oid));
464-
465-
if (use_mailmap) {
466-
size_t s = size;
467-
contents = replace_idents_using_mailmap(contents, &s);
468-
size = cast_size_t_to_ulong(s);
469-
}
470-
471-
if (type != data->type)
472-
die("object %s changed type!?", oid_to_hex(oid));
473-
if (data->info.sizep && size != data->size && !use_mailmap)
474-
die("object %s changed size!?", oid_to_hex(oid));
475-
476-
batch_write(opt, contents, size);
477-
free(contents);
478-
}
479456
}
480457

481458
static void print_default_format(struct strbuf *scratch, struct expand_data *data,
@@ -689,6 +666,7 @@ static void parse_cmd_contents(struct batch_options *opt,
689666
struct expand_data *data)
690667
{
691668
opt->batch_mode = BATCH_MODE_CONTENTS;
669+
data->info.contentp = &data->content;
692670
batch_one_object(line, output, opt, data);
693671
}
694672

@@ -698,6 +676,7 @@ static void parse_cmd_info(struct batch_options *opt,
698676
struct expand_data *data)
699677
{
700678
opt->batch_mode = BATCH_MODE_INFO;
679+
data->info.contentp = NULL;
701680
batch_one_object(line, output, opt, data);
702681
}
703682

@@ -839,7 +818,8 @@ static int batch_objects(struct batch_options *opt)
839818
* Likewise, grab the content in the initial request if it's small
840819
* and we're not planning to filter it.
841820
*/
842-
if (opt->batch_mode == BATCH_MODE_CONTENTS) {
821+
if ((opt->batch_mode == BATCH_MODE_CONTENTS) ||
822+
(opt->batch_mode == BATCH_MODE_QUEUE_AND_DISPATCH)) {
843823
data.info.typep = &data.type;
844824
if (!opt->transform_mode) {
845825
data.info.sizep = &data.size;

0 commit comments

Comments
 (0)