@@ -61,6 +61,17 @@ struct refname_atom {
61
61
int lstrip , rstrip ;
62
62
};
63
63
64
+ struct expand_data {
65
+ struct object_id oid ;
66
+ enum object_type type ;
67
+ unsigned long size ;
68
+ off_t disk_size ;
69
+ struct object_id delta_base_oid ;
70
+ void * content ;
71
+
72
+ struct object_info info ;
73
+ } oi , oi_deref ;
74
+
64
75
/*
65
76
* An atom is a valid field atom listed below, possibly prefixed with
66
77
* a "*" to denote deref_tag().
@@ -202,6 +213,30 @@ static int remote_ref_atom_parser(const struct ref_format *format, struct used_a
202
213
return 0 ;
203
214
}
204
215
216
+ static int objecttype_atom_parser (const struct ref_format * format , struct used_atom * atom ,
217
+ const char * arg , struct strbuf * err )
218
+ {
219
+ if (arg )
220
+ return strbuf_addf_ret (err , -1 , _ ("%%(objecttype) does not take arguments" ));
221
+ if (* atom -> name == '*' )
222
+ oi_deref .info .typep = & oi_deref .type ;
223
+ else
224
+ oi .info .typep = & oi .type ;
225
+ return 0 ;
226
+ }
227
+
228
+ static int objectsize_atom_parser (const struct ref_format * format , struct used_atom * atom ,
229
+ const char * arg , struct strbuf * err )
230
+ {
231
+ if (arg )
232
+ return strbuf_addf_ret (err , -1 , _ ("%%(objectsize) does not take arguments" ));
233
+ if (* atom -> name == '*' )
234
+ oi_deref .info .sizep = & oi_deref .size ;
235
+ else
236
+ oi .info .sizep = & oi .size ;
237
+ return 0 ;
238
+ }
239
+
205
240
static int body_atom_parser (const struct ref_format * format , struct used_atom * atom ,
206
241
const char * arg , struct strbuf * err )
207
242
{
@@ -388,8 +423,8 @@ static struct {
388
423
const char * arg , struct strbuf * err );
389
424
} valid_atom [] = {
390
425
{ "refname" , SOURCE_NONE , FIELD_STR , refname_atom_parser },
391
- { "objecttype" , SOURCE_OTHER },
392
- { "objectsize" , SOURCE_OTHER , FIELD_ULONG },
426
+ { "objecttype" , SOURCE_OTHER , FIELD_STR , objecttype_atom_parser },
427
+ { "objectsize" , SOURCE_OTHER , FIELD_ULONG , objectsize_atom_parser },
393
428
{ "objectname" , SOURCE_OTHER , FIELD_STR , objectname_atom_parser },
394
429
{ "tree" , SOURCE_OBJ },
395
430
{ "parent" , SOURCE_OBJ },
@@ -502,6 +537,12 @@ static int parse_ref_filter_atom(const struct ref_format *format,
502
537
used_atom [at ].name = xmemdupz (atom , ep - atom );
503
538
used_atom [at ].type = valid_atom [i ].cmp_type ;
504
539
used_atom [at ].source = valid_atom [i ].source ;
540
+ if (used_atom [at ].source == SOURCE_OBJ ) {
541
+ if (* atom == '*' )
542
+ oi_deref .info .contentp = & oi_deref .content ;
543
+ else
544
+ oi .info .contentp = & oi .content ;
545
+ }
505
546
if (arg ) {
506
547
arg = used_atom [at ].name + (arg - atom ) + 1 ;
507
548
if (!* arg ) {
@@ -817,7 +858,7 @@ static int grab_objectname(const char *name, const struct object_id *oid,
817
858
}
818
859
819
860
/* See grab_values */
820
- static void grab_common_values (struct atom_value * val , int deref , struct object * obj , void * buf , unsigned long sz )
861
+ static void grab_common_values (struct atom_value * val , int deref , struct expand_data * oi )
821
862
{
822
863
int i ;
823
864
@@ -829,13 +870,13 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
829
870
if (deref )
830
871
name ++ ;
831
872
if (!strcmp (name , "objecttype" ))
832
- v -> s = type_name (obj -> type );
873
+ v -> s = type_name (oi -> type );
833
874
else if (!strcmp (name , "objectsize" )) {
834
- v -> value = sz ;
835
- v -> s = xstrfmt ("%lu" , sz );
875
+ v -> value = oi -> size ;
876
+ v -> s = xstrfmt ("%lu" , oi -> size );
836
877
}
837
878
else if (deref )
838
- grab_objectname (name , & obj -> oid , v , & used_atom [i ]);
879
+ grab_objectname (name , & oi -> oid , v , & used_atom [i ]);
839
880
}
840
881
}
841
882
@@ -1194,7 +1235,6 @@ static void fill_missing_values(struct atom_value *val)
1194
1235
*/
1195
1236
static void grab_values (struct atom_value * val , int deref , struct object * obj , void * buf , unsigned long sz )
1196
1237
{
1197
- grab_common_values (val , deref , obj , buf , sz );
1198
1238
switch (obj -> type ) {
1199
1239
case OBJ_TAG :
1200
1240
grab_tag_values (val , deref , obj , buf , sz );
@@ -1418,28 +1458,35 @@ static const char *get_refname(struct used_atom *atom, struct ref_array_item *re
1418
1458
return show_ref (& atom -> u .refname , ref -> refname );
1419
1459
}
1420
1460
1421
- static int get_object (struct ref_array_item * ref , const struct object_id * oid ,
1422
- int deref , struct object * * obj , struct strbuf * err )
1461
+ static int get_object (struct ref_array_item * ref , int deref , struct object * * obj ,
1462
+ struct expand_data * oi , struct strbuf * err )
1423
1463
{
1424
1464
int eaten ;
1425
- int ret = 0 ;
1426
- unsigned long size ;
1427
- enum object_type type ;
1428
- void * buf = read_object_file (oid , & type , & size );
1429
- if (!buf )
1430
- ret = strbuf_addf_ret (err , -1 , _ ("missing object %s for %s" ),
1431
- oid_to_hex (oid ), ref -> refname );
1432
- else {
1433
- * obj = parse_object_buffer (oid , type , size , buf , & eaten );
1434
- if (!* obj )
1435
- ret = strbuf_addf_ret (err , -1 , _ ("parse_object_buffer failed on %s for %s" ),
1436
- oid_to_hex (oid ), ref -> refname );
1437
- else
1438
- grab_values (ref -> value , deref , * obj , buf , size );
1465
+ if (oi -> info .contentp ) {
1466
+ /* We need to know that to use parse_object_buffer properly */
1467
+ oi -> info .sizep = & oi -> size ;
1468
+ oi -> info .typep = & oi -> type ;
1439
1469
}
1470
+ if (oid_object_info_extended (the_repository , & oi -> oid , & oi -> info ,
1471
+ OBJECT_INFO_LOOKUP_REPLACE ))
1472
+ return strbuf_addf_ret (err , -1 , _ ("missing object %s for %s" ),
1473
+ oid_to_hex (& oi -> oid ), ref -> refname );
1474
+
1475
+ if (oi -> info .contentp ) {
1476
+ * obj = parse_object_buffer (& oi -> oid , oi -> type , oi -> size , oi -> content , & eaten );
1477
+ if (!obj ) {
1478
+ if (!eaten )
1479
+ free (oi -> content );
1480
+ return strbuf_addf_ret (err , -1 , _ ("parse_object_buffer failed on %s for %s" ),
1481
+ oid_to_hex (& oi -> oid ), ref -> refname );
1482
+ }
1483
+ grab_values (ref -> value , deref , * obj , oi -> content , oi -> size );
1484
+ }
1485
+
1486
+ grab_common_values (ref -> value , deref , oi );
1440
1487
if (!eaten )
1441
- free (buf );
1442
- return ret ;
1488
+ free (oi -> content );
1489
+ return 0 ;
1443
1490
}
1444
1491
1445
1492
/*
@@ -1449,7 +1496,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
1449
1496
{
1450
1497
struct object * obj ;
1451
1498
int i ;
1452
- const struct object_id * tagged ;
1499
+ struct object_info empty = OBJECT_INFO_INIT ;
1453
1500
1454
1501
ref -> value = xcalloc (used_atom_cnt , sizeof (struct atom_value ));
1455
1502
@@ -1569,13 +1616,20 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
1569
1616
1570
1617
for (i = 0 ; i < used_atom_cnt ; i ++ ) {
1571
1618
struct atom_value * v = & ref -> value [i ];
1572
- if (v -> s == NULL )
1573
- break ;
1619
+ if (v -> s == NULL && used_atom [i ].source == SOURCE_NONE )
1620
+ return strbuf_addf_ret (err , -1 , _ ("missing object %s for %s" ),
1621
+ oid_to_hex (& ref -> objectname ), ref -> refname );
1574
1622
}
1575
- if (used_atom_cnt <= i )
1623
+
1624
+ if (need_tagged )
1625
+ oi .info .contentp = & oi .content ;
1626
+ if (!memcmp (& oi .info , & empty , sizeof (empty )) &&
1627
+ !memcmp (& oi_deref .info , & empty , sizeof (empty )))
1576
1628
return 0 ;
1577
1629
1578
- if (get_object (ref , & ref -> objectname , 0 , & obj , err ))
1630
+
1631
+ oi .oid = ref -> objectname ;
1632
+ if (get_object (ref , 0 , & obj , & oi , err ))
1579
1633
return -1 ;
1580
1634
1581
1635
/*
@@ -1589,15 +1643,15 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
1589
1643
* If it is a tag object, see if we use a value that derefs
1590
1644
* the object, and if we do grab the object it refers to.
1591
1645
*/
1592
- tagged = & ((struct tag * )obj )-> tagged -> oid ;
1646
+ oi_deref . oid = ((struct tag * )obj )-> tagged -> oid ;
1593
1647
1594
1648
/*
1595
1649
* NEEDSWORK: This derefs tag only once, which
1596
1650
* is good to deal with chains of trust, but
1597
1651
* is not consistent with what deref_tag() does
1598
1652
* which peels the onion to the core.
1599
1653
*/
1600
- return get_object (ref , tagged , 1 , & obj , err );
1654
+ return get_object (ref , 1 , & obj , & oi_deref , err );
1601
1655
}
1602
1656
1603
1657
/*
0 commit comments