diff options
author | Olga Telezhnaya <olyatelezhnaya@gmail.com> | 2018-02-12 08:08:54 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-02-12 15:03:57 -0800 |
commit | 64b3296bbfccc30fc76c50d9f50fbf218cccddef (patch) | |
tree | 51b506171eb404b801d65691a67556f453d2b227 | |
parent | 15b3c56c4bf24609f1d52e34d7e29c8437b08d8a (diff) | |
download | git-64b3296bbfccc30fc76c50d9f50fbf218cccddef.tar.gz |
cat-file: start reusing populate_value()
Move logic related to getting object info from cat-file to ref-filter.
It will help to reuse whole formatting logic from ref-filter further.
Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/cat-file.c | 17 | ||||
-rw-r--r-- | ref-filter.c | 20 | ||||
-rw-r--r-- | ref-filter.h | 1 |
3 files changed, 25 insertions, 13 deletions
diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 0c362828ad..6db57e3533 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -285,21 +285,12 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt, struct strbuf buf = STRBUF_INIT; struct ref_array_item item = {0}; - if (!data->skip_object_info && - sha1_object_info_extended(data->oid.hash, &data->info, - OBJECT_INFO_LOOKUP_REPLACE) < 0) { - printf("%s missing\n", - obj_name ? obj_name : oid_to_hex(&data->oid)); - fflush(stdout); - return; - } - item.oid = data->oid; - item.type = data->type; - item.size = data->size; - item.disk_size = data->disk_size; item.rest = data->rest; - item.delta_base_oid = &data->delta_base_oid; + item.objectname = obj_name; + + if (populate_value(&item)) + return; strbuf_expand(&buf, opt->format.format, expand_format, &item); strbuf_addch(&buf, '\n'); diff --git a/ref-filter.c b/ref-filter.c index c168eff4d9..a047ef3150 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1403,6 +1403,23 @@ static const char *get_refname(struct used_atom *atom, struct ref_array_item *re return show_ref(&atom->u.refname, ref->refname); } +static int check_and_fill_for_cat(struct ref_array_item *ref) +{ + if (!cat_file_info->skip_object_info && + sha1_object_info_extended(ref->oid.hash, &cat_file_info->info, + OBJECT_INFO_LOOKUP_REPLACE) < 0) { + const char *e = ref->objectname; + printf("%s missing\n", e ? e : oid_to_hex(&ref->oid)); + fflush(stdout); + return -1; + } + ref->type = cat_file_info->type; + ref->size = cat_file_info->size; + ref->disk_size = cat_file_info->disk_size; + ref->delta_base_oid = &cat_file_info->delta_base_oid; + return 0; +} + /* * Parse the object referred by ref, and grab needed value. * Return 0 if everything was successful, -1 otherwise. @@ -1424,6 +1441,9 @@ int populate_value(struct ref_array_item *ref) ref->symref = ""; } + if (cat_file_info && check_and_fill_for_cat(ref)) + return -1; + /* Fill in specials first */ for (i = 0; i < used_atom_cnt; i++) { struct used_atom *atom = &used_atom[i]; diff --git a/ref-filter.h b/ref-filter.h index 87b026b8b7..5c6e019998 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -45,6 +45,7 @@ struct ref_array_item { off_t disk_size; const char *rest; struct object_id *delta_base_oid; + const char *objectname; char refname[FLEX_ARRAY]; }; |