From: Junio C Hamano Date: Fri, 18 Jan 2019 21:49:56 +0000 (-0800) Subject: Merge branch 'ot/ref-filter-object-info' X-Git-Tag: v2.21.0-rc0~79 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/55574bd04ada4dab255dad687665ee7578bc6a32?hp=-c Merge branch 'ot/ref-filter-object-info' The "--format=" option of for-each-ref, branch and tag learned to show a few more traits of objects that can be learned by the object_info API. * ot/ref-filter-object-info: ref-filter: give uintmax_t to format with %PRIuMAX ref-filter: add docs for new options ref-filter: add tests for deltabase ref-filter: add deltabase option ref-filter: add tests for objectsize:disk ref-filter: add check for negative file size ref-filter: add objectsize:disk option --- 55574bd04ada4dab255dad687665ee7578bc6a32 diff --combined ref-filter.c index 61d75d5c86,b22cab133e..422a9c9ae3 --- a/ref-filter.c +++ b/ref-filter.c @@@ -230,13 -230,31 +230,31 @@@ static int objecttype_atom_parser(cons static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err) + { + if (!arg) { + if (*atom->name == '*') + oi_deref.info.sizep = &oi_deref.size; + else + oi.info.sizep = &oi.size; + } else if (!strcmp(arg, "disk")) { + if (*atom->name == '*') + oi_deref.info.disk_sizep = &oi_deref.disk_size; + else + oi.info.disk_sizep = &oi.disk_size; + } else + return strbuf_addf_ret(err, -1, _("unrecognized %%(objectsize) argument: %s"), arg); + return 0; + } + + static int deltabase_atom_parser(const struct ref_format *format, struct used_atom *atom, + const char *arg, struct strbuf *err) { if (arg) - return strbuf_addf_ret(err, -1, _("%%(objectsize) does not take arguments")); + return strbuf_addf_ret(err, -1, _("%%(deltabase) does not take arguments")); if (*atom->name == '*') - oi_deref.info.sizep = &oi_deref.size; + oi_deref.info.delta_base_sha1 = oi_deref.delta_base_oid.hash; else - oi.info.sizep = &oi.size; + oi.info.delta_base_sha1 = oi.delta_base_oid.hash; return 0; } @@@ -431,6 -449,7 +449,7 @@@ static struct { "objecttype", SOURCE_OTHER, FIELD_STR, objecttype_atom_parser }, { "objectsize", SOURCE_OTHER, FIELD_ULONG, objectsize_atom_parser }, { "objectname", SOURCE_OTHER, FIELD_STR, objectname_atom_parser }, + { "deltabase", SOURCE_OTHER, FIELD_STR, deltabase_atom_parser }, { "tree", SOURCE_OBJ }, { "parent", SOURCE_OBJ }, { "numparent", SOURCE_OBJ, FIELD_ULONG }, @@@ -534,10 -553,6 +553,10 @@@ static int parse_ref_filter_atom(const if (ARRAY_SIZE(valid_atom) <= i) return strbuf_addf_ret(err, -1, _("unknown field name: %.*s"), (int)(ep-atom), atom); + if (valid_atom[i].source != SOURCE_NONE && !have_git_dir()) + return strbuf_addf_ret(err, -1, + _("not a git repository, but the field '%.*s' requires access to object data"), + (int)(ep-atom), atom); /* Add it in, including the deref prefix */ at = used_atom_cnt; @@@ -880,10 -895,14 +899,14 @@@ static void grab_common_values(struct a name++; if (!strcmp(name, "objecttype")) v->s = xstrdup(type_name(oi->type)); - else if (!strcmp(name, "objectsize")) { + else if (!strcmp(name, "objectsize:disk")) { + v->value = oi->disk_size; + v->s = xstrfmt("%"PRIuMAX, (uintmax_t)oi->disk_size); + } else if (!strcmp(name, "objectsize")) { v->value = oi->size; - v->s = xstrfmt("%lu", oi->size); + v->s = xstrfmt("%"PRIuMAX , (uintmax_t)oi->size); - } + } else if (!strcmp(name, "deltabase")) + v->s = xstrdup(oid_to_hex(&oi->delta_base_oid)); else if (deref) grab_objectname(name, &oi->oid, v, &used_atom[i]); } @@@ -1417,7 -1436,7 +1440,7 @@@ char *get_head_description(void struct strbuf desc = STRBUF_INIT; struct wt_status_state state; memset(&state, 0, sizeof(state)); - wt_status_get_state(&state, 1); + wt_status_get_state(the_repository, &state, 1); if (state.rebase_in_progress || state.rebase_interactive_in_progress) { if (state.branch) @@@ -1482,6 -1501,8 +1505,8 @@@ static int get_object(struct ref_array_ OBJECT_INFO_LOOKUP_REPLACE)) return strbuf_addf_ret(err, -1, _("missing object %s for %s"), oid_to_hex(&oi->oid), ref->refname); + if (oi->info.disk_sizep && oi->disk_size < 0) + BUG("Object size is less than zero."); if (oi->info.contentp) { *obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten); @@@ -2320,15 -2341,11 +2345,15 @@@ int parse_opt_merge_filter(const struc struct object_id oid; int no_merged = starts_with(opt->long_name, "no"); + BUG_ON_OPT_NEG(unset); + if (rf->merge) { if (no_merged) { - return opterror(opt, "is incompatible with --merged", 0); + return error(_("option `%s' is incompatible with --merged"), + opt->long_name); } else { - return opterror(opt, "is incompatible with --no-merged", 0); + return error(_("option `%s' is incompatible with --no-merged"), + opt->long_name); } } @@@ -2342,7 -2359,7 +2367,7 @@@ rf->merge_commit = lookup_commit_reference_gently(the_repository, &oid, 0); if (!rf->merge_commit) - return opterror(opt, "must point to a commit", 0); + return error(_("option `%s' must point to a commit"), opt->long_name); return 0; }