]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ot/ref-filter-object-info'
authorJunio C Hamano <gitster@pobox.com>
Fri, 17 Aug 2018 20:09:57 +0000 (13:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Aug 2018 20:09:57 +0000 (13:09 -0700)
A few atoms like %(objecttype) and %(objectsize) in the format
specifier of "for-each-ref --format=<format>" can be filled without
getting the full contents of the object, but just with the object
header.  These cases have been optimized by calling
oid_object_info() API (instead of reading and inspecting the data).

* ot/ref-filter-object-info:
  ref-filter: use oid_object_info() to get object
  ref-filter: merge get_obj and get_object
  ref-filter: initialize eaten variable
  ref-filter: fill empty fields with empty values
  ref-filter: add info_source to valid_atom

1  2 
ref-filter.c

diff --cc ref-filter.c
index a8def7b3a36fde5fd4b7184b84f8ae36740642f5,112955f006648315d048d1fba1c71862d538fe3f..0bccfceff2ae31200019838d9f2b67e13e32ef6f
@@@ -1435,24 -1458,36 +1460,36 @@@ static const char *get_refname(struct u
        return show_ref(&atom->u.refname, ref->refname);
  }
  
- static int get_object(struct ref_array_item *ref, const struct object_id *oid,
-                      int deref, struct object **obj, struct strbuf *err)
+ static int get_object(struct ref_array_item *ref, int deref, struct object **obj,
+                     struct expand_data *oi, struct strbuf *err)
  {
-       int eaten;
-       int ret = 0;
-       unsigned long size;
-       void *buf = get_obj(oid, obj, &size, &eaten);
-       if (!buf)
-               ret = strbuf_addf_ret(err, -1, _("missing object %s for %s"),
-                                     oid_to_hex(oid), ref->refname);
-       else if (!*obj)
-               ret = strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"),
-                                     oid_to_hex(oid), ref->refname);
-       else
-               grab_values(ref->value, deref, *obj, buf, size);
+       /* parse_object_buffer() will set eaten to 0 if free() will be needed */
+       int eaten = 1;
+       if (oi->info.contentp) {
+               /* We need to know that to use parse_object_buffer properly */
+               oi->info.sizep = &oi->size;
+               oi->info.typep = &oi->type;
+       }
+       if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
+                                    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.contentp) {
 -              *obj = parse_object_buffer(&oi->oid, oi->type, oi->size, oi->content, &eaten);
++              *obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten);
+               if (!obj) {
+                       if (!eaten)
+                               free(oi->content);
+                       return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"),
+                                              oid_to_hex(&oi->oid), ref->refname);
+               }
+               grab_values(ref->value, deref, *obj, oi->content, oi->size);
+       }
+       grab_common_values(ref->value, deref, oi);
        if (!eaten)
-               free(buf);
-       return ret;
+               free(oi->content);
+       return 0;
  }
  
  /*