Move printing function to ref-filter, it is logical because we move all formatting/printing logic to ref-filter. It could be much better if we embed this logic into current flows in ref-filter, but it looks like the task for another patch. Signed-off-by: Olga Telezhnaia <olyatelezhnaya@xxxxxxxxx> --- builtin/cat-file.c | 51 --------------------------------------------- ref-filter.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ ref-filter.h | 3 +++ 3 files changed, 55 insertions(+), 51 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 2066ff1e697e4..6c0cbf71f0f0c 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -226,57 +226,6 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *data) return end - start + 1; } -static void print_object_or_die(struct expand_data *data, int cmdmode, - int buffered, const char *rest) -{ - const struct object_id *oid = &data->oid; - unsigned long size; - char *contents; - - assert(data->info.typep); - - if (data->type != OBJ_BLOB) { - enum object_type type; - contents = read_object_file(oid, &type, &size); - if (!contents) - die("object %s disappeared", oid_to_hex(oid)); - if (type != data->type) - die("object %s changed type!?", oid_to_hex(oid)); - if (data->info.sizep && size != data->size) - die("object %s changed size!?", oid_to_hex(oid)); - - write_or_die(1, contents, size); - free(contents); - return; - } - - if (buffered) - fflush(stdout); - if (!cmdmode) { - if (stream_blob_to_fd(1, oid, NULL, 0)) - die("unable to stream %s to stdout", oid_to_hex(oid)); - return; - } - - if (!rest) - die("missing path for '%s'", oid_to_hex(oid)); - - if (cmdmode == 'w') { - if (filter_object(rest, 0100644, oid, &contents, &size)) - die("could not convert '%s' %s", oid_to_hex(oid), rest); - } else if (cmdmode == 'c') { - enum object_type type; - if (!textconv_object(the_repository, rest, 0100644, oid, 1, - &contents, &size)) - contents = read_object_file(oid, &type, &size); - if (!contents) - die("could not convert '%s' %s", oid_to_hex(oid), rest); - } else - BUG("invalid cmdmode: %c", cmdmode); - write_or_die(1, contents, size); - free(contents); -} - static void batch_object_write(const char *obj_name, struct strbuf *scratch, struct batch_options *opt, diff --git a/ref-filter.c b/ref-filter.c index 65b94ea21e54f..68d9741a56468 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -20,6 +20,7 @@ #include "commit-slab.h" #include "commit-graph.h" #include "commit-reach.h" +#include "streaming.h" static struct ref_msg { const char *gone; @@ -2366,3 +2367,54 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) return 0; } + +void print_object_or_die(struct expand_data *data, int cmdmode, + int buffered, const char *rest) +{ + const struct object_id *oid = &data->oid; + unsigned long size; + char *contents; + + assert(data->info.typep); + + if (data->type != OBJ_BLOB) { + enum object_type type; + contents = read_object_file(oid, &type, &size); + if (!contents) + die("object %s disappeared", oid_to_hex(oid)); + if (type != data->type) + die("object %s changed type!?", oid_to_hex(oid)); + if (data->info.sizep && size != data->size) + die("object %s changed size!?", oid_to_hex(oid)); + + write_or_die(1, contents, size); + free(contents); + return; + } + + if (buffered) + fflush(stdout); + if (!cmdmode) { + if (stream_blob_to_fd(1, oid, NULL, 0)) + die("unable to stream %s to stdout", oid_to_hex(oid)); + return; + } + + if (!rest) + die("missing path for '%s'", oid_to_hex(oid)); + + if (cmdmode == 'w') { + if (filter_object(rest, 0100644, oid, &contents, &size)) + die("could not convert '%s' %s", oid_to_hex(oid), rest); + } else if (cmdmode == 'c') { + enum object_type type; + if (!textconv_object(the_repository, rest, 0100644, oid, 1, + &contents, &size)) + contents = read_object_file(oid, &type, &size); + if (!contents) + die("could not convert '%s' %s", oid_to_hex(oid), rest); + } else + BUG("invalid cmdmode: %c", cmdmode); + write_or_die(1, contents, size); + free(contents); +} diff --git a/ref-filter.h b/ref-filter.h index fc61457d4d660..3422f39e64b5b 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -157,4 +157,7 @@ struct ref_array_item *ref_array_push(struct ref_array *array, const char *refname, const struct object_id *oid); +void print_object_or_die(struct expand_data *data, int cmdmode, + int buffered, const char *rest); + #endif /* REF_FILTER_H */ -- https://github.com/git/git/pull/568